@@ -602,19 +602,19 @@ async def _set_schedule_state_legacy(
602602 await self ._request (uri , method = "put" , data = data )
603603 self ._schedule_old_states [loc_id ][name ] = new_state
604604
605- def determine_contexts (self , loc_id : str , schedule_rule_id : str ) -> etree :
605+ def determine_contexts (self , loc_id : str , state : str , sched_id : str ) -> etree :
606606 """Helper function for set_schedule_state()."""
607- locator = f'.//*[@id="{ schedule_rule_id } "]/contexts'
607+ locator = f'.//*[@id="{ sched_id } "]/contexts'
608608 contexts = self ._domain_objects .find (locator )
609609 locator = f'.//*[@id="{ loc_id } "].../...'
610610 if (subject := contexts .find (locator )) is None :
611611 subject = f'<context><zone><location id="{ loc_id } " /></zone></context>'
612612 subject = etree .fromstring (subject )
613613
614- if new_state == "off" :
614+ if state == "off" :
615615 self ._last_active [loc_id ] = name
616616 contexts .remove (subject )
617- if new_state == "on" :
617+ if state == "on" :
618618 contexts .append (subject )
619619
620620 contexts = etree .tostring (contexts , encoding = "unicode" ).rstrip ()
@@ -665,7 +665,7 @@ async def set_schedule_state(
665665 template_id = self ._domain_objects .find (locator ).attrib ["id" ]
666666 template = f'<template id="{ template_id } " />'
667667
668- self .determine_contexts (loc_id , schedule_rule_id )
668+ self .determine_contexts (loc_id , new_state , schedule_rule_id )
669669 uri = f"{ RULES } ;id={ schedule_rule_id } "
670670 data = (
671671 f'<rules><rule id="{ schedule_rule_id } "><name><![CDATA[{ name } ]]></name>'
0 commit comments