bundles/infobeamer-monitor: only dump state if device is online

This commit is contained in:
Franzi 2023-12-27 14:55:15 +01:00
parent 2e2e8cf7c0
commit e33cc65cb1
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -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,10 +103,9 @@ while True:
)
)
mqtt_out(
'new device found!',
"new device found!",
device=device,
)
if device["is_online"]:
must_dump_state = True
else:
@ -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
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"]: