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