Skip to content

Commit cb5a0ee

Browse files
authored
Merge pull request #518 from plugwise/improve-5
Continued improving
2 parents 0be4fad + 67f4f5c commit cb5a0ee

File tree

17 files changed

+1047
-1074
lines changed

17 files changed

+1047
-1074
lines changed

fixtures/legacy_anna/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00",
6666
"heater_id": "04e4cbfe7f4340f090f85ec3b9e6a950",
6767
"item_count": 43,
68-
"notifications": {},
6968
"smile_name": "Smile Anna"
7069
}
7170
}

fixtures/legacy_anna_2/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"gateway_id": "be81e3f8275b4129852c4d8d550ae2eb",
6868
"heater_id": "ea5d8a7177e541b0a4b52da815166de4",
6969
"item_count": 43,
70-
"notifications": {},
7170
"smile_name": "Smile Anna"
7271
}
7372
}

fixtures/smile_p1_v2/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"gateway": {
3737
"gateway_id": "aaaa0000aaaa0000aaaa0000aaaa00aa",
3838
"item_count": 26,
39-
"notifications": {},
4039
"smile_name": "Smile P1"
4140
}
4241
}

fixtures/smile_p1_v2_2/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"gateway": {
3737
"gateway_id": "aaaa0000aaaa0000aaaa0000aaaa00aa",
3838
"item_count": 26,
39-
"notifications": {},
4039
"smile_name": "Smile P1"
4140
}
4241
}

fixtures/stretch_v23/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
"gateway": {
336336
"gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00",
337337
"item_count": 229,
338-
"notifications": {},
339338
"smile_name": "Stretch"
340339
}
341340
}

fixtures/stretch_v27_no_domain/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@
274274
"gateway": {
275275
"gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00",
276276
"item_count": 190,
277-
"notifications": {},
278277
"smile_name": "Stretch"
279278
}
280279
}

fixtures/stretch_v31/all_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
"gateway": {
137137
"gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00",
138138
"item_count": 83,
139-
"notifications": {},
140139
"smile_name": "Stretch"
141140
}
142141
}

plugwise/common.py

Lines changed: 66 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,6 @@ def smile(self, name: str) -> bool:
4242
"""Helper-function checking the smile-name."""
4343
return self.smile_name == name
4444

