From e33cc65cb172557e4d7e414044976ff416bf7f57 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Wed, 27 Dec 2023 14:55:15 +0100 Subject: [PATCH] bundles/infobeamer-monitor: only dump state if device is online --- bundles/infobeamer-monitor/files/monitor.py | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bundles/infobeamer-monitor/files/monitor.py b/bundles/infobeamer-monitor/files/monitor.py index 4e6c855..466c625 100644 --- a/bundles/infobeamer-monitor/files/monitor.py +++ b/bundles/infobeamer-monitor/files/monitor.py @@ -52,6 +52,8 @@ def mqtt_out(message, level="INFO", device=None): def mqtt_dump_state(device): + if not device["is_online"]: + return mqtt_out( "Sync status: {} - Location: {} - Running Setup: {} ({}) - Resolution: {}".format( "yes" if device["is_synced"] else "unknown", @@ -68,7 +70,10 @@ mqtt_out("Monitor starting up") while True: try: try: - r = get("https://info-beamer.com/api/v1/device/list", auth=("", CONFIG["api_key"])) + r = get( + "https://info-beamer.com/api/v1/device/list", + auth=("", CONFIG["api_key"]), + ) r.raise_for_status() ib_state = r.json()["devices"] except RequestException as e: @@ -98,11 +103,10 @@ while True: ) ) mqtt_out( - 'new device found!', + "new device found!", device=device, ) - if device["is_online"]: - must_dump_state = True + must_dump_state = True else: if device["is_online"] != state[did]["is_online"]: @@ -114,15 +118,18 @@ while True: LOG.info("device {} is now {}".format(did, online_status)) mqtt_out( - f"online status changed to {online_status}", + f"status changed to {online_status}", level="INFO" if device["is_online"] else "WARN", device=device, ) - if device["is_online"]: - must_dump_state = True + must_dump_state = True if device["description"] != state[did]["description"]: - LOG.info("device {} changed name to {}".format(did, device["description"])) + LOG.info( + "device {} changed name to {}".format( + did, device["description"] + ) + ) must_dump_state = True if device["is_online"]: