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:
rafaeldpsilva
2025-10-01 14:04:25 +01:00
parent a518665673
commit f96456ed29
12 changed files with 189 additions and 76 deletions

View File

@@ -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
}

View File

@@ -131,14 +131,20 @@
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import type { SensorDevice, SensorAction } from '@/services'
interface ActionParameters {
value?: number | string | boolean
[key: string]: unknown
}
const props = defineProps<{
sensor: any
action: any
sensor: SensorDevice
action: SensorAction
}>()
const emit = defineEmits<{
execute: [sensorId: string, actionId: string, parameters: any]
execute: [sensorId: string, actionId: string, parameters: ActionParameters]
close: []
}>()
@@ -182,7 +188,7 @@ const getUnit = () => {
const executeAction = async () => {
isExecuting.value = true
const parameters: any = {}
const parameters: ActionParameters = {}
if (props.action.type === 'adjust') {
if (hasNumericRange.value) {
@@ -195,7 +201,7 @@ const executeAction = async () => {
}
try {
emit('execute', props.sensor.id, props.action.id, parameters)
emit('execute', props.sensor.sensor_id, props.action.id, parameters)
} catch (error) {
console.error('Failed to execute action:', error)
} finally {