Skip to content

Commit eace9b3

Browse files
committed
Extend output of _rule_ids_by_tag()
1 parent 23f6dd6 commit eace9b3

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

plugwise/helper.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def _presets(self, loc_id: str) -> dict[str, list[float]]:
767767

768768
return presets
769769

770-
def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, str]:
770+
def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, dict[str, str]]:
771771
"""Helper-function for _presets().
772772
773773
Obtain the rule_id from the given name and and provide the location_id, when present.
@@ -782,20 +782,22 @@ def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, str]:
782782

783783
return schedule_ids
784784

785-
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, str]:
785+
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, dict[str, str]]:
786786
"""Helper-function for _presets(), _schedules() and _last_active_schedule().
787787
788788
Obtain the rule_id from the given template_tag and provide the location_id, when present.
789789
"""
790-
schedule_ids: dict[str, str] = {}
790+
schedule_ids: dict[str, dict[str, str]] = {}
791791
locator1 = f'./template[@tag="{tag}"]'
792792
locator2 = f'./contexts/context/zone/location[@id="{loc_id}"]'
793793
for rule in self._domain_objects.findall("./rule"):
794794
if rule.find(locator1) is not None:
795+
name = rule.find("name").text
796+
active = rule.find("active").text == "true"
795797
if rule.find(locator2) is not None:
796-
schedule_ids[rule.attrib["id"]] = loc_id
798+
schedule_ids[rule.attrib["id"]] = {"location": loc_id, "name": name, "active": active}
797799
else:
798-
schedule_ids[rule.attrib["id"]] = NONE
800+
schedule_ids[rule.attrib["id"]] = {"location": NONE, "name": name, "active": active}
799801

800802
return schedule_ids
801803

@@ -1495,22 +1497,16 @@ def _schedules(self, location: str) -> tuple[list[str], str]:
14951497
return available, selected
14961498

14971499
schedules: list[str] = []
1498-
for rule_id, loc_id in rule_ids.items():
1499-
active = False
1500-
name = self._domain_objects.find(f'rule[@id="{rule_id}"]/name').text
1501-
if (
1502-
self._domain_objects.find(f'rule[@id="{rule_id}"]/active').text
1503-
== "true"
1504-
):
1505-
active = True
1506-
1500+
for rule_id, data in rule_ids.items():
1501+
active = data["active"]
1502+
name = data["name"]
15071503
locator = f'./rule[@id="{rule_id}"]/directives'
15081504
# Show an empty schedule as no schedule found
15091505
if self._domain_objects.find(locator) is None:
15101506
continue # pragma: no cover
15111507

15121508
available.append(name)
1513-
if location == loc_id and active:
1509+
if location == data["location"] and active:
15141510
selected = name
15151511
self._last_active[location] = selected
15161512
schedules.append(name)

0 commit comments

Comments
 (0)