@@ -382,14 +382,14 @@ def _get_p1_smartmeter_info(self) -> None:
382382
383383 def _sort_gw_entities (self ) -> None :
384384 """Place the gateway and optional heater_central entities as 1st and 2nd."""
385- for dev_class in PRIORITY_DEVICE_CLASSES :
386- for entity_id , entity in dict ( self . gw_entities ). items ():
387- if entity [ "dev_class" ] == dev_class :
388- priority_entity = entity
389- self . gw_entities . pop ( entity_id )
390- other_entities = self . gw_entities
391- priority_entities = { entity_id : priority_entity }
392- self .gw_entities = { ** priority_entities , ** other_entities }
385+ def sort_key ( item ) :
386+ entity_id , entity = item
387+ try :
388+ return PRIORITY_DEVICE_CLASSES . index ( entity [ "dev_class" ])
389+ except ValueError :
390+ return len ( PRIORITY_DEVICE_CLASSES )
391+
392+ self .gw_entities = dict ( sorted ( self . gw_entities . items (), key = sort_key ))
393393
394394 def _all_locations (self ) -> None :
395395 """Collect all locations."""
@@ -813,13 +813,10 @@ def _process_on_off_device_c_heating_state(self, data: GwEntityData) -> None:
813813 if self .smile (ADAM ):
814814 # First count when not present, then create and init to False.
815815 # When present init to False
816- if "heating_state" not in data ["binary_sensors" ]:
817- self ._count += 1
818- data ["binary_sensors" ]["heating_state" ] = False
819-
820- if "cooling_state" not in data ["binary_sensors" ]:
821- self ._count += 1
822- data ["binary_sensors" ]["cooling_state" ] = False
816+ for state in ["heating_state" , "cooling_state" ]:
817+ if state not in data ["binary_sensors" ]:
818+ self ._count += 1
819+ data ["binary_sensors" ][state ] = False
823820
824821 if self ._cooling_enabled :
825822 data ["binary_sensors" ]["cooling_state" ] = data ["c_heating_state" ]
0 commit comments