Small improvements

This commit is contained in:
Maximilian Giller 2023-10-09 17:24:07 +02:00
parent 6830a31454
commit 11814a211d
4 changed files with 17 additions and 13 deletions

6
.gitignore vendored
View file

@ -161,4 +161,8 @@ cython_debug/
log.txt log.txt
.env .env
.vscode/c_cpp_properties.json
.vscode/extensions.json
.vscode/launch.json
.vscode/settings.json

View file

@ -5,4 +5,4 @@ vl53l1x
phue phue
# For statistics # For statistics
matplotlib # matplotlib

View file

@ -63,16 +63,16 @@ def count_change(change: int) -> None:
if peopleCount <= 0 and previous_lights_state: if peopleCount <= 0 and previous_lights_state:
# Count was 0, but lights were on => people count was not actually 0 # Count was 0, but lights were on => people count was not actually 0
peopleCount = 1 peopleCount = 1
logging.debug(f"People count corrected to {peopleCount}") logging.info(f"People count corrected to {peopleCount}")
elif peopleCount > 0 and not previous_lights_state: elif peopleCount > 0 and not previous_lights_state:
# Count was >0, but lights were off => people count was actually 0 # Count was >0, but lights were off => people count was actually 0
peopleCount = 0 peopleCount = 0
logging.debug(f"People count corrected to {peopleCount}") logging.info(f"People count corrected to {peopleCount}")
peopleCount += change peopleCount += change
if peopleCount < 0: if peopleCount < 0:
peopleCount = 0 peopleCount = 0
logging.debug(f"People count changed by {change}") logging.info(f"People count changed by {change}")
# Handle light # Handle light
target_light_state = peopleCount > 0 target_light_state = peopleCount > 0
@ -100,7 +100,7 @@ def set_light_state(target_light_state: bool) -> bool:
# Adjust light as necessary # Adjust light as necessary
hue.set_group(hue_conf["light_group"], {"on": target_light_state}) hue.set_group(hue_conf["light_group"], {"on": target_light_state})
logging.debug(f"Light state changed to {target_light_state}") logging.info(f"Light state changed to {target_light_state}")
return previous_lights_state return previous_lights_state

View file

@ -127,16 +127,16 @@ def count_change(change: int) -> None:
if peopleCount <= 0 and previous_lights_state and not motion_triggered_lights: if peopleCount <= 0 and previous_lights_state and not motion_triggered_lights:
# Count was 0, but lights were on (not because of motion triggers) => people count was not actually 0 # Count was 0, but lights were on (not because of motion triggers) => people count was not actually 0
peopleCount = 1 peopleCount = 1
logging.debug(f"People count corrected to {peopleCount}") logging.info(f"People count corrected to {peopleCount}")
elif peopleCount > 0 and not previous_lights_state: elif peopleCount > 0 and not previous_lights_state:
# Count was >0, but lights were off => people count was actually 0 # Count was >0, but lights were off => people count was actually 0
peopleCount = 0 peopleCount = 0
logging.debug(f"People count corrected to {peopleCount}") logging.info(f"People count corrected to {peopleCount}")
peopleCount += change peopleCount += change
if peopleCount < 0: if peopleCount < 0:
peopleCount = 0 peopleCount = 0
logging.debug(f"People count changed by {change}") logging.info(f"People count changed by {change}")
# Handle light # Handle light
target_light_state = peopleCount > 0 target_light_state = peopleCount > 0
@ -201,7 +201,7 @@ def set_light_scene(target_scene: str) -> bool:
# Set lights to scene # Set lights to scene
hue.set_group_scene(hue_conf["light_group"], target_scene) hue.set_group_scene(hue_conf["light_group"], target_scene)
logging.debug(f"Light scene set to {target_scene}") logging.info(f"Light scene set to {target_scene}")
def set_light_state(target_light_state: bool) -> bool: def set_light_state(target_light_state: bool) -> bool:
@ -223,12 +223,12 @@ def set_light_state(target_light_state: bool) -> bool:
if target_light_state and target_scene: if target_light_state and target_scene:
# Set to specific scene if exists # Set to specific scene if exists
hue.set_group_scene(hue_conf["light_group"], target_scene) hue.set_group_scene(hue_conf["light_group"], target_scene)
logging.debug( logging.info(
f"Light state changed to {target_light_state} with scene {target_scene}" f"Light state changed to {target_light_state} with scene {target_scene}"
) )
else: else:
hue.set_group(hue_conf["light_group"], {"on": target_light_state}) hue.set_group(hue_conf["light_group"], {"on": target_light_state})
logging.debug(f"Light state changed to {target_light_state}") logging.info(f"Light state changed to {target_light_state}")
return previous_lights_state return previous_lights_state
@ -249,7 +249,7 @@ def update_scene():
return return
set_light_scene(scene) set_light_scene(scene)
logging.debug(f"Updated scene at {datetime.now().time()} to {scene}.") logging.info(f"Updated scene at {datetime.now().time()} to {scene}.")
def register_time_triggers(): def register_time_triggers():