Browse Source

upgrade intertechno-cc1101 library to prepare for parametrization of power setting

Fabian Peter Hammerle 3 years ago
parent
commit
f619e90e49
5 changed files with 26 additions and 13 deletions
  1. 1 1
      Pipfile
  2. 2 2
      Pipfile.lock
  3. 8 3
      intertechno_cc1101_mqtt/__init__.py
  4. 7 3
      setup.py
  5. 8 4
      tests/test_mqtt_message.py

+ 1 - 1
Pipfile

@@ -8,7 +8,7 @@ intertechno-cc1101-mqtt = {path = ".", editable = true}
 # apparently, pipenv does not support dependency_links.
 # > Warning: You installed a VCS dependency in non–editable mode.
 # > This will work fine, but sub-dependencies will not be resolved by $ pipenv lock.
-intertechno-cc1101 = {git = "https://git.hammerle.me/fphammerle/intertechno-cc1101", editable = true, ref = "v0.1.0"}
+intertechno-cc1101 = {git = "https://git.hammerle.me/fphammerle/intertechno-cc1101", editable = true, ref = "v0.2.0"}
 
 [dev-packages]
 # black requires python>=3.6

+ 2 - 2
Pipfile.lock

@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "58daea9b443031f62b91f759ac9d965ea636164f0846e5015397cb728b43d18a"
+            "sha256": "0ec1d23f7562dc496b70754ed93fc96caeb88d4e18e4cea48ee6e290b177ddc2"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -26,7 +26,7 @@
         "intertechno-cc1101": {
             "editable": true,
             "git": "https://git.hammerle.me/fphammerle/intertechno-cc1101",
-            "ref": "ac373ecf524351e5c22c2a17e2e5bbaf4ce010de"
+            "ref": "602188dcc241c757a905bf43057c683241130e22"
         },
         "intertechno-cc1101-mqtt": {
             "editable": true,

+ 8 - 3
intertechno_cc1101_mqtt/__init__.py

@@ -64,18 +64,23 @@ def _mqtt_on_message(
         return
     try:
         remote_control = intertechno_cc1101.RemoteControl(address=address)
-    except AssertionError:
+    except ValueError:
         _LOGGER.warning(
             "failed to initialize remote control, invalid address? ignoring message",
             exc_info=True,
         )
         return
+    power_setting = intertechno_cc1101.DEFAULT_POWER_SETTING
     # https://www.home-assistant.io/integrations/switch.mqtt/#payload_on
     try:
         if message.payload.upper() == b"ON":
-            remote_control.turn_on(button_index=button_index)
+            remote_control.turn_on(
+                button_index=button_index, power_setting=power_setting
+            )
         elif message.payload.upper() == b"OFF":
-            remote_control.turn_off(button_index=button_index)
+            remote_control.turn_off(
+                button_index=button_index, power_setting=power_setting
+            )
         else:
             _LOGGER.warning(
                 "unexpected payload %r; expected 'ON' or 'OFF'", message.payload

+ 7 - 3
setup.py

@@ -45,11 +45,15 @@ setuptools.setup(
     entry_points={
         "console_scripts": ["intertechno-cc1101-mqtt = intertechno_cc1101_mqtt:_main"]
     },
-    install_requires=["intertechno-cc1101>=0.1.0,<0.2", "paho-mqtt<2"],
+    install_requires=[
+        # >=0.2.0 turn_on/off(power_setting=?, ...)
+        "intertechno-cc1101>=0.2.0,<0.3",
+        "paho-mqtt<2",
+    ],
     setup_requires=["setuptools_scm"],
     tests_require=["pytest"],
     dependency_links=[
-        "git+https://git.hammerle.me/fphammerle/intertechno-cc1101@v0.1.0"
-        "#egg=intertechno-cc1101-0.1.0"
+        "git+https://git.hammerle.me/fphammerle/intertechno-cc1101@v0.2.0"
+        "#egg=intertechno-cc1101-0.2.0"
     ],
 )

+ 8 - 4
tests/test_mqtt_message.py

@@ -67,11 +67,13 @@ def test__mqtt_on_message_button_index_action(
     with unittest.mock.patch("intertechno_cc1101.RemoteControl") as remote_control_mock:
         intertechno_cc1101_mqtt._mqtt_on_message("dummy", {}, message)
     if turn_on:
-        remote_control_mock().turn_on.assert_called_once_with(button_index=button_index)
+        remote_control_mock().turn_on.assert_called_once_with(
+            button_index=button_index, power_setting=0xC6
+        )
         remote_control_mock().turn_off.assert_not_called()
     else:
         remote_control_mock().turn_off.assert_called_once_with(
-            button_index=button_index
+            button_index=button_index, power_setting=0xC6
         )
         remote_control_mock().turn_on.assert_not_called()
 
@@ -122,7 +124,9 @@ def test__mqtt_on_message_alias(topic, address, button_index):
             message,
         )
     remote_control_mock.assert_called_once_with(address=address)
-    remote_control_mock().turn_on.assert_called_once_with(button_index=button_index)
+    remote_control_mock().turn_on.assert_called_once_with(
+        button_index=button_index, power_setting=0xC6
+    )
 
 
 @pytest.mark.parametrize(
@@ -188,7 +192,7 @@ def test__mqtt_on_message_remote_init_failed(caplog, topic):
         caplog.records[0].message
         == "failed to initialize remote control, invalid address? ignoring message"
     )
-    assert isinstance(caplog.records[0].exc_info[1], AssertionError)
+    assert isinstance(caplog.records[0].exc_info[1], ValueError)
 
 
 def test__mqtt_on_message_transmission_failed(caplog):