Skip to content

Commit c7dbf96

Browse files
committed
Breakout _create_gw_devices() function
1 parent cb5a0ee commit c7dbf96

File tree

3 files changed

+26
-67
lines changed

3 files changed

+26
-67
lines changed

plugwise/common.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"""
55
from __future__ import annotations
66

7+
from typing import cast
8+
79
from plugwise.constants import (
810
ANNA,
911
SWITCH_GROUP_TYPES,
12+
ApplianceType,
1013
DeviceData,
1114
ModelData,
1215
SensorType,
@@ -239,3 +242,22 @@ def _power_data_energy_diff(
239242
direct_data["sensors"][net_string] = tmp_val
240243

241244
return direct_data
245+
246+
def _create_gw_devices(self, appl: Munch) -> None:
247+
"""Helper-function for creating/updating gw_devices."""
248+
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
249+
self._count += 1
250+
for key, value in {
251+
"firmware": appl.firmware,
252+
"hardware": appl.hardware,
253+
"location": appl.location,
254+
"mac_address": appl.mac,
255+
"model": appl.model,
256+
"name": appl.name,
257+
"zigbee_mac_address": appl.zigbee_mac,
258+
"vendor": appl.vendor_name,
259+
}.items():
260+
if value is not None or key == "location":
261+
appl_key = cast(ApplianceType, key)
262+
self.gw_devices[appl.dev_id][appl_key] = value
263+
self._count += 1

plugwise/helper.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
ActuatorData,
4242
ActuatorDataType,
4343
ActuatorType,
44-
ApplianceType,
4544
BinarySensorType,
4645
DeviceData,
4746
GatewayData,
@@ -294,22 +293,7 @@ def _all_appliances(self) -> None:
294293
if appl.pwclass in THERMOSTAT_CLASSES and appl.location is None:
295294
continue
296295

297-
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
298-
self._count += 1
299-
for key, value in {
300-
"firmware": appl.firmware,
301-
"hardware": appl.hardware,
302-
"location": appl.location,
303-
"mac_address": appl.mac,
304-
"model": appl.model,
305-
"name": appl.name,
306-
"zigbee_mac_address": appl.zigbee_mac,
307-
"vendor": appl.vendor_name,
308-
}.items():
309-
if value is not None or key == "location":
310-
appl_key = cast(ApplianceType, key)
311-
self.gw_devices[appl.dev_id][appl_key] = value
312-
self._count += 1
296+
self._create_gw_devices(appl)
313297

314298
# For P1 collect the connected SmartMeter info
315299
if self.smile_type == "power":
@@ -356,23 +340,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None:
356340
location = self._domain_objects.find(f'./location[@id="{loc_id}"]')
357341
appl = self._energy_device_info_finder(appl, location)
358342

359-
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
360-
self._count += 1
361-
362-
for key, value in {
363-
"firmware": appl.firmware,
364-
"hardware": appl.hardware,
365-
"location": appl.location,
366-
"mac_address": appl.mac,
367-
"model": appl.model,
368-
"name": appl.name,
369-
"zigbee_mac_address": appl.zigbee_mac,
370-
"vendor": appl.vendor_name,
371-
}.items():
372-
if value is not None or key == "location":
373-
p1_key = cast(ApplianceType, key)
374-
self.gw_devices[appl.dev_id][p1_key] = value
375-
self._count += 1
343+
self._create_gw_devices(appl)
376344

377345
def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
378346
"""Collect device info (Smile/Stretch, Thermostats, OpenTherm/On-Off): firmware, model and vendor name."""

plugwise/legacy/helper.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,7 @@ def _all_appliances(self) -> None:
137137
if appl.pwclass == "heater_central" and appl.dev_id != self._heater_id:
138138
continue # pragma: no cover
139139

140-
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
141-
self._count += 1
142-
for key, value in {
143-
"firmware": appl.firmware,
144-
"hardware": appl.hardware,
145-
"location": appl.location,
146-
"mac_address": appl.mac,
147-
"model": appl.model,
148-
"name": appl.name,
149-
"zigbee_mac_address": appl.zigbee_mac,
150-
"vendor": appl.vendor_name,
151-
}.items():
152-
if value is not None or key == "location":
153-
appl_key = cast(ApplianceType, key)
154-
self.gw_devices[appl.dev_id][appl_key] = value
155-
self._count += 1
140+
self._create_gw_devices(appl)
156141

157142
# Place the gateway and optional heater_central devices as 1st and 2nd
158143
for dev_class in ("heater_central", "gateway"):
@@ -272,23 +257,7 @@ def _p1_smartmeter_info_finder(self, appl: Munch) -> None:
272257
location = self._locations.find(f'./location[@id="{loc_id}"]')
273258
appl = self._energy_device_info_finder(location, appl)
274259

275-
self.gw_devices[appl.dev_id] = {"dev_class": appl.pwclass}
276-
self._count += 1
277-
278-
for key, value in {
279-
"firmware": appl.firmware,
280-
"hardware": appl.hardware,
281-
"location": appl.location,
282-
"mac_address": appl.mac,
283-
"model": appl.model,
284-
"name": appl.name,
285-
"zigbee_mac_address": appl.zigbee_mac,
286-
"vendor": appl.vendor_name,
287-
}.items():
288-
if value is not None or key == "location":
289-
p1_key = cast(ApplianceType, key)
290-
self.gw_devices[appl.dev_id][p1_key] = value
291-
self._count += 1
260+
self._create_gw_devices(appl)
292261

293262
def _get_measurement_data(self, dev_id: str) -> DeviceData:
294263
"""Helper-function for smile.py: _get_device_data().

0 commit comments

Comments
 (0)