Procházet zdrojové kódy

no longer ignore msgs with retain flag

Fabian Peter Hammerle před 3 roky
rodič
revize
3e11bcd596

+ 0 - 3
intertechno_cc1101_mqtt/__init__.py

@@ -56,9 +56,6 @@ def _mqtt_on_message(
     # pylint: disable=unused-argument; callback
     # https://github.com/eclipse/paho.mqtt.python/blob/v1.5.0/src/paho/mqtt/client.py#L469
     _LOGGER.debug("received topic=%s payload=%r", message.topic, message.payload)
-    if message.retain:  # TODO remove
-        _LOGGER.warning("ignoring retained message")
-        return
     address, button_index = _parse_topic(topic=message.topic, aliases=aliases)
     if not address:
         return

+ 2 - 3
tests/test_cli.py

@@ -5,6 +5,8 @@ import pytest
 
 import intertechno_cc1101_mqtt
 
+# pylint: disable=protected-access
+
 
 @pytest.mark.parametrize(
     (
@@ -59,7 +61,6 @@ def test__main(
     with unittest.mock.patch(
         "intertechno_cc1101_mqtt._run"
     ) as run_mock, unittest.mock.patch("sys.argv", argv):
-        # pylint: disable=protected-access
         intertechno_cc1101_mqtt._main()
     run_mock.assert_called_once_with(
         mqtt_host=expected_mqtt_host,
@@ -102,7 +103,6 @@ def test__main_password_file(tmpdir, password_file_content, expected_password):
             str(mqtt_password_path),
         ],
     ):
-        # pylint: disable=protected-access
         intertechno_cc1101_mqtt._main()
     run_mock.assert_called_once_with(
         mqtt_host="localhost",
@@ -129,7 +129,6 @@ def test__main_password_file_collision(capsys):
         ],
     ):
         with pytest.raises(SystemExit):
-            # pylint: disable=protected-access
             intertechno_cc1101_mqtt._main()
     out, err = capsys.readouterr()
     assert not out

+ 5 - 19
tests/test_mqtt_message.py

@@ -9,24 +9,6 @@ import intertechno_cc1101_mqtt
 # pylint: disable=protected-access
 
 
-def test__mqtt_on_message_retained(caplog):
-    message = MQTTMessage(topic=b"intertechno-cc1101/12345678/0/set")
-    message.payload = b"ON"
-    message.retain = True
-    with unittest.mock.patch("intertechno_cc1101.RemoteControl") as remote_control_mock:
-        with caplog.at_level(logging.DEBUG):
-            intertechno_cc1101_mqtt._mqtt_on_message("dummy", {}, message)
-    remote_control_mock.assert_not_called()
-    assert caplog.record_tuples == [
-        (
-            "intertechno_cc1101_mqtt",
-            logging.DEBUG,
-            "received topic=intertechno-cc1101/12345678/0/set payload=b'ON'",
-        ),
-        ("intertechno_cc1101_mqtt", logging.WARNING, "ignoring retained message"),
-    ]
-
-
 @pytest.mark.parametrize(
     ("topic", "address"),
     (
@@ -75,9 +57,13 @@ def test__mqtt_on_message_invalid_address(caplog, topic, address_str):
     ("payload", "turn_on"),
     ((b"ON", True), (b"On", True), (b"on", True), (b"OFF", False), (b"off", False)),
 )
-def test__mqtt_on_message_button_index_action(topic, button_index, payload, turn_on):
+@pytest.mark.parametrize("retain", [True, False])
+def test__mqtt_on_message_button_index_action(
+    topic, button_index, payload, turn_on, retain
+):
     message = MQTTMessage(topic=topic)
     message.payload = payload
+    message.retain = retain
     with unittest.mock.patch("intertechno_cc1101.RemoteControl") as remote_control_mock:
         intertechno_cc1101_mqtt._mqtt_on_message("dummy", {}, message)
     if turn_on: