2020from messaging .in_app import update_unread_notifications_count
2121from const import NULL_EQUIVALENTS_SQL
2222
23+ # Predicate used in every negative-event INSERT to skip forced-online devices.
24+ # Centralised here so all three event paths stay in sync.
25+ _SQL_NOT_FORCED_ONLINE = "LOWER(COALESCE(devForceStatus, '')) != 'online'"
26+
2327
2428# Make sure log level is initialized correctly
2529Logger (get_setting_value ("LOG_LEVEL" ))
@@ -179,7 +183,7 @@ def insert_events(db):
179183 WHERE devAlertDown != 0
180184 AND devCanSleep = 0
181185 AND devPresentLastScan = 1
182- AND LOWER(COALESCE(devForceStatus, '')) != 'online'
186+ AND { _SQL_NOT_FORCED_ONLINE }
183187 AND NOT EXISTS (SELECT 1 FROM CurrentScan
184188 WHERE devMac = scanMac
185189 ) """ )
@@ -195,7 +199,7 @@ def insert_events(db):
195199 AND devCanSleep = 1
196200 AND devIsSleeping = 0
197201 AND devPresentLastScan = 0
198- AND LOWER(COALESCE(devForceStatus, '')) != 'online'
202+ AND { _SQL_NOT_FORCED_ONLINE }
199203 AND NOT EXISTS (SELECT 1 FROM CurrentScan
200204 WHERE devMac = scanMac)
201205 AND NOT EXISTS (SELECT 1 FROM Events
@@ -231,7 +235,7 @@ def insert_events(db):
231235 FROM Devices
232236 WHERE devAlertDown = 0
233237 AND devPresentLastScan = 1
234- AND LOWER(COALESCE(devForceStatus, '')) != 'online'
238+ AND { _SQL_NOT_FORCED_ONLINE }
235239 AND NOT EXISTS (SELECT 1 FROM CurrentScan
236240 WHERE devMac = scanMac
237241 ) """ )
0 commit comments