소스 검색

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 년 전
부모
커밋
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
 
     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):