1
0
Fork 0

pausing should prevent scene activation while still allowing rule processing

Bob Carroll 2023-11-06 20:09:30 -06:00
parent 8f651c14ce
commit 0a5e69c730
1 changed files with 13 additions and 14 deletions

View File

@ -94,8 +94,6 @@ class Rule(object):
:param triggers: a list of rule objects
"""
triggers[0].head = triggers[0]
for i, x in enumerate(triggers):
x.head = triggers[0]
if i > 0:
@ -167,28 +165,29 @@ async def periodic_rule_check(client, chain, timezone, scene, state, mutex):
logging.debug('Begin rule check')
await mutex.acquire()
if state['paused']:
logging.debug('Skipping, bedtime automation is paused')
elif now(timezone) >= midnight:
if now(timezone) >= midnight:
for rule in chain.walk():
if now(timezone).time() < rule.time:
logging.debug(f'Skipping, {rule.name} {rule.time} is in the future')
break
try:
logging.info(f'Rule triggered {rule.name} {rule.time}')
await apply_rule(rule, client)
if state['paused']:
logging.debug(f'Rule skipped {rule.name} {rule.time}, bedtime is paused')
else:
try:
logging.info(f'Rule triggered {rule.name} {rule.time}')
await apply_rule(rule, client)
logging.debug(f'Annoucing {scene} scene activation')
await client.publish('scene/activate', scene)
except Exception as ex:
logging.error(str(ex))
break
logging.debug(f'Annoucing {scene} scene activation')
await client.publish('scene/activate', scene)
except Exception as ex:
logging.error(str(ex))
break
if rule.next is None:
midnight += timedelta(1)
chain = rule.head
logging.debug('Last rule applied, re-winding')
logging.debug('Last rule visited, re-winding')
else:
chain = rule.next
else: