Refactor stores for modularity and API type updates

- Split energy store into sensor, room, analytics, and websocket stores
- Add new analytics, room, sensor, and websocket stores - Update API
types for sensors (SensorDevice, SensorAction) - Update sensorsApi to
use new SensorDevice type - Add central index for store exports and
types - Refactor energy store to delegate to modular stores - Remove
legacy code and consolidate API logic
This commit is contained in:
rafaeldpsilva
2025-09-25 17:09:42 +01:00
parent 326746b5ef
commit 3299472c85
8 changed files with 1139 additions and 857 deletions

View File

@@ -75,19 +75,6 @@ export interface SensorReading {
metadata?: Record<string, any>
}
export interface SensorInfo {
name: string
sensor_id: string
sensor_type: SensorType
room?: string
status: SensorStatus
first_seen: number
last_seen: number
total_readings: number
latest_values?: Record<string, any>
metadata?: Record<string, any>
}
export interface RoomInfo {
room: string
sensor_count: number
@@ -188,6 +175,60 @@ export interface SystemEvent {
room?: string
}
export interface SensorDevice {
id: string
sensor_id: string
name: string
type: SensorType
sensor_type: SensorType
room: string
status: SensorStatus
location?: string
lastSeen: number
total_readings?: number
capabilities: {
monitoring: string[]
actions: SensorAction[]
}
metadata: {
location?: string
model?: string
firmware?: string
battery?: number
created_at?: string
updated_at?: string
manufacturer?: string
}
}
export interface SensorAction {
id: string
name: string
type: 'toggle' | 'adjust' | 'trigger'
icon: string
parameters?: {
min?: number
max?: number
step?: number
options?: string[]
}
}
export interface SensorInfo {
id: string
sensor_id: string
name: string
type: SensorType
sensor_type: SensorType
room: string
status: SensorStatus
location?: string
created_at?: string
updated_at?: string
manufacturer?: string
model?: string
}
export enum SensorType {
ENERGY = 'energy',
CO2 = 'co2',

View File

@@ -1,6 +1,6 @@
import {
apiClient,
type SensorInfo,
type SensorDevice,
type SensorReading,
type DataQuery,
type DataResponse,
@@ -13,12 +13,12 @@ export const sensorsApi = {
room?: string
sensor_type?: SensorType
status?: SensorStatus
}): Promise<SensorInfo[]> {
return apiClient.get<SensorInfo[]>('/api/v1/sensors/get', params)
}): Promise<SensorDevice[]> {
return apiClient.get<SensorDevice[]>('/api/v1/sensors/get', params)
},
async getSensor(sensorId: string): Promise<SensorInfo> {
return apiClient.get<SensorInfo>(`/api/v1/sensors/${sensorId}`)
async getSensor(sensorId: string): Promise<SensorDevice> {
return apiClient.get<SensorDevice>(`/api/v1/sensors/${sensorId}`)
},
async getSensorData(