Fire occupancy alert on startup — UNKNOWN→OCCUPIED was silently suppressed

Previously the service would suppress the startup OCCUPIED alert, meaning
if phones were already present when the service started, no Matrix alert
ever fired until a departure+return cycle. Users never received confirmation
the sensor was working.
This commit is contained in:
Cobra
2026-04-14 14:39:02 -04:00
parent a3df9ed958
commit 2fb6e7e8e1
+5 -8
View File
@@ -898,14 +898,11 @@ def _update_occupancy_state_unlocked() -> None:
# Determine new occupancy state
new_occupancy = "OCCUPIED" if active_enrolled_count > 0 else "VACANT"
# Fire alert on transitions (but not UNKNOWN → OCCUPIED on startup)
# Fire alert on all transitions including startup UNKNOWN → OCCUPIED
if new_occupancy != location_occupancy:
if not (location_occupancy == "UNKNOWN" and new_occupancy == "OCCUPIED"):
msg = f"[NET] Location: {new_occupancy}"
logging.info(msg)
send_alert(msg)
else:
logging.debug(f"Suppressing startup occupancy alert: UNKNOWN → OCCUPIED")
msg = f"[NET] Location: {new_occupancy}"
logging.info(msg)
send_alert(msg)
location_occupancy = new_occupancy
logging.info(f"Location occupancy updated to {location_occupancy} ({active_enrolled_count} enrolled non-infra devices active)")
@@ -914,7 +911,7 @@ def _update_occupancy_state_unlocked() -> None:
def update_occupancy_state() -> None:
"""
Update location occupancy state based on presence of personal devices.
Fires Matrix alerts on VACANT/OCCUPIED transitions (not on UNKNOWN transitions).
Fires Matrix alerts on all VACANT/OCCUPIED transitions including startup.
Thread-safe: acquires locks in order: known_lock, then occupancy_lock.
"""
with known_lock: