diff --git a/cherry/bedtime/__init__.py b/cherry/bedtime/__init__.py index 78fbf8b..0f9d4e7 100644 --- a/cherry/bedtime/__init__.py +++ b/cherry/bedtime/__init__.py @@ -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: