Fixed no subtract between times
This commit is contained in:
parent
6f3ecdece9
commit
e5ce38851c
1 changed files with 19 additions and 2 deletions
|
@ -37,6 +37,23 @@ timeloop: Timeloop = Timeloop() # Used for time triggered schedule
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def time_minus_time(time_a: time, time_b: time) -> timedelta:
|
||||||
|
"""Implementes a basic timedelta function for time objects.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
time_a (time): Time to subtract from.
|
||||||
|
time_b (time): Time to be subtracted.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
timedelta: Delta between the two time objects.
|
||||||
|
"""
|
||||||
|
today = datetime.today()
|
||||||
|
dt_a = datetime.combine(today, time_a)
|
||||||
|
dt_b = datetime.combine(today, time_b)
|
||||||
|
|
||||||
|
return dt_a - dt_b
|
||||||
|
|
||||||
|
|
||||||
def get_scene_for_time(time: time) -> string:
|
def get_scene_for_time(time: time) -> string:
|
||||||
"""Determines the correct scene to activate for a given time.
|
"""Determines the correct scene to activate for a given time.
|
||||||
|
|
||||||
|
@ -54,7 +71,7 @@ def get_scene_for_time(time: time) -> string:
|
||||||
previous_scene = None
|
previous_scene = None
|
||||||
for start_time, scene in SCHEDULE.items():
|
for start_time, scene in SCHEDULE.items():
|
||||||
# If current time is still after schedule time, just keep going
|
# If current time is still after schedule time, just keep going
|
||||||
if start_time - time < 0:
|
if time_minus_time(start_time, time) < 0:
|
||||||
previous_scene = scene
|
previous_scene = scene
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -247,7 +264,7 @@ def register_time_triggers():
|
||||||
return
|
return
|
||||||
|
|
||||||
for time in SCHEDULE.keys():
|
for time in SCHEDULE.keys():
|
||||||
delta = time - datetime.now().time()
|
delta = time_minus_time(time, datetime.now().time())
|
||||||
if delta < 0:
|
if delta < 0:
|
||||||
delta += timedelta(1)
|
delta += timedelta(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue