Procházet zdrojové kódy

Remove explicit conf_types for individual devices.

All conf type info can now be built up dynamically from the config files.
Jason Rumney před 4 roky
rodič
revize
07ffe2df11

+ 0 - 14
custom_components/tuya_local/const.py

@@ -6,20 +6,6 @@ CONF_DEVICE_ID = "device_id"
 CONF_LOCAL_KEY = "local_key"
 CONF_TYPE = "type"
 CONF_TYPE_AUTO = "auto"
-CONF_TYPE_GPPH_HEATER = "heater"
-CONF_TYPE_DEHUMIDIFIER = "dehumidifier"
-CONF_TYPE_FAN = "fan"
-CONF_TYPE_GECO_HEATER = "geco_heater"
-CONF_TYPE_EUROM_600_HEATER = "eurom_heater"
-CONF_TYPE_GPCV_HEATER = "gpcv_heater"
-CONF_TYPE_KOGAN_HEATER = "kogan_heater"
-CONF_TYPE_KOGAN_SWITCH = "kogan_switch"
-CONF_TYPE_GSH_HEATER = "gsh_heater"
-CONF_TYPE_GARDENPAC_HEATPUMP = "gardenpac_heatpump"
-CONF_TYPE_PURLINE_M100_HEATER = "purline_m100_heater"
-CONF_TYPE_EANONS_HUMIDIFIER = "eanons_humidifier"
-CONF_TYPE_REMORA_HEATPUMP = "remora_heatpump"
-CONF_TYPE_INKBIRD_THERMOSTAT = "inkbird_thermostat"
 CONF_CLIMATE = "climate"
 CONF_DISPLAY_LIGHT = "display_light"
 CONF_CHILD_LOCK = "child_lock"

+ 1 - 2
tests/test_climate.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_GPPH_HEATER,
     DOMAIN,
 )
 from custom_components.tuya_local.heater.climate import GoldairHeater
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_GPPH_HEATER)
+    m_device.async_inferred_type = AsyncMock(return_value="heater")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}

+ 12 - 43
tests/test_device.py

@@ -6,19 +6,6 @@ from unittest.mock import AsyncMock, call, patch
 
 from homeassistant.const import TEMP_CELSIUS
 
-from custom_components.tuya_local.const import (
-    CONF_TYPE_DEHUMIDIFIER,
-    CONF_TYPE_FAN,
-    CONF_TYPE_GECO_HEATER,
-    CONF_TYPE_EUROM_600_HEATER,
-    CONF_TYPE_GPCV_HEATER,
-    CONF_TYPE_GPPH_HEATER,
-    CONF_TYPE_GSH_HEATER,
-    CONF_TYPE_KOGAN_HEATER,
-    CONF_TYPE_KOGAN_SWITCH,
-    CONF_TYPE_GARDENPAC_HEATPUMP,
-    CONF_TYPE_PURLINE_M100_HEATER,
-)
 from custom_components.tuya_local.device import TuyaLocalDevice
 
 from .const import (
@@ -101,70 +88,52 @@ class TestDevice(IsolatedAsyncioTestCase):
 
     async def test_detects_eurom_600_heater_payload(self):
         self.subject._cached_state = EUROM_600_HEATER_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_EUROM_600_HEATER
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "eurom_heater")
 
     async def test_detects_geco_heater_payload(self):
         self.subject._cached_state = GECO_HEATER_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_GECO_HEATER
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "geco_heater")
 
     async def test_detects_gpcv_heater_payload(self):
         self.subject._cached_state = GPCV_HEATER_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_GPCV_HEATER
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "gpcv_heater")
 
     async def test_detects_gpph_heater_payload(self):
         self.subject._cached_state = GPPH_HEATER_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_GPPH_HEATER
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "heater")
 
     async def test_detects_dehumidifier_payload(self):
         self.subject._cached_state = DEHUMIDIFIER_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_DEHUMIDIFIER
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "dehumidifier")
 
     async def test_detects_fan_payload(self):
         self.subject._cached_state = FAN_PAYLOAD
-        self.assertEqual(await self.subject.async_inferred_type(), CONF_TYPE_FAN)
+        self.assertEqual(await self.subject.async_inferred_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
-        )
+        self.assertEqual(await self.subject.async_inferred_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
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "kogan_switch")
 
     async def test_detects_kogan_socket_payload2(self):
         self.subject._cached_state = KOGAN_SOCKET_PAYLOAD2
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_KOGAN_SWITCH
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "kogan_switch")
 
     async def test_detects_gsh_heater_payload(self):
         self.subject._cached_state = GSH_HEATER_PAYLOAD
