Răsfoiți Sursa

Fix tests that need updating for the last change, and bug revealed by that update.

When values are stringified, they also need to be type converted on read for
value mapping to work.
Jason Rumney 4 ani în urmă
părinte
comite
3824633922

+ 6 - 0
custom_components/tuya_local/helpers/device_config.py

@@ -317,6 +317,12 @@ class TuyaDpsConfig:
         return default
 
     def _map_from_dps(self, value, device):
+        # For stringified dps, convert to desired type if possible
+        if self.stringify and value is not None:
+            try:
+                value = self.type(value)
+            except ValueError:
+                pass
         result = value
         mapping = self._find_map_for_dps(value)
         if mapping is not None:

+ 2 - 2
tests/const.py

@@ -147,7 +147,7 @@ INKBIRD_THERMOSTAT_PAYLOAD = {
 ANKO_FAN_PAYLOAD = {
     "1": True,
     "2": "normal",
-    "3": 1,
+    "3": "1",
     "4": "off",
-    "6": 0,
+    "6": "0",
 }

+ 3 - 3
tests/devices/test_anko_fan.py

@@ -144,7 +144,7 @@ class TestAnkoFan(IsolatedAsyncioTestCase):
 
     def test_speed(self):
         self.dps[PRESET_DPS] = "normal"
-        self.dps[SPEED_DPS] = 4
+        self.dps[SPEED_DPS] = "4"
         self.assertEqual(self.subject.percentage, 50)
 
     def test_speed_step(self):
@@ -152,12 +152,12 @@ class TestAnkoFan(IsolatedAsyncioTestCase):
 
     async def test_set_speed_in_normal_mode(self):
         self.dps[PRESET_DPS] = "normal"
-        async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 2}):
+        async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "2"}):
             await self.subject.async_set_percentage(25)
 
     async def test_set_speed_in_normal_mode_snaps(self):
         self.dps[PRESET_DPS] = "normal"
-        async with assert_device_properties_set(self.subject._device, {SPEED_DPS: 6}):
+        async with assert_device_properties_set(self.subject._device, {SPEED_DPS: "6"}):
             await self.subject.async_set_percentage(80)
 
     def test_device_state_attributes(self):