@@ -283,8 +283,6 @@ def _all_appliances(self) -> None:
283283
284284 Also, collect the P1 smartmeter info from a location
285285 as this one is not available as an appliance.
286- Note: For P1, the entity_id for the gateway and smartmeter are
287- switched to maintain backward compatibility with existing implementations.
288286 """
289287 self ._count = 0
290288 self ._all_locations ()
@@ -337,11 +335,6 @@ def _all_appliances(self) -> None:
337335 if not (appl := self ._appliance_info_finder (appl , appliance )):
338336 continue
339337
340- # P1: for gateway and smartmeter switch entity_id - part 1
341- # This is done to avoid breakage in HA Core
342- if appl .pwclass == "gateway" and self .smile_type == "power" :
343- appl .entity_id = appl .location
344-
345338 self ._create_gw_entities (appl )
346339
347340 # Collect P1 Smartmeter info
@@ -351,15 +344,25 @@ def _all_appliances(self) -> None:
351344 self ._sort_gw_entities ()
352345
353346 def _get_smartmeter_info (self ) -> None :
354- """For P1 collect the connected SmartMeter info from the Home/building location."""
347+ """For P1 collect the connected SmartMeter info from the Home/building location.
348+
349+ Note: For P1, the entity_id for the gateway and smartmeter are
350+ switched to maintain backward compatibility with existing implementations.
351+ """
355352 if self .smile_type == "power" :
356353 self ._p1_smartmeter_info_finder ()
357- # P1: for gateway and smartmeter switch entity_id - part 2
358- for item in self .gw_entities :
359- if item != self .gateway_id :
360- self .gateway_id = item
361- # Leave for-loop to avoid a 2nd entity_id switch
362- break
354+ # Switch entity_ids
355+ entity_id_0 = list (self .gw_entities )[0 ]
356+ entity_0 = list (self .gw_entities .values ())[0 ]
357+ entity_id_1 = list (self .gw_entities )[1 ]
358+ entity_1 = list (self .gw_entities .values ())[1 ]
359+ self .gw_entities [entity_id_0 ] = entity_1
360+ self .gw_entities [entity_id_1 ] = entity_0
361+ # Update gateway_id
362+ if entity_id_0 == self .gateway_id :
363+ self .gateway_id = entity_id_1
364+ else :
365+ self .gateway_id = entity_id_0
363366
364367 def _sort_gw_entities (self ) -> None :
365368 """Place the gateway and optional heater_central entities as 1st and 2nd."""
0 commit comments