@@ -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 :
@@ -350,22 +351,16 @@ def _get_p1_smartmeter_info(self) -> None:
350351 switched to maintain backward compatibility with existing implementations.
351352 """
352353 appl = Munch ()
353- loc_id = next (iter (self ._loc_data .keys ()))
354- if (
355- location := self ._domain_objects .find (f'./location[@id="{ loc_id } "]' )
356- ) is None :
357- return
358-
359354 locator = MODULE_LOCATOR
360- module_data = self ._get_module_data (location , locator )
355+ module_data = self ._get_module_data (self . _home_location , locator )
361356 if not module_data ["contents" ]:
362357 LOGGER .error ("No module data found for SmartMeter" ) # pragma: no cover
363358 return # pragma: no cover
364359 appl .available = None
365360 appl .entity_id = self .gateway_id
366361 appl .firmware = module_data ["firmware_version" ]
367362 appl .hardware = module_data ["hardware_version" ]
368- appl .location = loc_id
363+ appl .location = self . _home_loc_id
369364 appl .mac = None
370365 appl .model = module_data ["vendor_model" ]
371366 appl .model_id = None # don't use model_id for SmartMeter
@@ -375,8 +370,8 @@ def _get_p1_smartmeter_info(self) -> None:
375370 appl .zigbee_mac = None
376371
377372 # Replace the entity_id of the gateway by the smartmeter location_id
378- self .gw_entities [loc_id ] = self .gw_entities .pop (self .gateway_id )
379- 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
380375
381376 self ._create_gw_entities (appl )
382377
@@ -398,10 +393,14 @@ def _all_locations(self) -> None:
398393 for location in locations :
399394 loc .name = location .find ("name" ).text
400395 loc .loc_id = location .attrib ["id" ]
401- if loc .name == "Home" :
402- self ._home_location = loc .loc_id
403-
404396 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+ )
405404
406405 def _appliance_info_finder (self , appl : Munch , appliance : etree ) -> Munch :
407406 """Collect info for all appliances found."""
@@ -532,7 +531,7 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
532531 # !! DON'T CHANGE below two if-lines, will break stuff !!
533532 if self .smile_type == "power" :
534533 if entity ["dev_class" ] == "smartmeter" :
535- data .update (self ._power_data_from_location (entity [ "location" ] ))
534+ data .update (self ._power_data_from_location ())
536535
537536 return data
538537
@@ -574,18 +573,17 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
574573
575574 return data
576575
577- def _power_data_from_location (self , loc_id : str ) -> GwEntityData :
576+ def _power_data_from_location (self ) -> GwEntityData :
578577 """Helper-function for smile.py: _get_entity_data().
579578
580- Collect the power-data based on Location ID, from LOCATIONS .
579+ Collect the power-data from the Home location .
581580 """
582581 data : GwEntityData = {"sensors" : {}}
583582 loc = Munch ()
584583 log_list : list [str ] = ["point_log" , "cumulative_log" , "interval_log" ]
585584 t_string = "tariff"
586585
587- search = self ._domain_objects
588- loc .logs = search .find (f'./location[@id="{ loc_id } "]/logs' )
586+ loc .logs = self ._home_location .find ("./logs" )
589587 for loc .measurement , loc .attrs in P1_MEASUREMENTS .items ():
590588 for loc .log_type in log_list :
591589 self ._collect_power_values (data , loc , t_string )
@@ -764,31 +762,14 @@ def _get_gateway_mode(
764762 self ._count += 1
765763
766764 def _get_gateway_outdoor_temp (self , entity_id : str , data : GwEntityData ) -> None :
767- """Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS.
768-
769- Available under the Home location.
770- """
765+ """Adam & Anna: the Smile outdoor_temperature is present in the Home location."""
771766 if self ._is_thermostat and entity_id == self .gateway_id :
772- outdoor_temperature = self ._object_value (
773- self ._home_location , "outdoor_temperature"
774- )
775- if outdoor_temperature is not None :
776- data .update ({"sensors" : {"outdoor_temperature" : outdoor_temperature }})
767+ locator = "./logs/point_log[type='outdoor_temperature']/period/measurement"
768+ if (found := self ._home_location .find (locator )) is not None :
769+ value = format_measure (found .text , NONE )
770+ data .update ({"sensors" : {"outdoor_temperature" : value }})
777771 self ._count += 1
778772
779- def _object_value (self , obj_id : str , measurement : str ) -> float | int | None :
780- """Helper-function for smile.py: _get_entity_data().
781-
782- Obtain the value/state for the given object from a location in DOMAIN_OBJECTS
783- """
784- val : float | int | None = None
785- search = self ._domain_objects
786- locator = f'./location[@id="{ obj_id } "]/logs/point_log[type="{ measurement } "]/period/measurement'
787- if (found := search .find (locator )) is not None :
788- val = format_measure (found .text , NONE )
789-
790- return val
791-
792773 def _process_c_heating_state (self , data : GwEntityData ) -> None :
793774 """Helper-function for _get_measurement_data().
794775
0 commit comments