Skip to content

Commit 8a1f930

Browse files
committed
Use default inputs for actual
1 parent 2f85701 commit 8a1f930

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

plugwise/common.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SmileCommon:
1717
def __init__(self) -> None:
1818
"""Init."""
1919
self._appliances: etree
20+
self._domain_objects: etree
2021
self._cooling_present: bool
2122
self._heater_id: str
2223
self._on_off_device: bool
@@ -27,11 +28,12 @@ def smile(self, name: str) -> bool:
2728
"""Helper-function checking the smile-name."""
2829
return self.smile_name == name
2930

30-
def _appl_thermostat_info(self, xml_1: etree, xml_2: etree, appl: Munch) -> Munch:
31+
def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None) -> Munch:
3132
"""Helper-function for _appliance_info_finder()."""
3233
locator = "./logs/point_log[type='thermostat']/thermostat"
3334
mod_type = "thermostat"
34-
module_data = self._get_module_data(xml_1, xml_2, locator, mod_type)
35+
xml_2 = xml_2 or self._domain_objects
36+
module_data = self._get_module_data(xml_1, locator, mod_type, xml_2)
3537
appl.vendor_name = module_data["vendor_name"]
3638
appl.model = check_model(module_data["vendor_model"], appl.vendor_name)
3739
appl.hardware = module_data["hardware_version"]
@@ -42,19 +44,19 @@ def _appl_thermostat_info(self, xml_1: etree, xml_2: etree, appl: Munch) -> Munc
4244

4345
def _appl_heater_central_info(
4446
self,
47+
appl: Munch,
4548
xml_1: etree,
46-
xml_2: etree,
47-
xml_3: etree,
48-
appl: Munch
49+
xml_2: etree = None,
50+
xml_3: etree = None,
4951
) -> Munch:
5052
"""Helper-function for _appliance_info_finder()."""
5153
# Remove heater_central when no active device present
5254
if not self._opentherm_device and not self._on_off_device:
5355
return None
5456

5557
# Find the valid heater_central
56-
# xml_1: self._appliances for legacy, self._domain_objects for actual
57-
self._heater_id = check_heater_central(xml_1)
58+
# xml_2 self._appliances for legacy, self._domain_objects for actual
59+
self._heater_id = check_heater_central(xml_2 or self._domain_objects)
5860

