@@ -233,7 +233,8 @@ def __init__(self) -> None:
233233 self ._elga : bool
234234 self ._gw_allowed_modes : list [str ] = []
235235 self ._heater_id : str
236- self ._home_location : str
236+ self ._home_loc_id : str
237+ self ._home_location : etree
237238 self ._is_thermostat : bool
238239 self ._last_active : dict [str , str | None ]
239240 self ._last_modified : dict [str , str ] = {}
@@ -311,10 +312,10 @@ def _all_appliances(self) -> None:
311312 appl .location = None
312313 if (appl_loc := appliance .find ("location" )) is not None :
313314 appl .location = appl_loc .attrib ["id" ]
314- # Don't assign the _home_location to thermostat-devices without a location,
315+ # Don't assign the _home_loc_id to thermostat-devices without a location,
315316 # they are not active
316317 elif appl .pwclass not in THERMOSTAT_CLASSES :
317- appl .location = self ._home_location
318+ appl .location = self ._home_loc_id
318319
319320 # Don't show orphaned thermostat-types
320321 if appl .pwclass in THERMOSTAT_CLASSES and appl .location is None :
@@ -338,7 +339,6 @@ def _all_appliances(self) -> None:
338339 self ._create_gw_entities (appl )
339340
340341 if self .smile_type == "power" :
341- LOGGER .debug ("HOI home-loc: %s" , self ._home_location )
342342 self ._get_p1_smartmeter_info ()
343343
344344 # Sort the gw_entities
@@ -351,23 +351,16 @@ def _get_p1_smartmeter_info(self) -> None:
351351 switched to maintain backward compatibility with existing implementations.
352352 """
353353 appl = Munch ()
354- loc_id = next (iter (self ._loc_data .keys ()))
355- LOGGER .debug ("HOI loc_id: %s" , loc_id )
356- if (
357- location := self ._domain_objects .find (f'./location[@id="{ loc_id } "]' )
358- ) is None :
359- return
360-
361354 locator = MODULE_LOCATOR
362- module_data = self ._get_module_data (location , locator )
355+ module_data = self ._get_module_data (self . _home_location , locator )
363356 if not module_data ["contents" ]:
364357 LOGGER .error ("No module data found for SmartMeter" ) # pragma: no cover
365358 return # pragma: no cover
366359 appl .available = None
367360 appl .entity_id = self .gateway_id
368361 appl .firmware = module_data ["firmware_version" ]
369362 appl .hardware = module_data ["hardware_version" ]
370- appl .location = loc_id
363+ appl .location = self . _home_loc_id
371364 appl .mac = None
372365 appl .model = module_data ["vendor_model" ]
373366 appl .model_id = None # don't use model_id for SmartMeter
@@ -377,8 +370,8 @@ def _get_p1_smartmeter_info(self) -> None:
377370 appl .zigbee_mac = None
378371
379372 # Replace the entity_id of the gateway by the smartmeter location_id
380- self .gw_entities [loc_id ] = self .gw_entities .pop (self .gateway_id )
381- self .gateway_id = loc_id
373+ self .gw_entities [self . _home_loc_id ] = self .gw_entities .pop (self .gateway_id )
374+ self .gateway_id = self . _home_loc_id
382375
383376 self ._create_gw_entities (appl )
384377
@@ -400,10 +393,14 @@ def _all_locations(self) -> None:
400393 for location in locations :
401394 loc .name = location .find ("name" ).text
402395 loc .loc_id = location .attrib ["id" ]
403- if loc .name == "Home" :
404- self ._home_location = loc .loc_id
405-
406396 self ._loc_data [loc .loc_id ] = {"name" : loc .name }
397+ if loc .name != "Home" :
398+ continue
399+
400+ self ._home_loc_id = loc .loc_id
401+ self ._home_location = self ._domain_objects .find (
402+ f"./location[@id='{ loc .loc_id } ']"
403+ )
407404
408405 def _appliance_info_finder (self , appl : Munch , appliance : etree ) -> Munch :
409406 """Collect info for all appliances found."""
@@ -772,7 +769,7 @@ def _get_gateway_outdoor_temp(self, entity_id: str, data: GwEntityData) -> None:
772769 """
773770 if self ._is_thermostat and entity_id == self .gateway_id :
774771 outdoor_temperature = self ._object_value (
775- self ._home_location , "outdoor_temperature"
772+ self ._home_loc_id , "outdoor_temperature"
776773 )
777774 if outdoor_temperature is not None :
778775 data .update ({"sensors" : {"outdoor_temperature" : outdoor_temperature }})
0 commit comments