From f3bdf1a1531c1f5cf03ebc6ca93a5bdc403f12f5 Mon Sep 17 00:00:00 2001 From: Cobra Date: Tue, 14 Apr 2026 14:39:02 -0400 Subject: [PATCH] =?UTF-8?q?Fire=20occupancy=20alert=20on=20startup=20?= =?UTF-8?q?=E2=80=94=20UNKNOWN=E2=86=92OCCUPIED=20was=20silently=20suppres?= =?UTF-8?q?sed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- net_alerter/net_alerter.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/net_alerter/net_alerter.py b/net_alerter/net_alerter.py index cf9f458..b39710a 100644 --- a/net_alerter/net_alerter.py +++ b/net_alerter/net_alerter.py @@ -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: