Improve sensor ID mapping and error handling for real-time data
- Add robust mapping from WebSocket sensor IDs to API sensor IDs - Enhance error handling for backend connection issues - Remove legacy room metrics summary from SensorManagementView - Add loading and error states to sensor grid - Track recently updated sensors for UI feedback - Normalize incoming sensor data for compatibility
This commit is contained in:
@@ -55,6 +55,12 @@ export const useRoomStore = defineStore('room', () => {
|
||||
function updateRoomData(data: SensorReading) {
|
||||
const sensorStore = useSensorStore()
|
||||
|
||||
// Validate data structure and provide fallbacks
|
||||
if (!data.energy || !data.co2) {
|
||||
console.warn('Invalid sensor reading data, missing energy or co2 properties:', data)
|
||||
return
|
||||
}
|
||||
|
||||
// Store latest reading in sensor store
|
||||
sensorStore.updateLatestReading(data)
|
||||
|
||||
@@ -65,8 +71,8 @@ export const useRoomStore = defineStore('room', () => {
|
||||
roomMetrics = {
|
||||
room: data.room,
|
||||
sensors: [data.sensorId],
|
||||
energy: { current: 0, total: 0, average: 0, unit: data.energy.unit },
|
||||
co2: { current: 0, average: 0, max: 0, status: 'good', unit: data.co2.unit },
|
||||
energy: { current: 0, total: 0, average: 0, unit: data.energy?.unit || 'kWh' },
|
||||
co2: { current: 0, average: 0, max: 0, status: 'good', unit: data.co2?.unit || 'ppm' },
|
||||
occupancyEstimate: 'low',
|
||||
lastUpdated: data.timestamp,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user