|
@@ -60,7 +60,24 @@ class RemoteControl:
|
|
|
|
|
|
def _send_command(self, command: int, button_index: int) -> None:
|
|
def _send_command(self, command: int, button_index: int) -> None:
|
|
assert 0 <= command < 2 ** _COMMAND_LENGTH_BITS
|
|
assert 0 <= command < 2 ** _COMMAND_LENGTH_BITS
|
|
- assert 0 <= button_index < 2 ** _BUTTON_INDEX_LENGTH_BITS
|
|
+ if not isinstance(button_index, int):
|
|
|
|
+ raise ValueError(
|
|
|
|
+ "expected {}-bit unsigned integer as button index, got {!r}".format(
|
|
|
|
+ _BUTTON_INDEX_LENGTH_BITS, button_index
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ if button_index < 0:
|
|
|
|
+ raise ValueError(
|
|
|
|
+ "button index must not be negative (got {!r})".format(button_index)
|
|
|
|
+ )
|
|
|
|
+ if button_index >= 2 ** _BUTTON_INDEX_LENGTH_BITS:
|
|
|
|
+ raise ValueError(
|
|
|
|
+ "button index must not exceed {} ({}-bit unsigned integer), got {!r}".format(
|
|
|
|
+ 2 ** _BUTTON_INDEX_LENGTH_BITS,
|
|
|
|
+ _BUTTON_INDEX_LENGTH_BITS,
|
|
|
|
+ button_index,
|
|
|
|
+ )
|
|
|
|
+ )
|
|
_cc1101_transmit(
|
|
_cc1101_transmit(
|
|
_encode_message(
|
|
_encode_message(
|
|
(self._address << _COMMAND_LENGTH_BITS | command)
|
|
(self._address << _COMMAND_LENGTH_BITS | command)
|