@@ -268,12 +268,7 @@ def _get_locations(self) -> None:
268268 ):
269269 continue
270270
271- self ._loc_data [loc .loc_id ] = {
272- "name" : loc .name ,
273- "primary" : [],
274- "primary_prio" : 0 ,
275- "secondary" : [],
276- }
271+ self ._loc_data [loc .loc_id ] = {"name" : loc .name }
277272
278273 removed = list (set (self ._existing_locations ) - set (self ._new_locations ))
279274 if self ._existing_locations and removed :
@@ -858,6 +853,7 @@ def _match_and_rank_thermostats(self) -> None:
858853 Match thermostat-appliances with locations, rank them for locations with multiple thermostats.
859854 """
860855 for location_id , location in self ._loc_data .items ():
856+ location .update ({"primary" : [], "primary_prio" : 0 , "secondary" : []})
861857 for entity_id , entity in self .gw_entities .items ():
862858 self ._rank_thermostat (
863859 entity_id , entity , location_id , location , THERMO_MATCHING
@@ -885,20 +881,16 @@ def _rank_thermostat(
885881
886882 # Pre-elect new primary
887883 if thermo_matching [appl_class ] == location ["primary_prio" ]:
888- if entity_id not in location ["primary" ]:
889- location ["primary" ].append (entity_id )
884+ location ["primary" ].append (entity_id )
890885 elif (thermo_rank := thermo_matching [appl_class ]) > location ["primary_prio" ]:
891886 location ["primary_prio" ] = thermo_rank
892887 # Demote former primary
893888 if tl_primary := location ["primary" ]:
894- for item in tl_primary :
895- if item not in location ["secondary" ]:
896- location ["secondary" ].append (item )
897- location ["primary" ].remove (item )
889+ location ["secondary" ] += tl_primary
890+ location ["primary" ] = []
898891 # Crown primary
899- if entity_id not in location ["primary" ]:
900- location ["primary" ].append (entity_id )
901- elif entity_id not in location ["secondary" ]:
892+ location ["primary" ].append (entity_id )
893+ else :
902894 location ["secondary" ].append (entity_id )
903895
904896 def _control_state (self , data : GwEntityData ) -> str | bool :
0 commit comments