Config update

This commit is contained in:
2025-12-07 12:22:33 +01:00
parent 9718d9428a
commit 52d11bfff0
9 changed files with 318 additions and 222 deletions

View File

@@ -1,40 +1,6 @@
from datetime import datetime, timedelta
from datetime import datetime
from ir_helpers import *
TIMEOUT_REPEAT_PRESS = 5 # time to switch states when pressed shortly in sequence, in seconds
# --------------------------------- Helper functions ----------------------------------------------------
light_scene_helper_dict = {}
def scene_helper(scene_function):
"""Function to manage the repeated press of the same action
When pressed shortly in sequence, states are cycled
Otherwise light is toggled"""
unique_name_for_globals = id(scene_function)
is_on_func, scenes = scene_function()
last_called, call_idx = light_scene_helper_dict.get(unique_name_for_globals, (datetime.now(), -1))
now = datetime.now()
time_since_last_call = now - last_called
recently_called = (time_since_last_call < timedelta(seconds=TIMEOUT_REPEAT_PRESS))
light_already_on = is_on_func()
log.warning(f"{light_already_on=}")
if recently_called:
call_idx = (call_idx + 1)
else:
call_idx = -1
if light_already_on and call_idx == -1:
scenes[-1]()
call_idx = -1
elif not light_already_on:
scenes[0]()
call_idx = 0
else:
idx = call_idx % len(scenes)
scenes[idx]()
light_scene_helper_dict[unique_name_for_globals] = (now, call_idx)
# --------------------------------- "Scenes" for actions ----------------------------------------------------