PLG: Centralize SQL condition to skip forced-online devices in event inserts

This commit is contained in:
Jokob @NetAlertX
2026-04-10 22:13:09 +00:00
parent 50be56c8bb
commit c80dc9c36a

View File

@@ -20,6 +20,10 @@ from messaging.reporting import skip_repeated_notifications
from messaging.in_app import update_unread_notifications_count
from const import NULL_EQUIVALENTS_SQL
# Predicate used in every negative-event INSERT to skip forced-online devices.
# Centralised here so all three event paths stay in sync.
_SQL_NOT_FORCED_ONLINE = "LOWER(COALESCE(devForceStatus, '')) != 'online'"
# Make sure log level is initialized correctly
Logger(get_setting_value("LOG_LEVEL"))
@@ -179,7 +183,7 @@ def insert_events(db):
WHERE devAlertDown != 0
AND devCanSleep = 0
AND devPresentLastScan = 1
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
AND {_SQL_NOT_FORCED_ONLINE}
AND NOT EXISTS (SELECT 1 FROM CurrentScan
WHERE devMac = scanMac
) """)
@@ -195,7 +199,7 @@ def insert_events(db):
AND devCanSleep = 1
AND devIsSleeping = 0
AND devPresentLastScan = 0
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
AND {_SQL_NOT_FORCED_ONLINE}
AND NOT EXISTS (SELECT 1 FROM CurrentScan
WHERE devMac = scanMac)
AND NOT EXISTS (SELECT 1 FROM Events
@@ -231,7 +235,7 @@ def insert_events(db):
FROM Devices
WHERE devAlertDown = 0
AND devPresentLastScan = 1
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
AND {_SQL_NOT_FORCED_ONLINE}
AND NOT EXISTS (SELECT 1 FROM CurrentScan
WHERE devMac = scanMac
) """)