From dbf11551c5a271bb34a7d172ff0343e3cca0a361 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Thu, 9 May 2024 02:43:17 +0200 Subject: [PATCH] Fixed typo, Improved away mode trigger mechanism --- src/endpoints/handlers/fritz.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/endpoints/handlers/fritz.py b/src/endpoints/handlers/fritz.py index 7b36a22..8a8f8e4 100644 --- a/src/endpoints/handlers/fritz.py +++ b/src/endpoints/handlers/fritz.py @@ -7,6 +7,7 @@ from ..hue import hue refresh_every_seconds: int = 15 # Every x seconds devices are polled again trigger_away_after_seconds: int = 60 # After all away-devices are gone for x seconds +away_triggered = False away_devices = ["B2:06:77:EE:A9:0F"] # Max' iPhone macaddresses_to_track = ["B2:06:77:EE:A9:0F"] # Max' iPhone @@ -30,9 +31,9 @@ def get_all_devices() -> list: return devices -def get_specific_device(mac_adress: str) -> dict: +def get_specific_device(mac_address: str) -> dict: return fritz_api.call_action( - "Hosts", "GetSpecificHostEntry", NewMACAddress=mac_adress + "Hosts", "GetSpecificHostEntry", NewMACAddress=mac_address ) @@ -46,9 +47,13 @@ def check_for_change(): break # Execute away mode + global away_triggered if all_away: - hue.in_room_deactivate_lights("Max Zimmer") - + if not away_triggered: + away_triggered = True + hue.in_room_deactivate_lights("Max Zimmer") + else: + away_triggered = False async def track_network_devices(): global devices_last_online