sensor management page
This commit is contained in:
@@ -48,6 +48,38 @@ interface LegacyEnergyData {
|
||||
unit: string
|
||||
}
|
||||
|
||||
interface SensorDevice {
|
||||
id: string
|
||||
name: string
|
||||
type: 'energy' | 'co2' | 'temperature' | 'humidity' | 'hvac' | 'lighting' | 'security'
|
||||
room: string
|
||||
status: 'online' | 'offline' | 'error'
|
||||
lastSeen: number
|
||||
capabilities: {
|
||||
monitoring: string[] // e.g., ['energy', 'temperature']
|
||||
actions: SensorAction[] // Available actions
|
||||
}
|
||||
metadata: {
|
||||
location: string
|
||||
model?: string
|
||||
firmware?: string
|
||||
battery?: number
|
||||
}
|
||||
}
|
||||
|
||||
interface SensorAction {
|
||||
id: string
|
||||
name: string
|
||||
type: 'toggle' | 'adjust' | 'trigger'
|
||||
icon: string
|
||||
parameters?: {
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
options?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
export const useEnergyStore = defineStore('energy', () => {
|
||||
// State
|
||||
const isConnected = ref(false)
|
||||
@@ -63,6 +95,19 @@ export const useEnergyStore = defineStore('energy', () => {
|
||||
const sensorsData = reactive<Map<string, any>>(new Map()) // Legacy support
|
||||
const roomsData = reactive<Map<string, RoomMetrics>>(new Map())
|
||||
const latestReadings = reactive<Map<string, SensorReading>>(new Map())
|
||||
const sensorDevices = reactive<Map<string, SensorDevice>>(new Map())
|
||||
const availableRooms = ref<string[]>([
|
||||
'Conference Room A',
|
||||
'Conference Room B',
|
||||
'Office Floor 1',
|
||||
'Office Floor 2',
|
||||
'Kitchen',
|
||||
'Lobby',
|
||||
'Server Room',
|
||||
'Storage Room',
|
||||
'Meeting Room 1',
|
||||
'Meeting Room 2'
|
||||
])
|
||||
|
||||
let socket: WebSocket | null = null
|
||||
const newDataBuffer: (LegacyEnergyData | SensorReading)[] = []
|
||||
@@ -233,6 +278,156 @@ export const useEnergyStore = defineStore('energy', () => {
|
||||
return 'critical'
|
||||
}
|
||||
|
||||
// Initialize mock sensor devices
|
||||
function initializeMockSensors() {
|
||||
const mockSensors: SensorDevice[] = [
|
||||
{
|
||||
id: 'sensor_1',
|
||||
name: 'Energy Monitor 1',
|
||||
type: 'energy',
|
||||
room: 'Conference Room A',
|
||||
status: 'online',
|
||||
lastSeen: Date.now() / 1000,
|
||||
capabilities: {
|
||||
monitoring: ['energy'],
|
||||
actions: []
|
||||
},
|
||||
metadata: {
|
||||
location: 'Wall mounted',
|
||||
model: 'EM-100',
|
||||
firmware: '2.1.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'sensor_2',
|
||||
name: 'HVAC Controller 1',
|
||||
type: 'hvac',
|
||||
room: 'Conference Room A',
|
||||
status: 'online',
|
||||
lastSeen: Date.now() / 1000,
|
||||
capabilities: {
|
||||
monitoring: ['temperature', 'co2'],
|
||||
actions: [
|
||||
{ id: 'temp_adjust', name: 'Adjust Temperature', type: 'adjust', icon: '🌡️', parameters: { min: 18, max: 28, step: 0.5 } },
|
||||
{ id: 'fan_speed', name: 'Fan Speed', type: 'adjust', icon: '💨', parameters: { min: 0, max: 5, step: 1 } },
|
||||
{ id: 'power_toggle', name: 'Power', type: 'toggle', icon: '⚡' }
|
||||
]
|
||||
},
|
||||
metadata: {
|
||||
location: 'Ceiling mounted',
|
||||
model: 'HVAC-200',
|
||||
firmware: '3.2.1'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'sensor_3',
|
||||
name: 'Smart Light Controller',
|
||||
type: 'lighting',
|
||||
room: 'Office Floor 1',
|
||||
status: 'online',
|
||||
lastSeen: Date.now() / 1000,
|
||||
capabilities: {
|
||||
monitoring: ['energy'],
|
||||
actions: [
|
||||
{ id: 'brightness', name: 'Brightness', type: 'adjust', icon: '💡', parameters: { min: 0, max: 100, step: 5 } },
|
||||
{ id: 'power_toggle', name: 'Power', type: 'toggle', icon: '⚡' },
|
||||
{ id: 'scene', name: 'Scene', type: 'adjust', icon: '🎨', parameters: { options: ['Work', 'Meeting', 'Presentation', 'Relax'] } }
|
||||
]
|
||||
},
|
||||
metadata: {
|
||||
location: 'Ceiling grid',
|
||||
model: 'SL-300',
|
||||
firmware: '1.5.2'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'sensor_4',
|
||||
name: 'CO2 Sensor',
|
||||
type: 'co2',
|
||||
room: 'Meeting Room 1',
|
||||
status: 'online',
|
||||
lastSeen: Date.now() / 1000,
|
||||
capabilities: {
|
||||
monitoring: ['co2', 'temperature', 'humidity'],
|
||||
actions: [
|
||||
{ id: 'calibrate', name: 'Calibrate', type: 'trigger', icon: '⚙️' }
|
||||
]
|
||||
},
|
||||
metadata: {
|
||||
location: 'Wall mounted',
|
||||
model: 'CO2-150',
|
||||
firmware: '2.0.3',
|
||||
battery: 85
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'sensor_5',
|
||||
name: 'Security Camera',
|
||||
type: 'security',
|
||||
room: 'Lobby',
|
||||
status: 'online',
|
||||
lastSeen: Date.now() / 1000,
|
||||
capabilities: {
|
||||
monitoring: ['motion'],
|
||||
actions: [
|
||||
{ id: 'record_toggle', name: 'Recording', type: 'toggle', icon: '📹' },
|
||||
{ id: 'ptz_control', name: 'Pan/Tilt/Zoom', type: 'trigger', icon: '🎥' },
|
||||
{ id: 'night_mode', name: 'Night Mode', type: 'toggle', icon: '🌙' }
|
||||
]
|
||||
},
|
||||
metadata: {
|
||||
location: 'Corner ceiling',
|
||||
model: 'SEC-400',
|
||||
firmware: '4.1.0'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
mockSensors.forEach(sensor => {
|
||||
sensorDevices.set(sensor.id, sensor)
|
||||
})
|
||||
}
|
||||
|
||||
// Sensor management functions
|
||||
function updateSensorRoom(sensorId: string, newRoom: string) {
|
||||
const sensor = sensorDevices.get(sensorId)
|
||||
if (sensor) {
|
||||
sensor.room = newRoom
|
||||
sensorDevices.set(sensorId, { ...sensor })
|
||||
}
|
||||
}
|
||||
|
||||
async function executeSensorAction(sensorId: string, actionId: string, parameters?: any) {
|
||||
const sensor = sensorDevices.get(sensorId)
|
||||
if (!sensor) return false
|
||||
|
||||
const action = sensor.capabilities.actions.find(a => a.id === actionId)
|
||||
if (!action) return false
|
||||
|
||||
// Simulate API call to device
|
||||
console.log(`Executing action ${actionId} on sensor ${sensorId}`, parameters)
|
||||
|
||||
// Here you would make the actual API call to control the device
|
||||
// For now, we'll simulate a successful action
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
console.log(`Action ${action.name} executed successfully on ${sensor.name}`)
|
||||
resolve(true)
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
|
||||
function getSensorsByRoom(room: string): SensorDevice[] {
|
||||
return Array.from(sensorDevices.values()).filter(sensor => sensor.room === room)
|
||||
}
|
||||
|
||||
function getSensorsByType(type: SensorDevice['type']): SensorDevice[] {
|
||||
return Array.from(sensorDevices.values()).filter(sensor => sensor.type === type)
|
||||
}
|
||||
|
||||
// Initialize mock sensors on store creation
|
||||
initializeMockSensors()
|
||||
|
||||
return {
|
||||
isConnected,
|
||||
latestMessage,
|
||||
@@ -240,8 +435,14 @@ export const useEnergyStore = defineStore('energy', () => {
|
||||
sensorsData,
|
||||
roomsData,
|
||||
latestReadings,
|
||||
sensorDevices,
|
||||
availableRooms,
|
||||
connect,
|
||||
disconnect,
|
||||
getCO2Status
|
||||
getCO2Status,
|
||||
updateSensorRoom,
|
||||
executeSensorAction,
|
||||
getSensorsByRoom,
|
||||
getSensorsByType
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user