Просмотр исходного кода

Tighten the detection of Kogan Heater.

Avoid misdetecting non-functioning devices as Kogan Heater, require some properties to be present. Detected due to test coverage indicating that Kogan heater detection was covered when there was no specific case for it.

Improve test coverage for device by adding test cases for auto-detection of Kogan devices.
Jason Rumney 5 лет назад
Родитель
Сommit
4d3702bce0
2 измененных файлов с 17 добавлено и 1 удалено
  1. 1 1
      custom_components/tuya_local/device.py
  2. 16 0
      tests/test_device.py

+ 1 - 1
custom_components/tuya_local/device.py

@@ -88,7 +88,7 @@ class TuyaLocalDevice(object):
             cached_state = self._get_cached_state()
 
         _LOGGER.debug(f"Inferring device type from cached state: {cached_state}")
-        if "1" not in cached_state:
+        if "1" not in cached_state and "3" in cached_state:
             _LOGGER.info(f"Detecting {self.name} as Kogan Heater")
             return CONF_TYPE_KOGAN_HEATER
         if "5" in cached_state and "3" not in cached_state and "103" in cached_state:

+ 16 - 0
tests/test_device.py

@@ -12,6 +12,8 @@ from custom_components.tuya_local.const import (
     CONF_TYPE_GECO_HEATER,
     CONF_TYPE_GPCV_HEATER,
     CONF_TYPE_GPPH_HEATER,
+    CONF_TYPE_KOGAN_HEATER,
+    CONF_TYPE_KOGAN_SWITCH,
 )
 from custom_components.tuya_local.device import TuyaLocalDevice
 
@@ -21,6 +23,8 @@ from .const import (
     GECO_HEATER_PAYLOAD,
     GPCV_HEATER_PAYLOAD,
     GPPH_HEATER_PAYLOAD,
+    KOGAN_HEATER_PAYLOAD,
+    KOGAN_SOCKET_PAYLOAD,
 )
 
 
@@ -102,6 +106,18 @@ class TestDevice(IsolatedAsyncioTestCase):
         self.subject._cached_state = FAN_PAYLOAD
         self.assertEqual(await self.subject.async_inferred_type(), CONF_TYPE_FAN)
 
+    async def test_detects_kogan_heater_payload(self):
+        self.subject._cached_state = KOGAN_HEATER_PAYLOAD
+        self.assertEqual(
+            await self.subject.async_inferred_type(), CONF_TYPE_KOGAN_HEATER
+        )
+
+    async def test_detects_kogan_socket_payload(self):
+        self.subject._cached_state = KOGAN_SOCKET_PAYLOAD
+        self.assertEqual(
+            await self.subject.async_inferred_type(), CONF_TYPE_KOGAN_SWITCH
+        )
+
     async def test_detection_returns_none_when_device_type_could_not_be_detected(self):
         self.subject._cached_state = {"1": False}
         self.assertEqual(await self.subject.async_inferred_type(), None)