|
1 | | -from twinleaf import _twinleaf |
| 1 | +from twinleaf import _twinleaf # type: ignore[attr-defined] |
2 | 2 |
|
3 | 3 | class Device(_twinleaf._Device): |
4 | 4 | """ Primary TIO interface with sensor object """ |
@@ -31,6 +31,7 @@ def _rpc_int(self, name: str, size: int, signed: bool, value: int | None = None) |
31 | 31 | case 2, False: fstr = '<H' |
32 | 32 | case 4, False: fstr = '<I' |
33 | 33 | case 8, False: fstr = '<Q' |
| 34 | + case _: raise ValueError(f"Unsupported int size/signed combo: {size}, {signed}") |
34 | 35 | payload = b'' if value is None else struct.pack(fstr, value) |
35 | 36 | rep = self._rpc(name, payload) |
36 | 37 | val = struct.unpack(fstr, rep)[0] |
@@ -197,7 +198,7 @@ def __new__(cls, pyrpc: _twinleaf._Rpc, device: Device): |
197 | 198 | subclass = _RpcReadOnly |
198 | 199 | case _: |
199 | 200 | subclass = _RpcAction |
200 | | - rpc = super().__new__(subclass) |
| 201 | + rpc = super().__new__(subclass) # type: ignore[arg-type] |
201 | 202 | return rpc |
202 | 203 |
|
203 | 204 | def __init__(self, pyrpc: _twinleaf._Rpc, device: Device): |
@@ -242,11 +243,14 @@ def __repr__(self): |
242 | 243 | def _call(self, arg: _rpc_type=None) -> _rpc_type: |
243 | 244 | match self._type: |
244 | 245 | case t if t is int: |
| 246 | + assert arg is None or isinstance(arg, int) |
245 | 247 | return self._device._rpc_int(self.__name__, self._data_size, self._signed, arg) |
246 | 248 | case t if t is float: |
| 249 | + assert arg is None or isinstance(arg, float) |
247 | 250 | return self._device._rpc_float(self.__name__, self._data_size, arg) |
248 | 251 | case t if t is str: |
249 | 252 | if arg is None: arg = '' |
| 253 | + assert isinstance(arg, str) |
250 | 254 | return self._device._rpc(self.__name__, arg.encode()).decode() |
251 | 255 | case t if t is bytes: |
252 | 256 | if arg is None: arg = b'' |
|
0 commit comments