- Added @elysiajs/swagger dependency to package.json for API documentation. - Removed the old bed router and replaced it with a new history router. - Created a new state router to manage WebSocket connections and state updates. - Implemented a comprehensive state management system with the StateManager service. - Introduced AlarmManagement and BedService services for handling alarms and sensor readings. - Established a new MQTT service for managing MQTT connections and subscriptions. - Created an AlarmStateStore to manage volatile alerts and their states. - Defined FrontendState types for structured state management and WebSocket messaging.
63 lines
No EOL
1.5 KiB
TypeScript
63 lines
No EOL
1.5 KiB
TypeScript
export interface MeasurementPointState {
|
|
id: string;
|
|
sensorId: string;
|
|
label: string;
|
|
zone: string;
|
|
x: number;
|
|
y: number;
|
|
pin: number;
|
|
currentValue: number;
|
|
lastUpdateTime: Date;
|
|
warningThreshold: number;
|
|
alarmThreshold: number;
|
|
warningDelayMs: number;
|
|
status: 'normal' | 'warning' | 'alarm' | 'offline';
|
|
}
|
|
|
|
export interface AlertState {
|
|
id: string;
|
|
measurementPointId: string;
|
|
type: 'WARNING' | 'ALARM';
|
|
value: number;
|
|
threshold: number;
|
|
acknowledged: boolean;
|
|
silenced: boolean;
|
|
startTime: Date;
|
|
endTime?: Date;
|
|
sensorLabel: string;
|
|
zone: string;
|
|
}
|
|
|
|
export interface SystemStatus {
|
|
mqttConnected: boolean;
|
|
databaseConnected: boolean;
|
|
lastHeartbeat: Date;
|
|
activeConnections: number;
|
|
totalMeasurementPoints: number;
|
|
activeSensors: number;
|
|
}
|
|
|
|
export interface FrontendState {
|
|
// Measurement points and sensor data
|
|
measurementPoints: Record<string, MeasurementPointState>;
|
|
|
|
// Active alerts
|
|
alerts: Record<string, AlertState>;
|
|
|
|
// System status
|
|
system: SystemStatus;
|
|
}
|
|
|
|
// State update events
|
|
export interface StateUpdateEvent {
|
|
type: 'FULL_STATE' | 'PARTIAL_UPDATE' | 'SENSOR_UPDATE' | 'ALERT_UPDATE' | 'SYSTEM_UPDATE';
|
|
timestamp: Date;
|
|
data: Partial<FrontendState> | MeasurementPointState | AlertState | SystemStatus;
|
|
}
|
|
|
|
// WebSocket message types
|
|
export interface WebSocketMessage {
|
|
type: 'STATE_UPDATE' | 'HEARTBEAT' | 'ERROR' | 'ACKNOWLEDGE_ALERT' | 'SILENCE_ALERT';
|
|
payload: StateUpdateEvent | { alertId: string } | { message: string };
|
|
timestamp: Date;
|
|
} |