calculate midnight on iteration to deal with DST changes
parent
0a5e69c730
commit
cb2481c46e
|
@ -149,7 +149,6 @@ async def periodic_rule_check(client, chain, timezone, scene, state, mutex):
|
|||
"""
|
||||
Periodically checks for a matching rule to apply.
|
||||
|
||||
nstalling collected packages: cherry-hue
|
||||
:param client: mqtt client
|
||||
:param chain: the head of a rule chain
|
||||
:param timezone: local time zone object
|
||||
|
@ -157,14 +156,14 @@ async def periodic_rule_check(client, chain, timezone, scene, state, mutex):
|
|||
:param state: shared state dictionary
|
||||
:param mutex: lock for making changes to shared state
|
||||
"""
|
||||
midnight = timezone.localize(
|
||||
datetime.combine(now(timezone), datetime.min.time()))
|
||||
logging.debug(f'Setting time zone to {midnight.tzname()}')
|
||||
|
||||
while True:
|
||||
logging.debug('Begin rule check')
|
||||
await mutex.acquire()
|
||||
|
||||
midnight = timezone.localize(
|
||||
datetime.combine(now(timezone), datetime.min.time()))
|
||||
logging.debug(f'Setting time zone to {midnight.tzname()}')
|
||||
|
||||
if now(timezone) >= midnight:
|
||||
for rule in chain.walk():
|
||||
if now(timezone).time() < rule.time:
|
||||
|
|
Loading…
Reference in New Issue