Skip to content

Commit 90527ed

Browse files
committed
Use the _home_location where applicable
1 parent 4010e8c commit 90527ed

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

plugwise/helper.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
531531
# !! DON'T CHANGE below two if-lines, will break stuff !!
532532
if self.smile_type == "power":
533533
if entity["dev_class"] == "smartmeter":
534-
data.update(self._power_data_from_location(entity["location"]))
534+
data.update(self._power_data_from_location())
535535

536536
return data
537537

@@ -573,18 +573,17 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
573573

574574
return data
575575

576-
def _power_data_from_location(self, loc_id: str) -> GwEntityData:
576+
def _power_data_from_location(self) -> GwEntityData:
577577
"""Helper-function for smile.py: _get_entity_data().
578578
579-
Collect the power-data based on Location ID, from LOCATIONS.
579+
Collect the power-data from the Home location.
580580
"""
581581
data: GwEntityData = {"sensors": {}}
582582
loc = Munch()
583583
log_list: list[str] = ["point_log", "cumulative_log", "interval_log"]
584584
t_string = "tariff"
585585

586-
search = self._domain_objects
587-
loc.logs = search.find(f'./location[@id="{loc_id}"]/logs')
586+
loc.logs = self._home_location.find("./logs")
588587
for loc.measurement, loc.attrs in P1_MEASUREMENTS.items():
589588
for loc.log_type in log_list:
590589
self._collect_power_values(data, loc, t_string)
@@ -768,22 +767,19 @@ def _get_gateway_outdoor_temp(self, entity_id: str, data: GwEntityData) -> None:
768767
Available under the Home location.
769768
"""
770769
if self._is_thermostat and entity_id == self.gateway_id:
771-
outdoor_temperature = self._object_value(
772-
self._home_loc_id, "outdoor_temperature"
773-
)
770+
outdoor_temperature = self._home_loc_value("outdoor_temperature")
774771
if outdoor_temperature is not None:
775772
data.update({"sensors": {"outdoor_temperature": outdoor_temperature}})
776773
self._count += 1
777774

778-
def _object_value(self, obj_id: str, measurement: str) -> float | int | None:
775+
def _home_loc_value(self, measurement: str) -> float | int | None:
779776
"""Helper-function for smile.py: _get_entity_data().
780777
781-
Obtain the value/state for the given object from a location in DOMAIN_OBJECTS
778+
Obtain the value/state for the given measurement from the Home location
782779
"""
783780
val: float | int | None = None
784-
search = self._domain_objects
785-
locator = f'./location[@id="{obj_id}"]/logs/point_log[type="{measurement}"]/period/measurement'
786-
if (found := search.find(locator)) is not None:
781+
locator = f'./logs/point_log[type="{measurement}"]/period/measurement'
782+
if (found := self._home_location.find(locator)) is not None:
787783
val = format_measure(found.text, NONE)
788784

789785
return val

0 commit comments

Comments
 (0)