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.
This commit is contained in:
@@ -901,10 +901,15 @@ def _update_occupancy_state_unlocked() -> None:
|
|||||||
"""
|
"""
|
||||||
global location_occupancy
|
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
|
active_enrolled_count = 0
|
||||||
for mac, dev in known_devices.items():
|
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
|
active_enrolled_count += 1
|
||||||
|
|
||||||
# Determine new occupancy state
|
# Determine new occupancy state
|
||||||
@@ -915,8 +920,8 @@ def _update_occupancy_state_unlocked() -> None:
|
|||||||
if new_occupancy == "OCCUPIED":
|
if new_occupancy == "OCCUPIED":
|
||||||
present = []
|
present = []
|
||||||
for mac, dev in known_devices.items():
|
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:
|
||||||
label = device_labels.get(_normalize_mac(mac)) or dev.get('vendor') or mac[-8:]
|
label = device_labels.get(_normalize_mac(mac)) or mac[-8:]
|
||||||
present.append(label)
|
present.append(label)
|
||||||
msg = f"[NET] Location: OCCUPIED ({', '.join(present)})"
|
msg = f"[NET] Location: OCCUPIED ({', '.join(present)})"
|
||||||
else:
|
else:
|
||||||
@@ -925,7 +930,7 @@ def _update_occupancy_state_unlocked() -> None:
|
|||||||
send_alert(msg)
|
send_alert(msg)
|
||||||
|
|
||||||
location_occupancy = new_occupancy
|
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:
|
def update_occupancy_state() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user