浏览代码

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 5 年之前
父节点
当前提交
3824633922
共有 3 个文件被更改,包括 11 次插入5 次删除
  1. 6 0
      custom_components/tuya_local/helpers/device_config.py
  2. 2 2
      tests/const.py
  3. 3 3
      tests/devices/test_anko_fan.py

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

@@ -317,6 +317,12 @@ class TuyaDpsConfig:
         return default
         return default
 
 
     def _map_from_dps(self, value, device):
     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
         result = value
         mapping = self._find_map_for_dps(value)
         mapping = self._find_map_for_dps(value)
         if mapping is not None:
         if mapping is not None:

+ 2 - 2
tests/const.py

@@ -147,7 +147,7 @@ INKBIRD_THERMOSTAT_PAYLOAD = {
 ANKO_FAN_PAYLOAD = {
 ANKO_FAN_PAYLOAD = {
     "1": True,
     "1": True,
     "2": "normal",
     "2": "normal",
-    "3": 1,
+    "3": "1",
     "4": "off",
     "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):
     def test_speed(self):
         self.dps[PRESET_DPS] = "normal"
         self.dps[PRESET_DPS] = "normal"
-        self.dps[SPEED_DPS] = 4
+        self.dps[SPEED_DPS] = "4"
         self.assertEqual(self.subject.percentage, 50)
         self.assertEqual(self.subject.percentage, 50)
 
 
     def test_speed_step(self):
     def test_speed_step(self):
@@ -152,12 +152,12 @@ class TestAnkoFan(IsolatedAsyncioTestCase):
 
 
     async def test_set_speed_in_normal_mode(self):
     async def test_set_speed_in_normal_mode(self):
         self.dps[PRESET_DPS] = "normal"
         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)
             await self.subject.async_set_percentage(25)
 
 
     async def test_set_speed_in_normal_mode_snaps(self):
     async def test_set_speed_in_normal_mode_snaps(self):
         self.dps[PRESET_DPS] = "normal"
         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)
             await self.subject.async_set_percentage(80)
 
 
     def test_device_state_attributes(self):
     def test_device_state_attributes(self):