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

Use config_id to index unit test entities.

This will allow multiple entities of the same type to be tested.

- Remove some unnecessary names that are the same as the entitiy type.
- Add a missing translation.
Jason Rumney 4 лет назад
Родитель
Сommit
8346b944e7
31 измененных файлов с 48 добавлено и 55 удалено
  1. 0 1
      custom_components/tuya_local/devices/deta_fan.yaml
  2. 0 1
      custom_components/tuya_local/devices/eanons_humidifier.yaml
  3. 0 1
      custom_components/tuya_local/devices/electriq_cd20pro_dehumidifier.yaml
  4. 0 1
      custom_components/tuya_local/devices/electriq_cd25pro_dehumidifier.yaml
  5. 0 1
      custom_components/tuya_local/devices/goldair_dehumidifier.yaml
  6. 0 1
      custom_components/tuya_local/devices/lexy_f501_fan.yaml
  7. 4 5
      custom_components/tuya_local/translations/en.json
  8. 4 4
      tests/devices/base_device_tests.py
  9. 1 1
      tests/devices/test_awow_th213_thermostat.py
  10. 2 2
      tests/devices/test_beca_bhp6000_thermostat.py
  11. 2 2
      tests/devices/test_beca_bht6000_thermostat.py
  12. 1 1
      tests/devices/test_deta_fan.py
  13. 2 2
      tests/devices/test_eanons_humidifier.py
  14. 2 2
      tests/devices/test_electriq_12wminv_heatpump.py
  15. 1 1
      tests/devices/test_electriq_cd12_dehumidifier.py
  16. 2 2
      tests/devices/test_electriq_cd20_dehumidifier.py
  17. 3 3
      tests/devices/test_electriq_cd25_dehumidifier.py
  18. 2 2
      tests/devices/test_electriq_desd9lw_dehumidifier.py
  19. 4 4
      tests/devices/test_goldair_dehumidifier.py
  20. 1 1
      tests/devices/test_goldair_fan.py
  21. 1 1
      tests/devices/test_goldair_geco_heater.py
  22. 1 1
      tests/devices/test_goldair_gpcv_heater.py
  23. 2 2
      tests/devices/test_goldair_gpph_heater.py
  24. 1 1
      tests/devices/test_kogan_kahtp_heater.py
  25. 1 1
      tests/devices/test_kogan_kawfhtp_heater.py
  26. 2 2
      tests/devices/test_lexy_f501_fan.py
  27. 2 2
      tests/devices/test_purline_m100_heater.py
  28. 3 3
      tests/devices/test_renpho_rp_ap001s.py
  29. 1 1
      tests/devices/test_saswell_c16_thermostat.py
  30. 1 1
      tests/devices/test_wetair_wch750_heater.py
  31. 2 2
      tests/test_fan.py

+ 0 - 1
custom_components/tuya_local/devices/deta_fan.yaml

@@ -18,7 +18,6 @@ primary_entity:
       name: timer
 secondary_entities:
   - entity: light
-    name: Light
     dps:
       - id: 9
         type: boolean

+ 0 - 1
custom_components/tuya_local/devices/eanons_humidifier.yaml

@@ -1,7 +1,6 @@
 name: Eanons/pureenjoy Humidifier
 primary_entity:
   entity: humidifier
-  name: Humidifier
   class: humidifier
   dps:
     - id: 3

+ 0 - 1
custom_components/tuya_local/devices/electriq_cd20pro_dehumidifier.yaml

@@ -50,7 +50,6 @@ primary_entity:
       readonly: true
 secondary_entities:
   - entity: fan
-    name: Fan
     dps:
       - id: 1
         type: boolean

+ 0 - 1
custom_components/tuya_local/devices/electriq_cd25pro_dehumidifier.yaml

@@ -48,7 +48,6 @@ primary_entity:
       readonly: true
 secondary_entities:
   - entity: fan
-    name: Fan
     dps:
       - id: 1
         type: boolean

+ 0 - 1
custom_components/tuya_local/devices/goldair_dehumidifier.yaml

@@ -80,7 +80,6 @@ primary_entity:
       readonly: true
 secondary_entities:
   - entity: fan
-    name: Fan
     dps:
       - id: 1
         type: boolean

+ 0 - 1
custom_components/tuya_local/devices/lexy_f501_fan.yaml

@@ -48,7 +48,6 @@ primary_entity:
         - scale: 0.15
 secondary_entities:
   - entity: light
-    name: Light
     dps:
       - id: 9
         name: switch

+ 4 - 5
custom_components/tuya_local/translations/en.json

@@ -29,12 +29,9 @@
 		    "light": "Include a light entity",
 		    "lock": "Include a lock entity",
 		    "switch": "Include a switch entity",
-		    "fan_fan": "Include a fan entity",
 		    "fan_intensity": "Include intensity as a fan entitiy",
-		    "humidifier_humidifier": "Include a humidifier entity",
 		    "light_aq_indicator": "Include AQ indicator as a light entity",
 		    "light_display": "Include display as a light entity",
-		    "light_light": "Include a light entity",
 		    "light_uv_sterilization": "Include UV sterilization as a light entitiy",
 		    "lock_child_lock": "Include child lock as a lock entity",
 		    "switch_air_clean": "Include air clean as a switch entity",
@@ -42,7 +39,8 @@
 		    "switch_master": "Include master switch as a switch entity",
 		    "switch_open_window_detector": "Include open window detect as a switch entity",
 		    "switch_sleep": "Include sleep mode as a switch entity",
-		    "switch_sound": "Include sound mute as a switch entity"
+		    "switch_sound": "Include sound mute as a switch entity",
+		    "switch_uv_sterilization": "Include UV sterilization as a switch"
 		}
 	}
     },
@@ -81,7 +79,8 @@
 		"switch_master": "Include master switch as a switch entity",
 		"switch_open_window_detector": "Include open window detect as a switch entity",
 		"switch_sleep": "Include sleep mode as a switch entity",
-		"switch_sound": "Include sound mute as a switch entity"
+		"switch_sound": "Include sound mute as a switch entity",
+		    "switch_uv_sterilization": "Include UV sterilization as a switch"
             }
 	}
     },

+ 4 - 4
tests/devices/base_device_tests.py

@@ -39,15 +39,15 @@ class TuyaDeviceTestCase(IsolatedAsyncioTestCase):
         self.mock_device.name = cfg.name
 
         self.entities = {}
-        self.entities[cfg.primary_entity.entity] = self.create_entity(
+        self.entities[cfg.primary_entity.config_id] = self.create_entity(
             cfg.primary_entity
         )
 
         self.names = {}
-        self.names[cfg.primary_entity.entity] = cfg.primary_entity.name
+        self.names[cfg.primary_entity.config_id] = cfg.primary_entity.name
         for e in cfg.secondary_entities():
-            self.entities[e.entity] = self.create_entity(e)
-            self.names[e.entity] = e.name
+            self.entities[e.config_id] = self.create_entity(e)
+            self.names[e.config_id] = e.name
 
     def create_entity(self, config):
         """Create an entity to match the config"""

+ 1 - 1
tests/devices/test_awow_th213_thermostat.py

@@ -36,7 +36,7 @@ class TestAwowTH213Thermostat(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("awow_th213_thermostat.yaml", TH213_THERMOSTAT_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_beca_bhp6000_thermostat.py

@@ -29,8 +29,8 @@ class TestBecaBHP6000Thermostat(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("beca_bhp6000_thermostat_f.yaml", BECA_BHP6000_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
+        self.light = self.entities.get("light_display")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_beca_bht6000_thermostat.py

@@ -32,8 +32,8 @@ class TestBecaBHT6000Thermostat(TuyaDeviceTestCase):
             BECA_BHT6000_PAYLOAD,
         )
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
+        self.light = self.entities.get("light_display")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_deta_fan.py

@@ -22,7 +22,7 @@ class TestDetaFan(TuyaDeviceTestCase):
         self.setUpForConfig("deta_fan.yaml", DETA_FAN_PAYLOAD)
         self.subject = self.entities["fan"]
         self.light = self.entities["light"]
-        self.switch = self.entities["switch"]
+        self.switch = self.entities["switch_master"]
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_eanons_humidifier.py

@@ -42,8 +42,8 @@ class TestEanonsHumidifier(TuyaDeviceTestCase):
         self.setUpForConfig("eanons_humidifier.yaml", EANONS_HUMIDIFIER_PAYLOAD)
         self.subject = self.entities["humidifier"]
         self.climate = self.entities["climate"]
-        self.switch = self.entities["switch"]
-        self.fan = self.entities["fan"]
+        self.switch = self.entities["switch_uv_sterilization"]
+        self.fan = self.entities["fan_intensity"]
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_electriq_12wminv_heatpump.py

@@ -42,8 +42,8 @@ class TestElectriq12WMINVHeatpump(TuyaDeviceTestCase):
             "electriq_12wminv_heatpump.yaml", ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD
         )
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.switch = self.entities.get("switch")
+        self.light = self.entities.get("light_display")
+        self.switch = self.entities.get("switch_sleep")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_electriq_cd12_dehumidifier.py

@@ -22,7 +22,7 @@ class TestElectriqCD20ProDehumidifier(TuyaDeviceTestCase):
             "electriq_cd12pw_dehumidifier.yaml", ELECTRIQ_CD12PW_DEHUMIDIFIER_PAYLOAD
         )
         self.subject = self.entities.get("humidifier")
-        self.light = self.entities.get("light")
+        self.light = self.entities.get("light_display")
 
     def test_supported_features(self):
         self.assertEqual(self.subject.supported_features, SUPPORT_MODES)

+ 2 - 2
tests/devices/test_electriq_cd20_dehumidifier.py

@@ -27,8 +27,8 @@ class TestElectriqCD20ProDehumidifier(TuyaDeviceTestCase):
         )
         self.subject = self.entities.get("humidifier")
         self.fan = self.entities.get("fan")
-        self.light = self.entities.get("light")
-        self.switch = self.entities.get("switch")
+        self.light = self.entities.get("light_display")
+        self.switch = self.entities.get("switch_uv_sterilization")
 
     def test_supported_features(self):
         self.assertEqual(self.subject.supported_features, SUPPORT_MODES)

+ 3 - 3
tests/devices/test_electriq_cd25_dehumidifier.py

@@ -27,9 +27,9 @@ class TestElectriqCD25ProDehumidifier(TuyaDeviceTestCase):
         )
         self.subject = self.entities.get("humidifier")
         self.fan = self.entities.get("fan")
-        self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
-        self.switch = self.entities.get("switch")
+        self.light = self.entities.get("light_uv_sterilization")
+        self.lock = self.entities.get("lock_child_lock")
+        self.switch = self.entities.get("switch_ionizer")
 
     def test_supported_features(self):
         self.assertEqual(self.subject.supported_features, SUPPORT_MODES)

+ 2 - 2
tests/devices/test_electriq_desd9lw_dehumidifier.py

@@ -36,8 +36,8 @@ class TestElectriqDESD9LWDehumidifier(TuyaDeviceTestCase):
             ELECTRIQ_DESD9LW_DEHUMIDIFIER_PAYLOAD,
         )
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.switch = self.entities.get("switch")
+        self.light = self.entities.get("light_uv_sterilization")
+        self.switch = self.entities.get("switch_ionizer")
 
     def test_supported_features(self):
         self.assertEqual(

+ 4 - 4
tests/devices/test_goldair_dehumidifier.py

@@ -47,10 +47,10 @@ class TestGoldairDehumidifier(TuyaDeviceTestCase):
         self.setUpForConfig("goldair_dehumidifier.yaml", DEHUMIDIFIER_PAYLOAD)
         self.subject = self.entities.get("humidifier")
         self.fan = self.entities.get("fan")
-        self.climate = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
-        self.switch = self.entities.get("switch")
+        self.climate = self.entities.get("climate_dehumidifier_as_climate")
+        self.light = self.entities.get("light_display")
+        self.lock = self.entities.get("lock_child_lock")
+        self.switch = self.entities.get("switch_air_clean")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_goldair_fan.py

@@ -37,7 +37,7 @@ class TestGoldairFan(TuyaDeviceTestCase):
         self.setUpForConfig("goldair_fan.yaml", FAN_PAYLOAD)
         self.subject = self.entities.get("fan")
         self.climate = self.entities.get("climate")
-        self.light = self.entities.get("light")
+        self.light = self.entities.get("light_display")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_goldair_geco_heater.py

@@ -24,7 +24,7 @@ class TestGoldairGECOHeater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("goldair_geco_heater.yaml", GECO_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_goldair_gpcv_heater.py

@@ -26,7 +26,7 @@ class TestGoldairGPCVHeater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("goldair_gpcv_heater.yaml", GPCV_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_goldair_gpph_heater.py

@@ -36,8 +36,8 @@ class TestGoldairHeater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("goldair_gpph_heater.yaml", GPPH_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
+        self.light = self.entities.get("light_display")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_kogan_kahtp_heater.py

@@ -25,7 +25,7 @@ class TestGoldairKoganKAHTPHeater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("kogan_kahtp_heater.yaml", KOGAN_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_kogan_kawfhtp_heater.py

@@ -25,7 +25,7 @@ class TestGoldairKoganKAHTPHeater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("kogan_kawfhtp_heater.yaml", KOGAN_KAWFHTP_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_lexy_f501_fan.py

@@ -28,8 +28,8 @@ class TestLexyF501Fan(TuyaDeviceTestCase):
         self.setUpForConfig("lexy_f501_fan.yaml", LEXY_F501_PAYLOAD)
         self.subject = self.entities.get("fan")
         self.light = self.entities.get("light")
-        self.lock = self.entities.get("lock")
-        self.switch = self.entities.get("switch")
+        self.lock = self.entities.get("lock_child_lock")
+        self.switch = self.entities.get("switch_sound")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/devices/test_purline_m100_heater.py

@@ -36,8 +36,8 @@ class TestPulineM100Heater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("purline_m100_heater.yaml", PURLINE_M100_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
-        self.switch = self.entities.get("switch")
+        self.light = self.entities.get("light_display")
+        self.switch = self.entities.get("switch_open_window_detector")
 
     def test_supported_features(self):
         self.assertEqual(

+ 3 - 3
tests/devices/test_renpho_rp_ap001s.py

@@ -26,9 +26,9 @@ class TestRenphoPurifier(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("renpho_rp_ap001s.yaml", RENPHO_PURIFIER_PAYLOAD)
         self.subject = self.entities["fan"]
-        self.light = self.entities["light"]
-        self.lock = self.entities["lock"]
-        self.switch = self.entities["switch"]
+        self.light = self.entities["light_aq_indicator"]
+        self.lock = self.entities["lock_child_lock"]
+        self.switch = self.entities["switch_sleep"]
 
     def test_supported_features(self):
         self.assertEqual(self.subject.supported_features, SUPPORT_PRESET_MODE)

+ 1 - 1
tests/devices/test_saswell_c16_thermostat.py

@@ -45,7 +45,7 @@ class TestSaswellC16Thermostat(TuyaDeviceTestCase):
             "saswell_c16_thermostat.yaml", SASWELL_C16_THERMOSTAT_PAYLOAD
         )
         self.subject = self.entities.get("climate")
-        self.lock = self.entities.get("lock")
+        self.lock = self.entities.get("lock_child_lock")
 
     def test_supported_features(self):
         self.assertEqual(

+ 1 - 1
tests/devices/test_wetair_wch750_heater.py

@@ -30,7 +30,7 @@ class TestWetairWCH750Heater(TuyaDeviceTestCase):
     def setUp(self):
         self.setUpForConfig("wetair_wch750_heater.yaml", WETAIR_WCH750_HEATER_PAYLOAD)
         self.subject = self.entities.get("climate")
-        self.light = self.entities.get("light")
+        self.light = self.entities.get("light_display")
 
     def test_supported_features(self):
         self.assertEqual(

+ 2 - 2
tests/test_fan.py

@@ -40,7 +40,7 @@ async def test_init_entry_as_secondary(hass):
         data={
             CONF_TYPE: "goldair_dehumidifier",
             CONF_DEVICE_ID: "dummy",
-            "fan_fan": True,
+            CONF_FAN: True,
         },
     )
     # although async, the async_add_entities function passed to
@@ -54,7 +54,7 @@ async def test_init_entry_as_secondary(hass):
     hass.data[DOMAIN]["dummy"]["device"] = m_device
 
     await async_setup_entry(hass, entry, m_add_entities)
-    assert type(hass.data[DOMAIN]["dummy"]["fan_fan"]) == TuyaLocalFan
+    assert type(hass.data[DOMAIN]["dummy"][CONF_FAN]) == TuyaLocalFan
     m_add_entities.assert_called_once()