-        self.assertEqual(await self.subject.async_inferred_type(), CONF_TYPE_GSH_HEATER)
+        self.assertEqual(await self.subject.async_inferred_type(), "gsh_heater")
 
     async def test_detects_gardenpac_heatpump_payload(self):
         self.subject._cached_state = GARDENPAC_HEATPUMP_PAYLOAD
-        self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_GARDENPAC_HEATPUMP
-        )
+        self.assertEqual(await self.subject.async_inferred_type(), "gardenpac_heatpump")
 
     async def test_detects_purline_m100_heater_payload(self):
         self.subject._cached_state = PURLINE_M100_HEATER_PAYLOAD
         self.assertEqual(
-            await self.subject.async_inferred_type(), CONF_TYPE_PURLINE_M100_HEATER
+            await self.subject.async_inferred_type(), "purline_m100_heater"
         )
 
     async def test_detects_remora_heatpump_payload(self):

+ 15 - 34
tests/test_device_config.py

@@ -3,23 +3,6 @@ import unittest
 
 from warnings import warn
 
-from custom_components.tuya_local.const import (
-    CONF_TYPE_DEHUMIDIFIER,
-    CONF_TYPE_EUROM_600_HEATER,
-    CONF_TYPE_FAN,
-    CONF_TYPE_GARDENPAC_HEATPUMP,
-    CONF_TYPE_GECO_HEATER,
-    CONF_TYPE_GPCV_HEATER,
-    CONF_TYPE_GPPH_HEATER,
-    CONF_TYPE_GSH_HEATER,
-    CONF_TYPE_KOGAN_HEATER,
-    CONF_TYPE_KOGAN_SWITCH,
-    CONF_TYPE_PURLINE_M100_HEATER,
-    CONF_TYPE_REMORA_HEATPUMP,
-    CONF_TYPE_EANONS_HUMIDIFIER,
-    CONF_TYPE_INKBIRD_THERMOSTAT,
-)
-
 from custom_components.tuya_local.helpers.device_config import (
     available_configs,
     config_for_legacy_use,
@@ -132,13 +115,13 @@ class TestDeviceConfig(unittest.TestCase):
 
     def test_gpph_heater_detection(self):
         """Test that GPPH heater can be detected from its sample payload."""
-        self._test_detect(GPPH_HEATER_PAYLOAD, CONF_TYPE_GPPH_HEATER, "GoldairHeater")
+        self._test_detect(GPPH_HEATER_PAYLOAD, "heater", "GoldairHeater")
 
     def test_gpcv_heater_detection(self):
         """Test that GPCV heater can be detected from its sample payload."""
         self._test_detect(
             GPCV_HEATER_PAYLOAD,
-            CONF_TYPE_GPCV_HEATER,
+            "gpcv_heater",
             None,
         )
 
@@ -146,7 +129,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that Eurom heater can be detected from its sample payload."""
         self._test_detect(
             EUROM_600_HEATER_PAYLOAD,
-            CONF_TYPE_EUROM_600_HEATER,
+            "eurom_heater",
             None,
         )
 
@@ -154,7 +137,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that GECO heater can be detected from its sample payload."""
         self._test_detect(
             GECO_HEATER_PAYLOAD,
-            CONF_TYPE_GECO_HEATER,
+            "geco_heater",
             None,
         )
 
@@ -162,7 +145,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that Kogan heater can be detected from its sample payload."""
         self._test_detect(
             KOGAN_HEATER_PAYLOAD,
-            CONF_TYPE_KOGAN_HEATER,
+            "kogan_heater",
             None,
         )
 
@@ -170,19 +153,19 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that Goldair dehumidifier can be detected from its sample payload."""
         self._test_detect(
             DEHUMIDIFIER_PAYLOAD,
-            CONF_TYPE_DEHUMIDIFIER,
+            "dehumidifier",
             "GoldairDehumidifier",
         )
 
     def test_goldair_fan_detection(self):
         """Test that Goldair fan can be detected from its sample payload."""
-        self._test_detect(FAN_PAYLOAD, CONF_TYPE_FAN, "GoldairFan")
+        self._test_detect(FAN_PAYLOAD, "fan", "GoldairFan")
 
     def test_kogan_socket_detection(self):
         """Test that 1st gen Kogan Socket can be detected from its sample payload."""
         self._test_detect(
             KOGAN_SOCKET_PAYLOAD,
-            CONF_TYPE_KOGAN_SWITCH,
+            "kogan_switch",
             None,
         )
 
@@ -190,7 +173,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that 2nd gen Kogan Socket can be detected from its sample payload."""
         self._test_detect(
             KOGAN_SOCKET_PAYLOAD2,
-            CONF_TYPE_KOGAN_SWITCH,
+            "kogan_switch",
             None,
         )
 
@@ -198,7 +181,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that GSH heater can be detected from its sample payload."""
         self._test_detect(
             GSH_HEATER_PAYLOAD,
-            CONF_TYPE_GSH_HEATER,
+            "gsh_heater",
             None,
         )
 
@@ -206,7 +189,7 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that GardenPac heatpump can be detected from its sample payload."""
         self._test_detect(
             GARDENPAC_HEATPUMP_PAYLOAD,
-            CONF_TYPE_GARDENPAC_HEATPUMP,
+            "gardenpac_heatpump",
             None,
         )
 
@@ -214,24 +197,22 @@ class TestDeviceConfig(unittest.TestCase):
         """Test that Purline heater can be detected from its sample payload."""
         self._test_detect(
             PURLINE_M100_HEATER_PAYLOAD,
-            CONF_TYPE_PURLINE_M100_HEATER,
+            "purline_m100_heater",
             None,
         )
 
     # Non-legacy devices start here.
     def test_remora_heatpump_detection(self):
         """Test that Remora heatpump can be detected from its sample payload."""
-        self._test_detect(REMORA_HEATPUMP_PAYLOAD, CONF_TYPE_REMORA_HEATPUMP, None)
+        self._test_detect(REMORA_HEATPUMP_PAYLOAD, "remora_heatpump", None)
 
     def test_eanons_humidifier(self):
         """Test that Eanons humidifier can be detected from its sample payload."""
-        self._test_detect(EANONS_HUMIDIFIER_PAYLOAD, CONF_TYPE_EANONS_HUMIDIFIER, None)
+        self._test_detect(EANONS_HUMIDIFIER_PAYLOAD, "eanons_humidifier", None)
 
     def test_inkbird_thermostat(self):
         """Test that Inkbird thermostat can be detected from its sample payload."""
-        self._test_detect(
-            INKBIRD_THERMOSTAT_PAYLOAD, CONF_TYPE_INKBIRD_THERMOSTAT, None
-        )
+        self._test_detect(INKBIRD_THERMOSTAT_PAYLOAD, "inkbird_thermostat", None)
 
     def test_anko_fan(self):
         """Test that Anko fan can be detected from its sample payload."""

+ 1 - 2
tests/test_fan.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_FAN,
     DOMAIN,
 )
 from custom_components.tuya_local.generic.fan import TuyaLocalFan
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_FAN)
+    m_device.async_inferred_type = AsyncMock(return_value="fan")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}

+ 1 - 2
tests/test_humidifier.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_DEHUMIDIFIER,
     DOMAIN,
 )
 from custom_components.tuya_local.generic.humidifier import TuyaLocalHumidifier
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_DEHUMIDIFIER)
+    m_device.async_inferred_type = AsyncMock(return_value="dehumidifier")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}

+ 1 - 2
tests/test_light.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_GPPH_HEATER,
     DOMAIN,
 )
 from custom_components.tuya_local.generic.light import TuyaLocalLight
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_GPPH_HEATER)
+    m_device.async_inferred_type = AsyncMock(return_value="heater")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}

+ 1 - 2
tests/test_lock.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_GPPH_HEATER,
     DOMAIN,
 )
 from custom_components.tuya_local.generic.lock import TuyaLocalLock
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_GPPH_HEATER)
+    m_device.async_inferred_type = AsyncMock(return_value="heater")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}

+ 1 - 2
tests/test_switch.py

@@ -7,7 +7,6 @@ from custom_components.tuya_local.const import (
     CONF_SWITCH,
     CONF_TYPE,
     CONF_TYPE_AUTO,
-    CONF_TYPE_KOGAN_SWITCH,
     DOMAIN,
 )
 from custom_components.tuya_local.generic.switch import TuyaLocalSwitch
@@ -25,7 +24,7 @@ async def test_init_entry(hass):
     # AsyncMock, it expects us to await the result.
     m_add_entities = Mock()
     m_device = AsyncMock()
-    m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_KOGAN_SWITCH)
+    m_device.async_inferred_type = AsyncMock(return_value="kogan_switch")
 
     hass.data[DOMAIN] = {}
     hass.data[DOMAIN]["dummy"] = {}