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): def mqtt_dump_state(device):
if not device["is_online"]:
return
mqtt_out( mqtt_out(
"Sync status: {} - Location: {} - Running Setup: {} ({}) - Resolution: {}".format( "Sync status: {} - Location: {} - Running Setup: {} ({}) - Resolution: {}".format(
"yes" if device["is_synced"] else "unknown", "yes" if device["is_synced"] else "unknown",
@ -68,7 +70,10 @@ mqtt_out("Monitor starting up")
while True: while True:
try: try:
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() r.raise_for_status()
ib_state = r.json()["devices"] ib_state = r.json()["devices"]
except RequestException as e: except RequestException as e:
@ -98,11 +103,10 @@ while True:
) )
) )
mqtt_out( mqtt_out(
'new device found!', "new device found!",
device=device, device=device,
) )
if device["is_online"]: must_dump_state = True
must_dump_state = True
else: else:
if device["is_online"] != state[did]["is_online"]: if device["is_online"] != state[did]["is_online"]:
@ -114,15 +118,18 @@ while True:
LOG.info("device {} is now {}".format(did, online_status)) LOG.info("device {} is now {}".format(did, online_status))
mqtt_out( mqtt_out(
f"online status changed to {online_status}", f"status changed to {online_status}",
level="INFO" if device["is_online"] else "WARN", level="INFO" if device["is_online"] else "WARN",
device=device, device=device,
) )
if device["is_online"]: must_dump_state = True
must_dump_state = True
if device["description"] != state[did]["description"]: 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 must_dump_state = True
if device["is_online"]: if device["is_online"]: