From df6ecba5e5235d4ebd9c3d474a5be57af05a49f4 Mon Sep 17 00:00:00 2001 From: Cobra Date: Tue, 14 Apr 2026 14:56:20 -0400 Subject: [PATCH] Restrict occupancy to personal devices only (phones/wearables) Previously counted every non-infrastructure device toward OCCUPIED state, causing TVs and other stationary equipment to falsely indicate occupancy. Now only MACs in device_labels or personal_devices count. Everything else is observed but ignored for presence purposes. --- net_alerter/net_alerter.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net_alerter/net_alerter.py b/net_alerter/net_alerter.py index 10e2fd0..e9403c6 100644 --- a/net_alerter/net_alerter.py +++ b/net_alerter/net_alerter.py @@ -901,10 +901,15 @@ def _update_occupancy_state_unlocked() -> None: """ global location_occupancy - # Count active enrolled devices that are not infrastructure (in known_devices, not marked departing, not infrastructure IP) + # Count only explicitly configured personal devices (phones/wearables in device_labels or personal_devices) + # Ignores all other devices — TVs, smart home, unknown equipment, etc. + def _is_personal(mac: str) -> bool: + n = _normalize_mac(mac) + return n in device_labels or n in personal_devices + active_enrolled_count = 0 for mac, dev in known_devices.items(): - if not dev.get('departing', False) and dev['ip'] not in infrastructure_ips: + if _is_personal(mac) and not dev.get('departing', False) and dev['ip'] not in infrastructure_ips: active_enrolled_count += 1 # Determine new occupancy state @@ -915,8 +920,8 @@ def _update_occupancy_state_unlocked() -> None: if new_occupancy == "OCCUPIED": 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(_normalize_mac(mac)) or dev.get('vendor') or mac[-8:] + if _is_personal(mac) and not dev.get('departing', False) and dev['ip'] not in infrastructure_ips: + label = device_labels.get(_normalize_mac(mac)) or mac[-8:] present.append(label) msg = f"[NET] Location: OCCUPIED ({', '.join(present)})" else: @@ -925,7 +930,7 @@ def _update_occupancy_state_unlocked() -> None: send_alert(msg) location_occupancy = new_occupancy - logging.info(f"Location occupancy updated to {location_occupancy} ({active_enrolled_count} enrolled non-infra devices active)") + logging.info(f"Location occupancy updated to {location_occupancy} ({active_enrolled_count} personal devices active)") def update_occupancy_state() -> None: