Jelajahi Sumber

Device config: add a test for misspelled secondary_entities

- fix detected issue in asakuki_diffuser

Related to recent issues in #627 and #504 initial configs
Jason Rumney 2 tahun lalu
induk
melakukan
b4f44435e7

+ 1 - 1
custom_components/tuya_local/devices/asakuki_diffuser.yaml

@@ -16,7 +16,7 @@ primary_entity:
           value: 50
         - dps_val: "1"
           value: 100
-secondary_entites:
+secondary_entities:
   - entity: light
     dps:
       - id: 1

+ 11 - 0
tests/test_device_config.py

@@ -306,11 +306,22 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
             )
             self.check_entity(parsed.primary_entity, cfg)
             entities.append(parsed.primary_entity.config_id)
+            secondary = False
             for entity in parsed.secondary_entities():
+                secondary = True
                 self.check_entity(entity, cfg)
                 entities.append(entity.config_id)
+            # check entities are unique
             self.assertCountEqual(entities, set(entities))
 
+            # If there are no secondary entities, check that it is intended
+            if not secondary:
+                for key in parsed._config.keys():
+                    self.assertFalse(
+                        key.startswith("sec"),
+                        f"misspelled secondary_entities in {cfg}",
+                    )
+
     # Most of the device_config functionality is exercised during testing of
     # the various supported devices.  These tests concentrate only on the gaps.