Skip to content

Commit e801308

Browse files
committed
_get_module_data(): add key argument
making it possible to search for a more specific module tag
1 parent a16adc8 commit e801308

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

plugwise/common.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def _appl_heater_central_info(
9898
# xml_1: appliance
9999
# xml_3: self._modules for legacy, self._domain_objects for actual
100100
xml_3 = return_valid(xml_3, self._domain_objects)
101-
module_data = self._get_module_data(xml_1, locator_1, xml_3)
101+
module_data = self._get_module_data(xml_1, locator_1, xml_2=xml_3)
102102
if not module_data["contents"]:
103-
module_data = self._get_module_data(xml_1, locator_2, xml_3)
103+
module_data = self._get_module_data(xml_1, locator_2, xml_2=xml_3)
104104
if not module_data["contents"]:
105105
self._heater_id = NONE
106106
return (
@@ -121,7 +121,7 @@ def _appl_thermostat_info(
121121
"""Helper-function for _appliance_info_finder()."""
122122
locator = "./logs/point_log[type='thermostat']/thermostat"
123123
xml_2 = return_valid(xml_2, self._domain_objects)
124-
module_data = self._get_module_data(xml_1, locator, xml_2)
124+
module_data = self._get_module_data(xml_1, locator, xml_2=xml_2)
125125
if not module_data["contents"]:
126126
return Munch() # no module-data present means the device has been removed
127127

@@ -239,6 +239,7 @@ def _get_module_data(
239239
self,
240240
xml_1: etree.Element,
241241
locator: str,
242+
key: str | None = None,
242243
xml_2: etree.Element = None,
243244
legacy: bool = False,
244245
) -> ModuleData:
@@ -256,8 +257,11 @@ def _get_module_data(
256257
"zigbee_mac_address": None,
257258
}
258259

259-
if (appl_search := xml_1.find(locator)) is not None:
260+
for appl_search in xml_1.findall(locator):
260261
link_tag = appl_search.tag
262+
if key is not None and key not in link_tag:
263+
continue
264+
261265
link_id = appl_search.attrib["id"]
262266
loc = f".//services/{link_tag}[@id='{link_id}']...."
263267
# Not possible to walrus for some reason...
@@ -272,4 +276,6 @@ def _get_module_data(
272276
module_data["firmware_version"] = module.find("firmware_version").text
273277
get_zigbee_data(module, module_data, legacy)
274278

279+
break
280+
275281
return module_data

plugwise/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def _get_p1_smartmeter_info(self) -> None:
164164
"""
165165
appl = Munch()
166166
locator = MODULE_LOCATOR
167-
module_data = self._get_module_data(self._home_location, locator)
167+
tag = "electricity"
168+
module_data = self._get_module_data(self._home_location, locator, key=tag)
168169
# No module-data present means the device has been removed
169170
if not module_data["contents"]: # pragma: no cover
170171
return

plugwise/legacy/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _energy_entity_info_finder(self, appliance: etree, appl: Munch) -> Munch:
212212
if self.smile.type in ("power", "stretch"):
213213
locator = "./services/electricity_point_meter"
214214
module_data = self._get_module_data(
215-
appliance, locator, self._modules, legacy=True
215+
appliance, locator, xml_2=self._modules, legacy=True
216216
)
217217
if not module_data["contents"]:
218218
return (

0 commit comments

Comments
 (0)