Prefer auto-discovered hostname over device label in alerts
Label in device_labels is for tracking/identification. When mDNS reveals the real device name, use it. Label serves as fallback when no hostname has been discovered yet.
This commit is contained in:
+11
-12
@@ -919,23 +919,22 @@ def fmt_duration(secs: float) -> str:
|
||||
|
||||
|
||||
def format_arrival(hostname: str, ip: str, vendor: str, mac: str) -> str:
|
||||
"""Format arrival alert message. Uses friendly label if configured, else hostname/vendor."""
|
||||
"""Format arrival alert message. Discovered hostname takes precedence; label is fallback."""
|
||||
label = device_labels.get(_normalize_mac(mac))
|
||||
if label:
|
||||
return f"[NET] ARRIVED: {label} ({ip})"
|
||||
if hostname == ip:
|
||||
return f"[NET] ARRIVED: {ip} [{vendor}] MAC:{mac}"
|
||||
return f"[NET] ARRIVED: {hostname} ({ip}) [{vendor}] MAC:{mac}"
|
||||
# Use discovered hostname if it's real (not just the IP); fall back to label
|
||||
display = (hostname if hostname and hostname != ip else None) or label
|
||||
if display:
|
||||
return f"[NET] ARRIVED: {display} ({ip})"
|
||||
return f"[NET] ARRIVED: {ip} [{vendor}] MAC:{mac}"
|
||||
|
||||
|
||||
def format_departure(hostname: str, ip: str, vendor: str, mac: str, duration: str) -> str:
|
||||
"""Format departure alert message. Uses friendly label if configured, else hostname/vendor."""
|
||||
"""Format departure alert message. Discovered hostname takes precedence; label is fallback."""
|
||||
label = device_labels.get(_normalize_mac(mac))
|
||||
if label:
|
||||
return f"[NET] DEPARTED: {label} ({ip}) — present {duration}"
|
||||
if hostname == ip:
|
||||
return f"[NET] DEPARTED: {ip} [{vendor}] MAC:{mac} — present {duration}"
|
||||
return f"[NET] DEPARTED: {hostname} ({ip}) [{vendor}] MAC:{mac} — present {duration}"
|
||||
display = (hostname if hostname and hostname != ip else None) or label
|
||||
if display:
|
||||
return f"[NET] DEPARTED: {display} ({ip}) — present {duration}"
|
||||
return f"[NET] DEPARTED: {ip} [{vendor}] MAC:{mac} — present {duration}"
|
||||
|
||||
|
||||
def _update_occupancy_state_unlocked() -> None:
|
||||
|
||||
Reference in New Issue
Block a user