Disable status events by default

This commit is contained in:
Anton Tananaev
2026-05-13 22:35:58 -07:00
parent 35756817af
commit a89a766440
2 changed files with 13 additions and 6 deletions

View File

@@ -503,6 +503,14 @@ public final class Keys {
List.of(KeyType.CONFIG),
true);
/**
* Generate device connection status events (deviceOnline, deviceOffline, deviceUnknown) on status changes.
*/
public static final ConfigKey<Boolean> EVENT_STATUS_ENABLE = new BooleanConfigKey(
"event.status.enable",
List.of(KeyType.CONFIG),
false);
/**
* If the speed is above specified value, the object is considered to be in motion. Default value is 0.01 knots.
*/

View File

@@ -64,6 +64,7 @@ public class ConnectionManager implements BroadcastInterface {
private final long deviceTimeout;
private final boolean showUnknownDevices;
private final boolean statusEventsEnabled;
private final Map<Long, DeviceSession> sessionsByDeviceId = new ConcurrentHashMap<>();
private final Map<ConnectionKey, Map<String, DeviceSession>> sessionsByEndpoint = new ConcurrentHashMap<>();
@@ -97,6 +98,7 @@ public class ConnectionManager implements BroadcastInterface {
this.deviceLookupService = deviceLookupService;
deviceTimeout = config.getLong(Keys.STATUS_TIMEOUT);
showUnknownDevices = config.getBoolean(Keys.WEB_SHOW_UNKNOWN_DEVICES);
statusEventsEnabled = config.getBoolean(Keys.EVENT_STATUS_ENABLE);
broadcastService.registerListener(this);
}
@@ -238,16 +240,13 @@ public class ConnectionManager implements BroadcastInterface {
String oldStatus = device.getStatus();
device.setStatus(status);
if (!status.equals(oldStatus)) {
String eventType;
Map<Event, Position> events = new HashMap<>();
eventType = switch (status) {
if (!status.equals(oldStatus) && statusEventsEnabled) {
String eventType = switch (status) {
case Device.STATUS_ONLINE -> Event.TYPE_DEVICE_ONLINE;
case Device.STATUS_UNKNOWN -> Event.TYPE_DEVICE_UNKNOWN;
default -> Event.TYPE_DEVICE_OFFLINE;
};
events.put(new Event(eventType, deviceId), null);
notificationManager.updateEvents(events);
notificationManager.updateEvents(Collections.singletonMap(new Event(eventType, deviceId), null));
}
if (time != null) {