added logging

This commit is contained in:
2026-08-22 16:33:34 +02:00
parent 1a34118ab5
commit 90671d0b9b
5 changed files with 34 additions and 4 deletions
+9 -2
View File
@@ -4,6 +4,8 @@ from __future__ import annotations
import logging
import time
from datetime import datetime
from pathlib import Path
from lib._zyxel import ZyxelError, ZyxelRouter, normalize_mac
from notify import send_notification
@@ -53,11 +55,16 @@ def _build_router(config: dict) -> ZyxelRouter:
def _notify(config: dict, device: dict) -> None:
LOG.info("ARRIVAL: %s", device["name"])
notification = config.get("notification", {})
if not notification.get("enabled", True):
return
message = str(notification.get("message", "{name} arrived home")).format(
name=device["name"], mac=device["mac"]
)
event_log = notification.get("event_log")
if event_log:
timestamp = datetime.now().astimezone().isoformat(timespec="seconds")
with Path(event_log).open("a", encoding="utf-8") as stream:
stream.write(f"{timestamp} {message}\n")
if not notification.get("enabled", True):
return
send_notification(
message,
topic_url=notification.get("topic_url") or None,