Browse Source

setup/unload: simplify by looping over all entities.

Instead of handling primary and secondary entities separately,
loop over all_entities, as the operations are the same.

Still some primary/secondary separation in the migration code, which
might be different for early versions (though I doubt anyone is migrating
from those in 2024).
Jason Rumney 1 year ago
parent
commit
183a9f8a0f
1 changed files with 2 additions and 7 deletions
  1. 2 7
      custom_components/tuya_local/__init__.py

+ 2 - 7
custom_components/tuya_local/__init__.py

@@ -638,9 +638,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
         return False
 
     entities = set()
-    e = device_conf.primary_entity
-    entities.add(e.entity)
-    for e in device_conf.secondary_entities():
+    for e in device_conf.all_entities():
         entities.add(e.entity)
 
     await hass.config_entries.async_forward_entry_setups(entry, entities)
@@ -663,10 +661,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
         return False
 
     entities = {}
-    e = device_conf.primary_entity
-    if e.config_id in data:
-        entities[e.entity] = True
-    for e in device_conf.secondary_entities():
+    for e in device_conf.all_entities():
         if e.config_id in data:
             entities[e.entity] = True