feat: Add Swagger documentation support and restructure routes
- 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.
This commit is contained in:
parent
a767dc3635
commit
4ae5196ef1
12 changed files with 1189 additions and 1 deletions
63
types/FrontendState.ts
Normal file
63
types/FrontendState.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue