diff --git a/net_alerter/net_alerter.py b/net_alerter/net_alerter.py index 12c8cc2..10e2fd0 100644 --- a/net_alerter/net_alerter.py +++ b/net_alerter/net_alerter.py @@ -875,23 +875,23 @@ def fmt_duration(secs: float) -> str: def format_arrival(hostname: str, ip: str, vendor: str, mac: str) -> str: - """Format arrival alert message. Deduplicate IP if hostname equals IP.""" + """Format arrival alert message. Uses friendly label if configured, else hostname/vendor.""" + label = device_labels.get(_normalize_mac(mac)) + if label: + return f"[NET] ARRIVED: {label} ({ip})" if hostname == ip: - # Hostname resolution failed, don't repeat IP return f"[NET] ARRIVED: {ip} [{vendor}] MAC:{mac}" - else: - # Hostname resolved successfully, show both - return f"[NET] ARRIVED: {hostname} ({ip}) [{vendor}] MAC:{mac}" + return f"[NET] ARRIVED: {hostname} ({ip}) [{vendor}] MAC:{mac}" def format_departure(hostname: str, ip: str, vendor: str, mac: str, duration: str) -> str: - """Format departure alert message. Deduplicate IP if hostname equals IP.""" + """Format departure alert message. Uses friendly label if configured, else hostname/vendor.""" + label = device_labels.get(_normalize_mac(mac)) + if label: + return f"[NET] DEPARTED: {label} ({ip}) — present {duration}" if hostname == ip: - # Hostname resolution failed, don't repeat IP return f"[NET] DEPARTED: {ip} [{vendor}] MAC:{mac} — present {duration}" - else: - # Hostname resolved successfully, show both - return f"[NET] DEPARTED: {hostname} ({ip}) [{vendor}] MAC:{mac} — present {duration}" + return f"[NET] DEPARTED: {hostname} ({ip}) [{vendor}] MAC:{mac} — present {duration}" def _update_occupancy_state_unlocked() -> None: @@ -916,7 +916,7 @@ def _update_occupancy_state_unlocked() -> None: present = [] for mac, dev in known_devices.items(): if not dev.get('departing', False) and dev['ip'] not in infrastructure_ips: - label = device_labels.get(mac) or dev.get('vendor') or mac[-8:] + label = device_labels.get(_normalize_mac(mac)) or dev.get('vendor') or mac[-8:] present.append(label) msg = f"[NET] Location: OCCUPIED ({', '.join(present)})" else: