@@ -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,18 +768,19 @@ 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
@@ -793,7 +795,7 @@ def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, dict[str, str]]:
793795 for rule in self ._domain_objects .findall ("./rule" ):
794796 if rule .find (locator1 ) is not None :
795797 name = rule .find ("name" ).text
796- active = rule .find ("active" ).text == "true"
798+ active = rule .find ("active" ).text
797799 if rule .find (locator2 ) is not None :
798800 schedule_ids [rule .attrib ["id" ]] = {"location" : loc_id , "name" : name , "active" : active }
799801 else :
@@ -1498,7 +1500,7 @@ def _schedules(self, location: str) -> tuple[list[str], str]:
14981500
14991501 schedules : list [str ] = []
15001502 for rule_id , data in rule_ids .items ():
1501- active = data ["active" ]
1503+ active = data ["active" ] == "true"
15021504 name = data ["name" ]
15031505 locator = f'./rule[@id="{ rule_id } "]/directives'
15041506 # Show an empty schedule as no schedule found
0 commit comments