Optimized code a little
This commit is contained in:
parent
b47435cb56
commit
966f9aa005
1 changed files with 16 additions and 15 deletions
|
@ -1,5 +1,4 @@
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import datetime, time, timedelta
|
||||||
import string
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from interface.philips_hue import PhilipsHue
|
from interface.philips_hue import PhilipsHue
|
||||||
from sensor.people_counter import PeopleCounter
|
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
|
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.
|
"""Determines the correct scene to activate for a given time.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -71,7 +70,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 time_minus_time(start_time, time) < timedelta(0):
|
if start_time <= time:
|
||||||
previous_scene = scene
|
previous_scene = scene
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -181,7 +180,7 @@ def trigger_change(triggerState: Dict):
|
||||||
motion_triggered_lights = target_light_state
|
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.
|
"""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:
|
Args:
|
||||||
|
@ -256,6 +255,7 @@ def update_scene():
|
||||||
set_light_scene(scene)
|
set_light_scene(scene)
|
||||||
logging.debug(f'Updated scene at {datetime.now().time()} to {scene}.')
|
logging.debug(f'Updated scene at {datetime.now().time()} to {scene}.')
|
||||||
|
|
||||||
|
|
||||||
def register_time_triggers():
|
def register_time_triggers():
|
||||||
"""Registeres time triggered callbacks based on the schedule, to adjust the current scene, if lights are on.
|
"""Registeres time triggered callbacks based on the schedule, to adjust the current scene, if lights are on.
|
||||||
"""
|
"""
|
||||||
|
@ -275,11 +275,12 @@ def register_time_triggers():
|
||||||
logging.info("Registered time triggers.")
|
logging.info("Registered time triggers.")
|
||||||
|
|
||||||
|
|
||||||
register_time_triggers()
|
if __name__ == "__main__":
|
||||||
|
register_time_triggers()
|
||||||
|
|
||||||
# Represents callback trigger order
|
# Represents callback trigger order
|
||||||
counter.hookChange(change_cb)
|
counter.hookChange(change_cb)
|
||||||
counter.hookCounting(count_change)
|
counter.hookCounting(count_change)
|
||||||
counter.hookTrigger(trigger_change)
|
counter.hookTrigger(trigger_change)
|
||||||
|
|
||||||
counter.run()
|
counter.run()
|
||||||
|
|
Loading…
Reference in a new issue