Skip to content

Commit b16ba06

Browse files
committed
Partly revert to handle both actual and legacy
1 parent c964847 commit b16ba06

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

plugwise/common.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from plugwise.constants import (
1010
ANNA,
11-
LOGGER,
1211
SPECIAL_PLUG_TYPES,
1312
SWITCH_GROUP_TYPES,
1413
ApplianceType,
@@ -74,13 +73,12 @@ def _appl_heater_central_info(
7473
appl.name = "OpenTherm"
7574
locator_1 = "./logs/point_log[type='flame_state']/boiler_state"
7675
locator_2 = "./services/boiler_state"
77-
mod_type = "boiler_state"
7876
# xml_1: appliance
7977
# xml_3: self._modules for legacy, self._domain_objects for actual
8078
xml_3 = return_valid(xml_3, self._domain_objects)
81-
module_data = self._get_module_data(xml_1, xml_3)
82-
#if not module_data["contents"]:
83-
# module_data = self._get_module_data(xml_1, xml_3)
79+
module_data = self._get_module_data(xml_1, locator_1, xml_3)
80+
if not module_data["contents"]:
81+
module_data = self._get_module_data(xml_1, locator_2, xml_3)
8482
appl.vendor_name = module_data["vendor_name"]
8583
appl.hardware = module_data["hardware_version"]
8684
appl.model_id = module_data["vendor_model"] if not legacy else None
@@ -95,9 +93,8 @@ def _appl_heater_central_info(
9593
def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None) -> Munch:
9694
"""Helper-function for _appliance_info_finder()."""
9795
locator = "./logs/point_log[type='thermostat']/thermostat"
98-
mod_type = "thermostat"
9996
xml_2 = return_valid(xml_2, self._domain_objects)
100-
module_data = self._get_module_data(xml_1, xml_2)
97+
module_data = self._get_module_data(xml_1, locator, xml_2)
10198
appl.vendor_name = module_data["vendor_name"]
10299
appl.model = module_data["vendor_model"]
103100
if appl.model != "ThermoTouch": # model_id for Anna not present as stand-alone device
@@ -278,6 +275,7 @@ def _get_lock_state(self, xml: etree, data: DeviceData, stretch_v2: bool = False
278275
def _get_module_data(
279276
self,
280277
xml_1: etree,
278+
locator: str,
281279
xml_2: etree = None,
282280
legacy: bool = False,
283281
) -> ModelData:
@@ -294,12 +292,11 @@ def _get_module_data(
294292
"vendor_model": None,
295293
"zigbee_mac_address": None,
296294
}
297-
if (appl_search := xml_1.find("./logs/point_log/*[@id]")) is not None:
295+
296+
if (appl_search := xml_1.find(locator)) is not None:
298297
link_tag = appl_search.tag
299298
link_id = appl_search.attrib["id"]
300299
loc = f".//services/{link_tag}[@id='{link_id}']...."
301-
if legacy:
302-
loc = f".//{link_tag}[@id='{link_id}']...."
303300
# Not possible to walrus for some reason...
304301
# xml_2: self._modules for legacy, self._domain_objects for actual
305302
search = return_valid(xml_2, self._domain_objects)

plugwise/helper.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None:
356356
"""Collect P1 DSMR SmartMeter info."""
357357
loc_id = next(iter(self.loc_data.keys()))
358358
location = self._domain_objects.find(f'./location[@id="{loc_id}"]')
359-
module_data = self._get_module_data(location)
359+
locator = "./logs/point_log/*[@id]"
360+
module_data = self._get_module_data(location, locator)
360361
if not module_data["contents"]:
361362
LOGGER.error("No module data found for SmartMeter") # pragma: no cover
362363
return None # pragma: no cover
@@ -394,7 +395,8 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
394395
return appl
395396
case _ as s if s.endswith("_plug"):
396397
# Collect info from plug-types (Plug, Aqara Smart Plug)
397-
module_data = self._get_module_data(appliance)
398+
locator = "./logs/point_log/*[@id]"
399+
module_data = self._get_module_data(appliance, locator)
398400
# A plug without module-data is orphaned/ no present
399401
if not module_data["contents"]:
400402
return Munch()
@@ -712,14 +714,11 @@ def _wireless_availability(self, appliance: etree, data: DeviceData) -> None:
712714
Collect the availability-status for wireless connected devices.
713715
"""
714716
if self.smile(ADAM):
715-
# Try collecting for a Plug
716-
module_data = self._get_module_data(appliance)
717+
locator = "./logs/point_log/*[@id]"
718+
module_data = self._get_module_data(appliance, locator)
717719
if not module_data["contents"]:
718-
# Try collecting for a wireless thermostat
719-
module_data = self._get_module_data(appliance)
720-
if not module_data["contents"]:
721-
LOGGER.error("No module data found for Plug or wireless thermostat") # pragma: no cover
722-
return None # pragma: no cover
720+
LOGGER.error("No module data found for Plug or wireless thermostat") # pragma: no cover
721+
return None # pragma: no cover
723722

724723
if module_data["reachable"] is not None:
725724
data["available"] = module_data["reachable"]

plugwise/legacy/helper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
230230
"""
231231
if self.smile_type in ("power", "stretch"):
232232
locator = "./services/electricity_point_meter"
233-
mod_type = "electricity_point_meter"
234-
235-
module_data = self._get_module_data(appliance, self._modules, legacy=True)
233+
module_data = self._get_module_data(appliance, locator, self._modules, legacy=True)
236234
appl.zigbee_mac = module_data["zigbee_mac_address"]
237235
# Filter appliance without zigbee_mac, it's an orphaned device
238236
if appl.zigbee_mac is None and self.smile_type != "power":

0 commit comments

Comments
 (0)