fix(sf-infrastructure): normalize websocket alert types to canonical camelCase
This commit is contained in:
@@ -4,14 +4,25 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'websocket_event.dart';
|
||||
|
||||
const _alertTypes = {
|
||||
'battery_low',
|
||||
'disconnected',
|
||||
'reconnected',
|
||||
'falldown',
|
||||
'movement',
|
||||
'sos',
|
||||
'abnormal_heart_rate',
|
||||
const _alertTypeAliases = {
|
||||
'battery_low': 'lowBattery',
|
||||
'lowBattery': 'lowBattery',
|
||||
'disconnected': 'disconnect',
|
||||
'disconnect': 'disconnect',
|
||||
'reconnected': 'reconnect',
|
||||
'reconnect': 'reconnect',
|
||||
'falldown': 'falldown',
|
||||
'movement': 'movement',
|
||||
'sos': 'sos',
|
||||
'abnormal_heart_rate': 'abnormalHeartRate',
|
||||
'abnormalHeartRate': 'abnormalHeartRate',
|
||||
'geofenceIn': 'geofenceIn',
|
||||
'geofence_in': 'geofenceIn',
|
||||
'geofenceOut': 'geofenceOut',
|
||||
'geofence_out': 'geofenceOut',
|
||||
'braceletRemoved': 'braceletRemoved',
|
||||
'bracelet_removed': 'braceletRemoved',
|
||||
'standstill': 'standstill',
|
||||
};
|
||||
|
||||
WebSocketEvent? parseWebSocketEvent(String raw) {
|
||||
@@ -30,9 +41,10 @@ WebSocketEvent? parseWebSocketEvent(String raw) {
|
||||
|
||||
type = type.replaceAll('-', '_');
|
||||
|
||||
if (_alertTypes.contains(type)) {
|
||||
final normalizedAlert = _alertTypeAliases[type];
|
||||
if (normalizedAlert != null) {
|
||||
return AlertEvent(
|
||||
type: type,
|
||||
type: normalizedAlert,
|
||||
deviceIdentificator: json['deviceIdentificator'] as String? ?? '',
|
||||
timestamp: timestamp,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user