Refactor sensor ID usage and types, add CO2 metrics, update docs
- Standardize on `sensor.sensor_id` throughout components and stores - Add average and max CO2 metrics to sensor store and HomeView - Improve type safety for sensors, actions, and API calls - Update AGENTS.md with repository guidelines - Refine settings store types and utility functions - Add WindowWithAuth interface for auth store access - Minor bug fixes and code cleanup
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="font-medium text-gray-900">{{ sensor.name }}</h3>
|
||||
<p class="text-sm text-gray-500">{{ sensor.id }}</p>
|
||||
<p class="text-sm text-gray-500">{{ sensor.sensor_id }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
@@ -30,9 +30,9 @@
|
||||
<!-- Room Assignment -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Room Assignment</label>
|
||||
<select
|
||||
:value="sensor.room"
|
||||
@change="$emit('updateRoom', sensor.id, ($event.target as HTMLSelectElement).value)"
|
||||
<select
|
||||
:value="sensor.room"
|
||||
@change="$emit('updateRoom', sensor.sensor_id, ($event.target as HTMLSelectElement).value)"
|
||||
class="w-full px-3 py-2 border border-gray-200 rounded-lg bg-white text-sm"
|
||||
>
|
||||
<option value="">Unassigned</option>
|
||||
@@ -100,7 +100,7 @@
|
||||
<span class="font-medium">Location:</span>
|
||||
<div>{{ sensor.metadata.location }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div v-if="sensor.lastSeen">
|
||||
<span class="font-medium">Last Seen:</span>
|
||||
<div>{{ formatTime(sensor.lastSeen) }}</div>
|
||||
</div>
|
||||
@@ -166,26 +166,27 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useSensorStore } from '@/stores/sensor'
|
||||
import type { SensorDevice, SensorAction } from '@/services'
|
||||
|
||||
const props = defineProps<{
|
||||
sensor: any
|
||||
sensor: SensorDevice
|
||||
availableRooms: string[]
|
||||
isExecutingAction?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
updateRoom: [sensorId: string, newRoom: string]
|
||||
executeAction: [sensor: any, action: any]
|
||||
executeAction: [sensor: SensorDevice, action: SensorAction]
|
||||
}>()
|
||||
|
||||
const sensorStore = useSensorStore()
|
||||
|
||||
const getSensorValues = (sensor: any) => {
|
||||
const getSensorValues = (sensor: SensorDevice) => {
|
||||
const values = []
|
||||
|
||||
// Get real-time sensor reading from store
|
||||
const latestReading = sensorStore.latestReadings.get(sensor.id) || sensorStore.latestReadings.get(sensor.sensor_id)
|
||||
console.log(`[Detailed] Getting values for sensor ${sensor.id}, found reading:`, latestReading)
|
||||
const latestReading = sensorStore.latestReadings.get(sensor.sensor_id)
|
||||
console.log(`[Detailed] Getting values for sensor ${sensor.sensor_id}, found reading:`, latestReading)
|
||||
console.log('[Detailed] Available readings:', Array.from(sensorStore.latestReadings.keys()))
|
||||
console.log(`[Detailed] Sensor capabilities:`, sensor.capabilities?.monitoring)
|
||||
|
||||
@@ -315,25 +316,24 @@ const sensorValues = computed(() => getSensorValues(props.sensor))
|
||||
|
||||
// Check if sensor was recently updated for pulsing animation
|
||||
const isRecentlyUpdated = computed(() => {
|
||||
return sensorStore.recentlyUpdatedSensors.has(props.sensor.id) ||
|
||||
sensorStore.recentlyUpdatedSensors.has(props.sensor.sensor_id)
|
||||
return sensorStore.recentlyUpdatedSensors.has(props.sensor.sensor_id)
|
||||
})
|
||||
|
||||
const getDefaultTags = (sensor: any) => {
|
||||
const tags = [sensor.type]
|
||||
|
||||
if (sensor.metadata.battery) {
|
||||
const getDefaultTags = (sensor: SensorDevice): string[] => {
|
||||
const tags: string[] = [sensor.type]
|
||||
|
||||
if (sensor.metadata?.battery) {
|
||||
tags.push('wireless')
|
||||
} else {
|
||||
tags.push('wired')
|
||||
}
|
||||
|
||||
|
||||
if (sensor.capabilities.actions.length > 0) {
|
||||
tags.push('controllable')
|
||||
} else {
|
||||
tags.push('monitor-only')
|
||||
}
|
||||
|
||||
|
||||
return tags
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user