Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Ongoing

- Improve readability of xml-data in POST/PUT requests
- 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)
- Continuous improvements [#711](https://github.com/plugwise/python-plugwise/pull/711)

## v1.7.2

Expand Down
3 changes: 2 additions & 1 deletion plugwise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@ async def _smile_detect_legacy(
self.smile_version = parse(system.find("./gateway/firmware").text)
return_model = str(system.find("./gateway/product").text)
self.smile_hostname = system.find("./gateway/hostname").text
# If wlan0 contains data it's active, so eth0 should be checked last
# If wlan0 contains data it's active, eth0 should be checked last as is preferred
for network in ("wlan0", "eth0"):
locator = f"./{network}/mac"
if (net_locator := system.find(locator)) is not None:
self.smile_mac_address = net_locator.text

# P1 legacy:
elif dsmrmain is not None:
status = await self._request(STATUS)
Expand Down
17 changes: 8 additions & 9 deletions plugwise/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def _check_availability(
for msg in item.values():
if message in msg:
data["available"] = False
break

def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None:
"""Helper-function for _get_entity_data().
Expand Down Expand Up @@ -329,16 +330,14 @@ def _get_schedule_states_with_off(

Also, replace NONE by OFF when none of the schedules are active.
"""
loc_schedule_states: dict[str, str] = {}
for schedule in schedules:
loc_schedule_states[schedule] = "off"
if schedule == selected and data["climate_mode"] == "auto":
loc_schedule_states[schedule] = "on"
self._schedule_old_states[location] = loc_schedule_states

all_off = True
for state in self._schedule_old_states[location].values():
if state == "on":
self._schedule_old_states[location] = {}
for schedule in schedules:
active: bool = schedule == selected and data["climate_mode"] == "auto"
self._schedule_old_states[location][schedule] = "off"
if active:
self._schedule_old_states[location][schedule] = "on"
all_off = False

if all_off:
data["select_schedule"] = OFF
1 change: 1 addition & 0 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def _sort_gw_entities(self) -> None:
other_entities = self.gw_entities
priority_entities = {entity_id: priority_entity}
self.gw_entities = {**priority_entities, **other_entities}
break

def _all_locations(self) -> None:
"""Collect all locations."""
Expand Down
4 changes: 3 additions & 1 deletion plugwise/legacy/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NONE,
OFF,
P1_LEGACY_MEASUREMENTS,
PRIORITY_DEVICE_CLASSES,
TEMP_CELSIUS,
THERMOSTAT_CLASSES,
UOM,
Expand Down Expand Up @@ -130,14 +131,15 @@ def _all_appliances(self) -> None:
self._create_gw_entities(appl)

# Place the gateway and optional heater_central devices as 1st and 2nd
for dev_class in ("heater_central", "gateway"):
for dev_class in PRIORITY_DEVICE_CLASSES:
for entity_id, entity in dict(self.gw_entities).items():
if entity["dev_class"] == dev_class:
tmp_entity = entity
self.gw_entities.pop(entity_id)
cleared_dict = self.gw_entities
add_to_front = {entity_id: tmp_entity}
self.gw_entities = {**add_to_front, **cleared_dict}
break

def _all_locations(self) -> None:
"""Collect all locations."""
Expand Down
4 changes: 2 additions & 2 deletions plugwise/legacy/smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ async def set_schedule_state(
for rule in self._domain_objects.findall("rule"):
if rule.find("name").text == name:
schedule_rule_id = rule.attrib["id"]
break

if schedule_rule_id is None:
raise PlugwiseError(
Expand All @@ -215,8 +216,7 @@ async def set_schedule_state(
new_state = "true"

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

data = (
"<rules>"
Expand Down
7 changes: 4 additions & 3 deletions plugwise/smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,15 @@ async def set_switch_state(
return await self._set_groupswitch_member_state(members, state, switch)

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

data = (
f"<{switch.func_type}>"
Expand Down
Loading