added logging
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user