Browse Source

button automators: no longer report battery% on deprecated topic `homeassistant/cover/switchbot/+/battery-percentage`

Fabian Peter Hammerle 2 years ago
parent
commit
557669a92c
3 changed files with 8 additions and 24 deletions
  1. 3 0
      CHANGELOG.md
  2. 0 16
      switchbot_mqtt/_actors/__init__.py
  3. 5 8
      tests/test_switchbot_button_automator.py

+ 3 - 0
CHANGELOG.md

@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Removed
 - compatibility with `python3.6`
+- no longer report button automator's battery percentage on deprecated topic
+  `homeassistant/cover/switchbot/+/battery-percentage`
+  (use `homeassistant/switch/switchbot/+/battery-percentage` instead, see `v2.1.0`)
 
 ## [2.2.0] - 2021-10-23
 ### Added

+ 0 - 16
switchbot_mqtt/_actors/__init__.py

@@ -57,13 +57,6 @@ class _ButtonAutomator(_MQTTControlledActor):
     _MQTT_BATTERY_PERCENTAGE_TOPIC_LEVELS = _BUTTON_TOPIC_LEVELS_PREFIX + (
         "battery-percentage",
     )
-    # for downward compatibility (will be removed in v3):
-    _MQTT_BATTERY_PERCENTAGE_TOPIC_LEVELS_LEGACY = _TOPIC_LEVELS_PREFIX + (
-        "cover",
-        "switchbot",
-        _MQTTTopicPlaceholder.MAC_ADDRESS,
-        "battery-percentage",
-    )
 
     def __init__(
         self, *, mac_address: str, retry_count: int, password: typing.Optional[str]
@@ -78,15 +71,6 @@ class _ButtonAutomator(_MQTTControlledActor):
     def _get_device(self) -> switchbot.SwitchbotDevice:
         return self.__device
 
-    def _report_battery_level(self, mqtt_client: paho.mqtt.client.Client) -> None:
-        super()._report_battery_level(mqtt_client=mqtt_client)
-        # kept for downward compatibility (will be removed in v3)
-        self._mqtt_publish(
-            topic_levels=self._MQTT_BATTERY_PERCENTAGE_TOPIC_LEVELS_LEGACY,
-            payload=str(self._get_device().get_battery_percent()).encode(),
-            mqtt_client=mqtt_client,
-        )
-
     def execute_command(
         self,
         mqtt_message_payload: bytes,

+ 5 - 8
tests/test_switchbot_button_automator.py

@@ -49,14 +49,11 @@ def test__update_and_report_device_info(
     with unittest.mock.patch("switchbot.Switchbot.update") as update_mock:
         actor._update_and_report_device_info(mqtt_client=mqtt_client_mock)
     update_mock.assert_called_once_with()
-    assert mqtt_client_mock.publish.call_args_list == [
-        unittest.mock.call(topic=t, payload=battery_percent_encoded, retain=True)
-        for t in [
-            "homeassistant/switch/switchbot/dummy/battery-percentage",
-            # will be removed in v3:
-            "homeassistant/cover/switchbot/dummy/battery-percentage",
-        ]
-    ]
+    mqtt_client_mock.publish.assert_called_once_with(
+        topic="homeassistant/switch/switchbot/dummy/battery-percentage",
+        payload=battery_percent_encoded,
+        retain=True,
+    )
 
 
 @pytest.mark.parametrize("mac_address", ["aa:bb:cc:dd:ee:ff", "aa:bb:cc:11:22:33"])