Skip to content

Commit e9717e0

Browse files
committed
Simplify availability collection
1 parent 9fec5a8 commit e9717e0

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

plugwise/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None)
101101
appl.model_id = appl.model
102102
appl.model = check_model(appl.model, appl.vendor_name)
103103

104+
appl.available = module_data["reachable"]
104105
appl.hardware = module_data["hardware_version"]
105106
appl.firmware = module_data["firmware_version"]
106107
appl.zigbee_mac = module_data["zigbee_mac_address"]
@@ -190,6 +191,7 @@ def _create_gw_devices(self, appl: Munch) -> None:
190191
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
191192
self._count += 1
192193
for key, value in {
194+
"available": appl.available,
193195
"firmware": appl.firmware,
194196
"hardware": appl.hardware,
195197
"location": appl.location,

plugwise/helper.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def _all_appliances(self) -> None:
300300
if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None:
301301
continue
302302

303+
appl.available = None
303304
appl.dev_id = appliance.attrib["id"]
304305
appl.name = appliance.find("name").text
305306
appl.model = None
@@ -402,6 +403,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
402403
if not module_data["contents"]:
403404
return Munch()
404405

406+
appl.available = module_data["reachable"]
405407
appl.firmware = module_data["firmware_version"]
406408
appl.hardware = module_data["hardware_version"]
407409
appl.model_id = module_data["vendor_model"]
@@ -514,9 +516,6 @@ def _get_measurement_data(self, dev_id: str) -> DeviceData:
514516
if appliance.find("type").text in ACTUATOR_CLASSES:
515517
self._get_actuator_functionalities(appliance, device, data)
516518

517-
# Collect availability-status for wireless connected devices to Adam
518-
self._wireless_availability(appliance, data)
519-
520519
if dev_id == self.gateway_id and self.smile(ADAM):
521520
self._get_regulation_mode(appliance, data)
522521
self._get_gateway_mode(appliance, data)
@@ -709,22 +708,6 @@ def _get_actuator_functionalities(
709708
act_item = cast(ActuatorType, item)
710709
data[act_item] = temp_dict
711710

712-
def _wireless_availability(self, appliance: etree, data: DeviceData) -> None:
713-
"""Helper-function for _get_measurement_data().
714-
715-
Collect the availability-status for wireless connected devices.
716-
"""
717-
if self.smile(ADAM):
718-
locator = MODULE_LOCATOR
719-
module_data = self._get_module_data(appliance, locator)
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
723-
724-
if module_data["reachable"] is not None:
725-
data["available"] = module_data["reachable"]
726-
self._count += 1
727-
728711
def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None:
729712
"""Helper-function for _get_measurement_data().
730713

plugwise/legacy/helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def _all_appliances(self) -> None:
125125
appl.pwclass = "heater_central_plug"
126126

127127
appl.model = appl.pwclass.replace("_", " ").title()
128+
appl.available = None
128129
appl.model_id = None
129130
appl.firmware = None
130131
appl.hardware = None
@@ -251,6 +252,7 @@ def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
251252
def _p1_smartmeter_info_finder(self, appl: Munch) -> None:
252253
"""Collect P1 DSMR Smartmeter info."""
253254
loc_id = next(iter(self.loc_data.keys()))
255+
appl.available = None
254256
appl.dev_id = loc_id
255257
appl.location = loc_id
256258
appl.mac = None

0 commit comments

Comments
 (0)