Skip to content

Commit 4b5c84c

Browse files
authored
Merge pull request #711 from plugwise/improve-01
Continuous improvement
2 parents 1a6d924 + c633ef5 commit 4b5c84c

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Ongoing
44

5-
- Improve readability of xml-data in POST/PUT requests
5+
- Improve readability of xml-data in POST/PUT requests via [#707](https://github.com/plugwise/python-plugwise/pull/707) and [#708](https://github.com/plugwise/python-plugwise/pull/708)
6+
- Continuous improvements [#711](https://github.com/plugwise/python-plugwise/pull/711)
67

78
## v1.7.2
89

plugwise/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,12 @@ async def _smile_detect_legacy(
298298
self.smile_version = parse(system.find("./gateway/firmware").text)
299299
return_model = str(system.find("./gateway/product").text)
300300
self.smile_hostname = system.find("./gateway/hostname").text
301-
# If wlan0 contains data it's active, so eth0 should be checked last
301+
# If wlan0 contains data it's active, eth0 should be checked last as is preferred
302302
for network in ("wlan0", "eth0"):
303303
locator = f"./{network}/mac"
304304
if (net_locator := system.find(locator)) is not None:
305305
self.smile_mac_address = net_locator.text
306+
306307
# P1 legacy:
307308
elif dsmrmain is not None:
308309
status = await self._request(STATUS)

plugwise/data.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def _check_availability(
228228
for msg in item.values():
229229
if message in msg:
230230
data["available"] = False
231+
break
231232

232233
def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None:
233234
"""Helper-function for _get_entity_data().
@@ -329,16 +330,14 @@ def _get_schedule_states_with_off(
329330
330331
Also, replace NONE by OFF when none of the schedules are active.
331332
"""
332-
loc_schedule_states: dict[str, str] = {}
333-
for schedule in schedules:
334-
loc_schedule_states[schedule] = "off"
335-
if schedule == selected and data["climate_mode"] == "auto":
336-
loc_schedule_states[schedule] = "on"
337-
self._schedule_old_states[location] = loc_schedule_states
338-
339333
all_off = True
340-
for state in self._schedule_old_states[location].values():
341-
if state == "on":
334+
self._schedule_old_states[location] = {}
335+
for schedule in schedules:
336+
active: bool = schedule == selected and data["climate_mode"] == "auto"
337+
self._schedule_old_states[location][schedule] = "off"
338+
if active:
339+
self._schedule_old_states[location][schedule] = "on"
342340
all_off = False
341+
343342
if all_off:
344343
data["select_schedule"] = OFF

plugwise/helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def _sort_gw_entities(self) -> None:
195195
other_entities = self.gw_entities
196196
priority_entities = {entity_id: priority_entity}
197197
self.gw_entities = {**priority_entities, **other_entities}
198+
break
198199

199200
def _all_locations(self) -> None:
200201
"""Collect all locations."""

plugwise/legacy/helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
NONE,
2424
OFF,
2525
P1_LEGACY_MEASUREMENTS,
26+
PRIORITY_DEVICE_CLASSES,
2627
TEMP_CELSIUS,
2728
THERMOSTAT_CLASSES,
2829
UOM,
@@ -130,14 +131,15 @@ def _all_appliances(self) -> None:
130131
self._create_gw_entities(appl)
131132

132133
# Place the gateway and optional heater_central devices as 1st and 2nd
133-
for dev_class in ("heater_central", "gateway"):
134+
for dev_class in PRIORITY_DEVICE_CLASSES:
134135
for entity_id, entity in dict(self.gw_entities).items():
135136
if entity["dev_class"] == dev_class:
136137
tmp_entity = entity
137138
self.gw_entities.pop(entity_id)
138139
cleared_dict = self.gw_entities
139140
add_to_front = {entity_id: tmp_entity}
140141
self.gw_entities = {**add_to_front, **cleared_dict}
142+
break
141143

142144
def _all_locations(self) -> None:
143145
"""Collect all locations."""

plugwise/legacy/smile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ async def set_schedule_state(
204204
for rule in self._domain_objects.findall("rule"):
205205
if rule.find("name").text == name:
206206
schedule_rule_id = rule.attrib["id"]
207+
break
207208

208209
if schedule_rule_id is None:
209210
raise PlugwiseError(
@@ -215,8 +216,7 @@ async def set_schedule_state(
215216
new_state = "true"
216217

217218
locator = f'.//*[@id="{schedule_rule_id}"]/template'
218-
for rule in self._domain_objects.findall(locator):
219-
template_id = rule.attrib["id"]
219+
template_id = self._domain_objects.find(locator).attrib["id"]
220220

221221
data = (
222222
"<rules>"

plugwise/smile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,15 @@ async def set_switch_state(
399399
return await self._set_groupswitch_member_state(members, state, switch)
400400

401401
locator = f'appliance[@id="{appl_id}"]/{switch.actuator}/{switch.func_type}'
402-
found: list[etree] = self._domain_objects.findall(locator)
402+
found = self._domain_objects.findall(locator)
403403
for item in found:
404+
# multiple types of e.g. toggle_functionality present
404405
if (sw_type := item.find("type")) is not None:
405406
if sw_type.text == switch.act_type:
406407
switch_id = item.attrib["id"]
407-
else:
408+
break
409+
else: # actuators with a single item like relay_functionality
408410
switch_id = item.attrib["id"]
409-
break
410411

411412
data = (
412413
f"<{switch.func_type}>"

0 commit comments

Comments
 (0)