Skip to content

Commit 8a4b2b4

Browse files
committed
Data: re-order functions
1 parent 3b6269d commit 8a4b2b4

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

plugwise/data.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ def __init__(self) -> None:
2727
SmileHelper.__init__(self)
2828

2929

30+
def _all_device_data(self) -> None:
31+
"""Helper-function for get_all_devices().
32+
33+
Collect data for each device and add to self.gw_data and self.gw_devices.
34+
"""
35+
self._update_gw_devices()
36+
self.gw_data.update(
37+
{
38+
"gateway_id": self.gateway_id,
39+
"item_count": self._count,
40+
"notifications": self._notifications,
41+
"smile_name": self.smile_name,
42+
}
43+
)
44+
if self._is_thermostat:
45+
self.gw_data.update(
46+
{"heater_id": self._heater_id, "cooling_present": self._cooling_present}
47+
)
48+
3049
def _update_gw_devices(self) -> None:
3150
"""Helper-function for _all_device_data() and async_update().
3251
@@ -83,25 +102,53 @@ def _update_for_cooling(self, device: DeviceData) -> None:
83102
sensors["setpoint_high"] = temp_dict["setpoint_high"]
84103
self._count += 2
85104

86-
def _all_device_data(self) -> None:
87-
"""Helper-function for get_all_devices().
105+
def _get_device_data(self, dev_id: str) -> DeviceData:
106+
"""Helper-function for _all_device_data() and async_update().
88107
89-
Collect data for each device and add to self.gw_data and self.gw_devices.
108+
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
90109
"""
91-
self._update_gw_devices()
92-
self.gw_data.update(
93-
{
94-
"gateway_id": self.gateway_id,
95-
"item_count": self._count,
96-
"notifications": self._notifications,
97-
"smile_name": self.smile_name,
98-
}
110+
device = self.gw_devices[dev_id]
111+
data = self._get_measurement_data(dev_id)
112+
113+
# Check availability of wired-connected devices
114+
# Smartmeter
115+
self._check_availability(
116+
device, "smartmeter", data, "P1 does not seem to be connected"
99117
)
100-
if self._is_thermostat:
101-
self.gw_data.update(
102-
{"heater_id": self._heater_id, "cooling_present": self._cooling_present}
118+
# OpenTherm device
119+
if device["name"] != "OnOff":
120+
self._check_availability(
121+
device, "heater_central", data, "no OpenTherm communication"
103122
)
104123

124+
# Switching groups data
125+
self._device_data_switching_group(device, data)
126+
# Adam data
127+
self._device_data_adam(device, data)
128+
# Skip obtaining data for non master-thermostats
129+
if device["dev_class"] not in ZONE_THERMOSTATS:
130+
return data
131+
132+
# Thermostat data (presets, temperatures etc)
133+
self._device_data_climate(device, data)
134+
135+
return data
136+
137+
def _check_availability(
138+
self, device: DeviceData, dev_class: str, data: DeviceData, message: str
139+
) -> None:
140+
"""Helper-function for _get_device_data().
141+
142+
Provide availability status for the wired-commected devices.
143+
"""
144+
if device["dev_class"] == dev_class:
145+
data["available"] = True
146+
self._count += 1
147+
for item in self._notifications.values():
148+
for msg in item.values():
149+
if message in msg:
150+
data["available"] = False
151+
105152
def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
106153
"""Helper-function for _get_device_data().
107154
@@ -197,50 +244,3 @@ def _get_schedule_states_with_off(
197244
all_off = False
198245
if all_off:
199246
data["select_schedule"] = OFF
200-
201-
def _check_availability(
202-
self, device: DeviceData, dev_class: str, data: DeviceData, message: str
203-
) -> None:
204-
"""Helper-function for _get_device_data().
205-
206-
Provide availability status for the wired-commected devices.
207-
"""
208-
if device["dev_class"] == dev_class:
209-
data["available"] = True
210-
self._count += 1
211-
for item in self._notifications.values():
212-
for msg in item.values():
213-
if message in msg:
214-
data["available"] = False
215-
216-
def _get_device_data(self, dev_id: str) -> DeviceData:
217-
"""Helper-function for _all_device_data() and async_update().
218-
219-
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
220-
"""
221-
device = self.gw_devices[dev_id]
222-
data = self._get_measurement_data(dev_id)
223-
224-
# Check availability of wired-connected devices
225-
# Smartmeter
226-
self._check_availability(
227-
device, "smartmeter", data, "P1 does not seem to be connected"
228-
)
229-
# OpenTherm device
230-
if device["name"] != "OnOff":
231-
self._check_availability(
232-
device, "heater_central", data, "no OpenTherm communication"
233-
)
234-
235-
# Switching groups data
236-
self._device_data_switching_group(device, data)
237-
# Adam data
238-
self._device_data_adam(device, data)
239-
# Skip obtaining data for non master-thermostats
240-
if device["dev_class"] not in ZONE_THERMOSTATS:
241-
return data
242-
243-
# Thermostat data (presets, temperatures etc)
244-
self._device_data_climate(device, data)
245-
246-
return data

plugwise/legacy/data.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ def __init__(self) -> None:
1818
"""Init."""
1919
SmileLegacyHelper.__init__(self)
2020

21-
def _update_gw_devices(self) -> None:
22-
"""Helper-function for _all_device_data() and async_update().
23-
24-
Collect data for each device and add to self.gw_devices.
25-
"""
26-
for device_id, device in self.gw_devices.items():
27-
data = self._get_device_data(device_id)
28-
device.update(data)
29-
remove_empty_platform_dicts(device)
30-
3121
def _all_device_data(self) -> None:
3222
"""Helper-function for get_all_devices().
3323
@@ -46,6 +36,36 @@ def _all_device_data(self) -> None:
4636
{"heater_id": self._heater_id, "cooling_present": False}
4737
)
4838

39+
def _update_gw_devices(self) -> None:
40+
"""Helper-function for _all_device_data() and async_update().
41+
42+
Collect data for each device and add to self.gw_devices.
43+
"""
44+
for device_id, device in self.gw_devices.items():
45+
data = self._get_device_data(device_id)
46+
device.update(data)
47+
remove_empty_platform_dicts(device)
48+
49+
def _get_device_data(self, dev_id: str) -> DeviceData:
50+
"""Helper-function for _all_device_data() and async_update().
51+
52+
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
53+
"""
54+
device = self.gw_devices[dev_id]
55+
data = self._get_measurement_data(dev_id)
56+
57+
# Switching groups data
58+
self._device_data_switching_group(device, data)
59+
60+
# Skip obtaining data for non master-thermostats
61+
if device["dev_class"] not in ZONE_THERMOSTATS:
62+
return data
63+
64+
# Thermostat data (presets, temperatures etc)
65+
self._device_data_climate(device, data)
66+
67+
return data
68+
4969
def _device_data_climate(self, device: DeviceData, data: DeviceData) -> None:
5070
"""Helper-function for _get_device_data().
5171
@@ -70,23 +90,3 @@ def _device_data_climate(self, device: DeviceData, data: DeviceData) -> None:
7090
self._count += 1
7191
if sel_schedule == NONE:
7292
data["mode"] = "heat"
73-
74-
def _get_device_data(self, dev_id: str) -> DeviceData:
75-
"""Helper-function for _all_device_data() and async_update().
76-
77-
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
78-
"""
79-
device = self.gw_devices[dev_id]
80-
data = self._get_measurement_data(dev_id)
81-
82-
# Switching groups data
83-
self._device_data_switching_group(device, data)
84-
85-
# Skip obtaining data for non master-thermostats
86-
if device["dev_class"] not in ZONE_THERMOSTATS:
87-
return data
88-
89-
# Thermostat data (presets, temperatures etc)
90-
self._device_data_climate(device, data)
91-
92-
return data

0 commit comments

Comments
 (0)