Refactor SimpleSensorCard to use typed sensor props and clean up energy
reading logic
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="font-medium text-gray-900 text-sm">{{ sensor.name }}</h3>
|
||||
<p class="text-xs text-gray-500">{{ sensor.room || 'Unassigned' }}</p>
|
||||
<p class="text-xs text-gray-500">{{ sensor.sensor_id || 'Unknown' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Status Indicator -->
|
||||
@@ -72,38 +72,34 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useEnergyStore } from '@/stores/energy'
|
||||
import { useSensorStore } from '@/stores/sensor'
|
||||
import type { SensorAction, SensorDevice } from '@/services'
|
||||
|
||||
const props = defineProps<{
|
||||
sensor: any
|
||||
sensor: SensorDevice
|
||||
isExecutingAction?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
executeAction: [sensor: any, action: any]
|
||||
showMore: [sensor: any]
|
||||
executeAction: [sensor: SensorDevice, action: SensorAction]
|
||||
showMore: [sensor: SensorDevice]
|
||||
}>()
|
||||
|
||||
const energyStore = useEnergyStore()
|
||||
const sensorStore = useSensorStore()
|
||||
|
||||
const getSensorValues = (sensor: any) => {
|
||||
const getSensorValues = (sensor: SensorDevice) => {
|
||||
const values = []
|
||||
|
||||
const latestReading = energyStore.latestReadings.get(sensor.sensor_id)
|
||||
const latestReading = sensorStore.latestReadings.get(sensor.sensor_id)
|
||||
|
||||
// Only show energy if the sensor actually monitors energy
|
||||
if (sensor.capabilities?.monitoring?.includes('energy')) {
|
||||
const energyValue =
|
||||
latestReading?.energy?.value?.toFixed(2) ||
|
||||
energyStore.latestMessage?.value?.toFixed(2) ||
|
||||
'0.00'
|
||||
const energyValue = latestReading?.energy?.value?.toFixed(2) || '0.00'
|
||||
values.push({
|
||||
type: 'energy',
|
||||
label: 'Energy',
|
||||
value: energyValue,
|
||||
unit: latestReading?.energy?.unit || energyStore.latestMessage?.unit || 'kWh',
|
||||
unit: latestReading?.energy?.unit || 'kWh',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -214,10 +210,7 @@ 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 getSensorTypeIcon = (type: string) => {
|
||||
|
||||
Reference in New Issue
Block a user