5961
# Info for On-Off device
6062
if self._on_off_device:
@@ -68,11 +70,12 @@ def _appl_heater_central_info(
6870
locator_1 = "./logs/point_log[type='flame_state']/boiler_state"
6971
locator_2 = "./services/boiler_state"
7072
mod_type = "boiler_state"
71-
# xml_2: appliance
73+
# xml_1: appliance
7274
# xml_3: self._modules for legacy, self._domain_objects for actual
73-
module_data = self._get_module_data(xml_2, xml_3, locator_1, mod_type)
75+
xml_3 = xml_3 or self._domain_objects
76+
module_data = self._get_module_data(xml_1, locator_1, mod_type, xml_3)
7477
if not module_data["contents"]:
75-
module_data = self._get_module_data(xml_2, xml_3, locator_2, mod_type)
78+
module_data = self._get_module_data(xml_1, locator_2, mod_type, xml_3)
7679
appl.vendor_name = module_data["vendor_name"]
7780
appl.hardware = module_data["hardware_version"]
7881
appl.model = module_data["vendor_model"]
@@ -86,7 +89,12 @@ def _appl_heater_central_info(
8689
return appl
8790

8891
def _get_module_data(
89-
self, xml_1: etree, xml_2: etree, locator: str, mod_type: str, legacy:bool=False,
92+
self,
93+
xml_1: etree,
94+
locator: str,
95+
mod_type: str,
96+
xml_2: etree = None,
97+
legacy: bool = False,
9098
) -> ModelData:
9199
"""Helper-function for _energy_device_info_finder() and _appliance_info_finder().
92100
@@ -109,7 +117,8 @@ def _get_module_data(
109117
loc = f".//{mod_type}[@id='{link_id}']...."
110118
# Not possible to walrus for some reason...
111119
# xml_2: self._modules for legacy, self._domain_objects for actual
112-
module = xml_2.find(loc)
120+
search = xml_2 or self._domain_objects
121+
module = search.find(loc)
113122
if module is not None: # pylint: disable=consider-using-assignment-expr
114123
model_data["contents"] = True
115124
get_vendor_name(module, model_data)

plugwise/helper.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
268268
if self.smile_type == "power":
269269
locator = "./logs/point_log/electricity_point_meter"
270270
mod_type = "electricity_point_meter"
271-
module_data = self._get_module_data(appliance, self._domain_objects, locator, mod_type)
271+
module_data = self._get_module_data(appliance, locator, mod_type)
272272
appl.hardware = module_data["hardware_version"]
273273
appl.model = module_data["vendor_model"]
274274
appl.vendor_name = module_data["vendor_name"]
@@ -279,7 +279,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
279279
if self.smile(ADAM):
280280
locator = "./logs/interval_log/electricity_interval_meter"
281281
mod_type = "electricity_interval_meter"
282-
module_data = self._get_module_data(appliance, self._domain_objects, locator, mod_type)
282+
module_data = self._get_module_data(appliance, locator, mod_type)
283283
# Filter appliance without zigbee_mac, it's an orphaned device
284284
appl.zigbee_mac = module_data["zigbee_mac_address"]
285285
if appl.zigbee_mac is None:
@@ -294,7 +294,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
294294

295295
return appl # pragma: no cover
296296

297-
def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
297+
def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
298298
"""Collect device info (Smile/Stretch, Thermostats, OpenTherm/On-Off): firmware, model and vendor name."""
299299
# Collect gateway device info
300300
if appl.pwclass == "gateway":
@@ -334,11 +334,11 @@ def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
334334

335335
# Collect thermostat device info
336336
if appl.pwclass in THERMOSTAT_CLASSES:
337-
return self._appl_thermostat_info(appliance, self._domain_objects, appl)
337+
return self._appl_thermostat_info(appl, appliance)
338338

339339
# Collect extra heater_central device info
340340
if appl.pwclass == "heater_central":
341-
appl = self._appl_heater_central_info(self._domain_objects, appliance, self._domain_objects, appl)
341+
appl = self._appl_heater_central_info(appl, appliance)
342342
# Anna + Loria: collect dhw control operation modes
343343
dhw_mode_list: list[str] = []
344344
locator = "./actuator_functionalities/domestic_hot_water_mode_control_functionality"
@@ -420,7 +420,7 @@ def _all_appliances(self) -> None:
420420

421421
# Determine class for this appliance
422422
# Skip on heater_central when no active device present
423-
if not (appl := self._appliance_info_finder(appliance, appl)):
423+
if not (appl := self._appliance_info_finder(appl, appliance)):
424424
continue
425425

426426
# Skip orphaned heater_central (Core Issue #104433)
@@ -634,12 +634,12 @@ def _wireless_availability(self, appliance: etree, data: DeviceData) -> None:
634634
# Collect for Plugs
635635
locator = "./logs/interval_log/electricity_interval_meter"
636636
mod_type = "electricity_interval_meter"
637-
module_data = self._get_module_data(appliance, self._domain_objects, locator, mod_type)
637+
module_data = self._get_module_data(appliance, locator, mod_type)
638638
if module_data["reachable"] is None:
639639
# Collect for wireless thermostats
640640
locator = "./logs/point_log[type='thermostat']/thermostat"
641641
mod_type = "thermostat"
642-
module_data = self._get_module_data(appliance, self._domain_objects, locator, mod_type)
642+
module_data = self._get_module_data(appliance, locator, mod_type)
643643

644644
if module_data["reachable"] is not None:
645645
data["available"] = module_data["reachable"]

plugwise/legacy/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
136136
locator = "./services/electricity_point_meter"
137137
mod_type = "electricity_point_meter"
138138

139-
module_data = self._get_module_data(appliance, self._modules, locator, mod_type, legacy=True)
139+
module_data = self._get_module_data(appliance, locator, mod_type, self._modules, legacy=True)
140140
appl.zigbee_mac = module_data["zigbee_mac_address"]
141141
# Filter appliance without zigbee_mac, it's an orphaned device
142142
if appl.zigbee_mac is None and self.smile_type != "power":
@@ -158,11 +158,11 @@ def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
158158
"""Collect device info (Smile/Stretch, Thermostats, OpenTherm/On-Off): firmware, model and vendor name."""
159159
# Collect thermostat device info
160160
if appl.pwclass in THERMOSTAT_CLASSES:
161-
return self._appl_thermostat_info(appliance, self._modules, appl)
161+
return self._appl_thermostat_info(appl, appliance, self._modules)
162162

163163
# Collect heater_central device info
164164
if appl.pwclass == "heater_central":
165-
return self._appl_heater_central_info(self._appliances, appliance, self._modules, appl)
165+
return self._appl_heater_central_info(appl, appliance, self._appliances, self._modules)
166166

167167
# Collect info from Stretches
168168
appl = self._energy_device_info_finder(appliance, appl)

0 commit comments

Comments
 (0)