Przeglądaj źródła

BLE plant moisture: add refresh button

According to user reports, these devices can be forced to refresh by
setting the temperature unit.

Add a button to do that, to make it easier to use without changing the
temperature unit unintentionally.

 #1696
Jason Rumney 1 rok temu
rodzic
commit
e27bc3cb43

+ 26 - 0
custom_components/tuya_local/devices/ble_smart_plant_moisture.yaml

@@ -52,3 +52,29 @@ secondary_entities:
             value: celsius
           - dps_val: f
             value: fahrenheit
+  - entity: button
+    name: Refresh
+    class: restart
+    category: config
+    dps:
+      - id: 9
+        type: string
+        name: button
+        mapping:
+          - dps_val: c
+            constraint: current
+            conditions:
+              - dps_val: c
+                value: true
+              - dps_val: f
+                value: false
+          - dps_val: f
+            constraint: current
+            conditions:
+              - dps_val: c
+                value: false
+              - dps_val: f
+                value: true
+      - id: 9
+        type: string
+        name: current

+ 8 - 0
tests/const.py

@@ -1671,3 +1671,11 @@ DUUX_BLIZZARD_PAYLOAD = {
     "14": False,
     "15": 0,
 }
+
+BLE_SMARTPLANT_PAYLOAD = {
+    "3": 50,
+    "5": 25,
+    "9": "c",
+    "14": "Low",
+    "15": 20,
+}

+ 52 - 0
tests/devices/test_ble_smartplant.py

@@ -0,0 +1,52 @@
+"""
+Test BLE smart plant sensor.
+Primarily for testing the refresh button used in this device, which is
+made by sending the temperature unit as the current setting so as to
+give the device a command to initiate a data transmission without actually
+changing anything.
+"""
+
+from ..const import BLE_SMARTPLANT_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+MOISTURE_DP = "3"
+TEMPERATURE_DP = "5"
+TEMPERATURE_UNIT_DP = "9"
+BATTERY_STATE_DP = "14"
+BATTERY_DP = "15"
+
+
+class TestBleSmartPlant(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "ble_smart_plant_moisture.yaml",
+            BLE_SMARTPLANT_PAYLOAD,
+        )
+        self.refresh_button = self.entities.get("button_refresh")
+        self.mark_secondary(
+            [
+                "sensor_battery",
+                "select_temperature_unit",
+                "button_refresh",
+            ]
+        )
+
+    async def test_refresh_logic(self):
+        self.dps[TEMPERATURE_UNIT_DP] = "c"
+
+        async with assert_device_properties_set(
+            self.refresh_button._device,
+            {TEMPERATURE_UNIT_DP: "c"},
+        ):
+            await self.refresh_button.async_press()
+
+        self.dps[TEMPERATURE_UNIT_DP] = "f"
+
+        async with assert_device_properties_set(
+            self.refresh_button._device,
+            {TEMPERATURE_UNIT_DP: "f"},
+        ):
+            await self.refresh_button.async_press()