Optimized code a little

This commit is contained in:
Maximilian Giller 2022-05-08 22:51:48 +02:00
parent b47435cb56
commit 966f9aa005

View file

@ -1,5 +1,4 @@
from datetime import datetime, time, timedelta
import string
from typing import Dict
from interface.philips_hue import PhilipsHue
from sensor.people_counter import PeopleCounter
@ -54,7 +53,7 @@ def time_minus_time(time_a: time, time_b: time) -> timedelta:
return dt_a - dt_b
def get_scene_for_time(time: time) -> string:
def get_scene_for_time(time: time) -> str:
"""Determines the correct scene to activate for a given time.
Args:
@ -71,7 +70,7 @@ def get_scene_for_time(time: time) -> string:
previous_scene = None
for start_time, scene in SCHEDULE.items():
# If current time is still after schedule time, just keep going
if time_minus_time(start_time, time) < timedelta(0):
if start_time <= time:
previous_scene = scene
continue
@ -181,7 +180,7 @@ def trigger_change(triggerState: Dict):
motion_triggered_lights = target_light_state
def set_light_scene(target_scene: string) -> bool:
def set_light_scene(target_scene: str) -> bool:
"""Sets the lights to the given scene, but only, if lights are already on. Does not correct count if lights are in an unexpected state.
Args:
@ -256,6 +255,7 @@ def update_scene():
set_light_scene(scene)
logging.debug(f'Updated scene at {datetime.now().time()} to {scene}.')
def register_time_triggers():
"""Registeres time triggered callbacks based on the schedule, to adjust the current scene, if lights are on.
"""
@ -275,6 +275,7 @@ def register_time_triggers():
logging.info("Registered time triggers.")
if __name__ == "__main__":
register_time_triggers()
# Represents callback trigger order