45-
def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None) -> Munch:
46-
"""Helper-function for _appliance_info_finder()."""
47-
locator = "./logs/point_log[type='thermostat']/thermostat"
48-
mod_type = "thermostat"
49-
xml_2 = return_valid(xml_2, self._domain_objects)
50-
module_data = self._get_module_data(xml_1, locator, mod_type, xml_2)
51-
appl.vendor_name = module_data["vendor_name"]
52-
appl.model = check_model(module_data["vendor_model"], appl.vendor_name)
53-
appl.hardware = module_data["hardware_version"]
54-
appl.firmware = module_data["firmware_version"]
55-
appl.zigbee_mac = module_data["zigbee_mac_address"]
56-
57-
return appl
58-
5945
def _appl_heater_central_info(
6046
self,
6147
appl: Munch,
@@ -103,6 +89,71 @@ def _appl_heater_central_info(
10389

10490
return appl
10591

92+
def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None) -> Munch:
93+
"""Helper-function for _appliance_info_finder()."""
94+
locator = "./logs/point_log[type='thermostat']/thermostat"
95+
mod_type = "thermostat"
96+
xml_2 = return_valid(xml_2, self._domain_objects)
97+
module_data = self._get_module_data(xml_1, locator, mod_type, xml_2)
98+
appl.vendor_name = module_data["vendor_name"]
99+
appl.model = check_model(module_data["vendor_model"], appl.vendor_name)
100+
appl.hardware = module_data["hardware_version"]
101+
appl.firmware = module_data["firmware_version"]
102+
appl.zigbee_mac = module_data["zigbee_mac_address"]
103+
104+
return appl
105+
106+
def _device_data_switching_group(
107+
self, device: DeviceData, data: DeviceData
108+
) -> None:
109+
"""Helper-function for _get_device_data().
110+
111+
Determine switching group device data.
112+
"""
113+
if device["dev_class"] in SWITCH_GROUP_TYPES:
114+
counter = 0
115+
for member in device["members"]:
116+
if self.gw_devices[member]["switches"].get("relay"):
117+
counter += 1
118+
data["switches"]["relay"] = counter != 0
119+
self._count += 1
120+
121+
def _get_group_switches(self) -> dict[str, DeviceData]:
122+
"""Helper-function for smile.py: get_all_devices().
123+
124+
Collect switching- or pump-group info.
125+
"""
126+
switch_groups: dict[str, DeviceData] = {}
127+
# P1 and Anna don't have switchgroups
128+
if self.smile_type == "power" or self.smile(ANNA):
129+
return switch_groups
130+
131+
for group in self._domain_objects.findall("./group"):
132+
members: list[str] = []
133+
group_id = group.attrib["id"]
134+
group_name = group.find("name").text
135+
group_type = group.find("type").text
136+
group_appliances = group.findall("appliances/appliance")
137+
for item in group_appliances:
138+
# Check if members are not orphaned - stretch
139+
if item.attrib["id"] in self.gw_devices:
140+
members.append(item.attrib["id"])
141+
142+
if group_type in SWITCH_GROUP_TYPES and members:
143+
switch_groups.update(
144+
{
145+
group_id: {
146+
"dev_class": group_type,
147+
"model": "Switchgroup",
148+
"name": group_name,
149+
"members": members,
150+
},
151+
},
152+
)
153+
self._count += 4
154+
155+
return switch_groups
156+
106157
def _get_module_data(
107158
self,
108159
xml_1: etree,
@@ -158,43 +209,7 @@ def _get_zigbee_data(self, module: etree, model_data: ModelData, legacy: bool) -
158209
model_data["zigbee_mac_address"] = zb_node.find("mac_address").text
159210
model_data["reachable"] = zb_node.find("reachable").text == "true"
160211

161-
def _get_group_switches(self) -> dict[str, DeviceData]:
162-
"""Helper-function for smile.py: get_all_devices().
163-
164-
Collect switching- or pump-group info.
165-
"""
166-
switch_groups: dict[str, DeviceData] = {}
167-
# P1 and Anna don't have switchgroups
168-
if self.smile_type == "power" or self.smile(ANNA):
169-
return switch_groups
170-
171-
for group in self._domain_objects.findall("./group"):
172-
members: list[str] = []
173-
group_id = group.attrib["id"]
174-
group_name = group.find("name").text
175-
group_type = group.find("type").text
176-
group_appliances = group.findall("appliances/appliance")
177-
for item in group_appliances:
178-
# Check if members are not orphaned - stretch
179-
if item.attrib["id"] in self.gw_devices:
180-
members.append(item.attrib["id"])
181-
182-
if group_type in SWITCH_GROUP_TYPES and members:
183-
switch_groups.update(
184-
{
185-
group_id: {
186-
"dev_class": group_type,
187-
"model": "Switchgroup",
188-
"name": group_name,
189-
"members": members,
190-
},
191-
},
192-
)
193-
self._count += 4
194-
195-
return switch_groups
196-
197-
def power_data_energy_diff(
212+
def _power_data_energy_diff(
198213
self,
199214
measurement: str,
200215
net_string: SensorType,

plugwise/data.py

Lines changed: 55 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
MIN_SETPOINT,
1212
NONE,
1313
OFF,
14-
SWITCH_GROUP_TYPES,
1514
ZONE_THERMOSTATS,
1615
ActuatorData,
1716
DeviceData,
@@ -28,6 +27,25 @@ def __init__(self) -> None:
2827
SmileHelper.__init__(self)
2928

3029

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+
3149
def _update_gw_devices(self) -> None:
3250
"""Helper-function for _all_device_data() and async_update().
3351
@@ -84,39 +102,52 @@ def _update_for_cooling(self, device: DeviceData) -> None:
84102
sensors["setpoint_high"] = temp_dict["setpoint_high"]
85103
self._count += 2
86104

87-
def _all_device_data(self) -> None:
88-
"""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().
89107
90-
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.
91109
"""
92-
self._update_gw_devices()
93-
self.gw_data.update(
94-
{
95-
"gateway_id": self.gateway_id,
96-
"item_count": self._count,
97-
"notifications": self._notifications,
98-
"smile_name": self.smile_name,
99-
}
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"
100117
)
101-
if self._is_thermostat:
102-
self.gw_data.update(
103-
{"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"
104122
)
105123

106-
def _device_data_switching_group(
107-
self, device: DeviceData, data: DeviceData
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
108139
) -> None:
109140
"""Helper-function for _get_device_data().
110141
111-
Determine switching group device data.
142+
Provide availability status for the wired-commected devices.
112143
"""
113-
if device["dev_class"] in SWITCH_GROUP_TYPES:
114-
counter = 0
115-
for member in device["members"]:
116-
if self.gw_devices[member]["switches"].get("relay"):
117-
counter += 1
118-
data["switches"]["relay"] = counter != 0
144+
if device["dev_class"] == dev_class:
145+
data["available"] = True
119146
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
120151

121152
def _device_data_adam(self, device: DeviceData, data: DeviceData) -> None:
122153
"""Helper-function for _get_device_data().
@@ -213,50 +244,3 @@ def _get_schedule_states_with_off(
213244
all_off = False
214245
if all_off:
215246
data["select_schedule"] = OFF
216-
217-
def _check_availability(
218-
self, device: DeviceData, dev_class: str, data: DeviceData, message: str
219-
) -> None:
220-
"""Helper-function for _get_device_data().
221-
222-
Provide availability status for the wired-commected devices.
223-
"""
224-
if device["dev_class"] == dev_class:
225-
data["available"] = True
226-
self._count += 1
227-
for item in self._notifications.values():
228-
for msg in item.values():
229-
if message in msg:
230-
data["available"] = False
231-
232-
def _get_device_data(self, dev_id: str) -> DeviceData:
233-
"""Helper-function for _all_device_data() and async_update().
234-
235-
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
236-
"""
237-
device = self.gw_devices[dev_id]
238-
data = self._get_measurement_data(dev_id)
239-
240-
# Check availability of wired-connected devices
241-
# Smartmeter
242-
self._check_availability(
243-
device, "smartmeter", data, "P1 does not seem to be connected"
244-
)
245-
# OpenTherm device
246-
if device["name"] != "OnOff":
247-
self._check_availability(
248-
device, "heater_central", data, "no OpenTherm communication"
249-
)
250-
251-
# Switching groups data
252-
self._device_data_switching_group(device, data)
253-
# Adam data
254-
self._device_data_adam(device, data)
255-
# Skip obtaining data for non master-thermostats
256-
if device["dev_class"] not in ZONE_THERMOSTATS:
257-
return data
258-
259-
# Thermostat data (presets, temperatures etc)
260-
self._device_data_climate(device, data)
261-
262-
return data

0 commit comments

Comments
 (0)