Skip to content

Commit 27a109d

Browse files
authored
Merge pull request #500 from plugwise/gateway_away
Bugfixes for #558 and # 559
2 parents ecbcb4b + ef5500a commit 27a109d

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.36.3
4+
5+
- Bugfixes for [#558](https://github.com/plugwise/plugwise-beta/issues/558) and [#559](https://github.com/plugwise/plugwise-beta/issues/559).
6+
37
## v0.36.2
48

59
- Improve support for Anna+Elga systems that do not support cooling (fix for [#547](https://github.com/plugwise/plugwise-beta/issues/547)).

plugwise/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,20 +871,20 @@ async def set_gateway_mode(self, mode: str) -> None:
871871
if mode not in self._gw_allowed_modes:
872872
raise PlugwiseError("Plugwise: invalid gateway mode.")
873873

874-
time_1 = dt.datetime.now(dt.UTC)
875-
away_time = time_1.isoformat(timespec="milliseconds") + "Z"
876-
time_2 = str(dt.date.today() - dt.timedelta(1))
877-
vacation_time = time_2 + "T23:00:00.000Z"
878874
end_time = "2037-04-21T08:00:53.000Z"
879875
valid = ""
880876
if mode == "away":
877+
time_1 = self._domain_objects.find("./gateway/time").text
878+
away_time = dt.datetime.fromisoformat(time_1).astimezone(dt.UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
881879
valid = (
882880
f"<valid_from>{away_time}</valid_from><valid_to>{end_time}</valid_to>"
883881
)
884882
if mode == "vacation":
883+
time_2 = str(dt.date.today() - dt.timedelta(1))
884+
vacation_time = time_2 + "T23:00:00.000Z"
885885
valid = f"<valid_from>{vacation_time}</valid_from><valid_to>{end_time}</valid_to>"
886886

887-
uri = f"{APPLIANCES};type=gateway/gateway_mode_control"
887+
uri = f"{APPLIANCES};id={self.gateway_id}/gateway_mode_control"
888888
data = f"<gateway_mode_control_functionality><mode>{mode}</mode>{valid}</gateway_mode_control_functionality>"
889889

890890
await self._request(uri, method="put", data=data)

plugwise/helper.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ def _presets(self, loc_id: str) -> dict[str, list[float]]:
751751
return self._presets_legacy()
752752

753753
if not (rule_ids := self._rule_ids_by_tag(tag_1, loc_id)):
754+
rule_ids = None
754755
if not (rule_ids := self._rule_ids_by_name(tag_2, loc_id)):
755756
return presets # pragma: no cover
756757

@@ -767,35 +768,38 @@ def _presets(self, loc_id: str) -> dict[str, list[float]]:
767768

768769
return presets
769770

770-
def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, str]:
771+
def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, dict[str, str]]:
771772
"""Helper-function for _presets().
772773
773774
Obtain the rule_id from the given name and and provide the location_id, when present.
774775
"""
775-
schedule_ids: dict[str, str] = {}
776+
schedule_ids: dict[str, dict[str, str]] = {}
776777
locator = f'./contexts/context/zone/location[@id="{loc_id}"]'
777778
for rule in self._domain_objects.findall(f'./rule[name="{name}"]'):
779+
active = rule.find("active").text
778780
if rule.find(locator) is not None:
779-
schedule_ids[rule.attrib["id"]] = loc_id
781+
schedule_ids[rule.attrib["id"]] = {"location": loc_id, "name": name, "active": active}
780782
else:
781-
schedule_ids[rule.attrib["id"]] = NONE
783+
schedule_ids[rule.attrib["id"]] = {"location": NONE, "name": name, "active": active}
782784

783785
return schedule_ids
784786

785-
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, str]:
787+
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, dict[str, str]]:
786788
"""Helper-function for _presets(), _schedules() and _last_active_schedule().
787789
788790
Obtain the rule_id from the given template_tag and provide the location_id, when present.
789791
"""
790-
schedule_ids: dict[str, str] = {}
792+
schedule_ids: dict[str, dict[str, str]] = {}
791793
locator1 = f'./template[@tag="{tag}"]'
792794
locator2 = f'./contexts/context/zone/location[@id="{loc_id}"]'
793795
for rule in self._domain_objects.findall("./rule"):
794796
if rule.find(locator1) is not None:
797+
name = rule.find("name").text
798+
active = rule.find("active").text
795799
if rule.find(locator2) is not None:
796-
schedule_ids[rule.attrib["id"]] = loc_id
800+
schedule_ids[rule.attrib["id"]] = {"location": loc_id, "name": name, "active": active}
797801
else:
798-
schedule_ids[rule.attrib["id"]] = NONE
802+
schedule_ids[rule.attrib["id"]] = {"location": NONE, "name": name, "active": active}
799803

800804
return schedule_ids
801805

@@ -1478,7 +1482,7 @@ def _schedules(self, location: str) -> tuple[list[str], str]:
14781482
NEW: when a location_id is present then the schedule is active. Valid for both Adam and non-legacy Anna.
14791483
"""
14801484
available: list[str] = [NONE]
1481-
rule_ids: dict[str, str] = {}
1485+
rule_ids: dict[str, dict[str, str]] = {}
14821486
selected = NONE
14831487

14841488
# Legacy Anna schedule, only one schedule allowed
@@ -1495,15 +1499,16 @@ def _schedules(self, location: str) -> tuple[list[str], str]:
14951499
return available, selected
14961500

14971501
schedules: list[str] = []
1498-
for rule_id, loc_id in rule_ids.items():
1499-
name = self._domain_objects.find(f'./rule[@id="{rule_id}"]/name').text
1502+
for rule_id, data in rule_ids.items():
1503+
active = data["active"] == "true"
1504+
name = data["name"]
15001505
locator = f'./rule[@id="{rule_id}"]/directives'
15011506
# Show an empty schedule as no schedule found
15021507
if self._domain_objects.find(locator) is None:
15031508
continue # pragma: no cover
15041509

15051510
available.append(name)
1506-
if location == loc_id:
1511+
if location == data["location"] and active:
15071512
selected = name
15081513
self._last_active[location] = selected
15091514
schedules.append(name)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "0.36.2"
7+
version = "0.36.3"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)