From a3265ae3216b0adf1e77283a02ec9c07b5dd8e64 Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Mon, 13 Nov 2023 13:27:59 +0200 Subject: [PATCH] Copy some types from the backend --- webif/src/lib/types.ts | 37 +++++++++++++++++++++ webif/src/routes/Circuits.svelte | 3 +- webif/src/routes/group/[group]/+page.svelte | 3 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 webif/src/lib/types.ts diff --git a/webif/src/lib/types.ts b/webif/src/lib/types.ts new file mode 100644 index 0000000..88e1089 --- /dev/null +++ b/webif/src/lib/types.ts @@ -0,0 +1,37 @@ +export enum SensorType { + Iotawatt = 'iotawatt', + Shelly = 'shelly', + Virtual = 'virtual', + Unmetered = 'unmetered', + Dummy = 'dummy', +} + +export interface PowerSensor { + type: SensorType +} + +export enum CircuitType { + Main = 'main', + Circuit = 'circuit', +} + +export type Circuit = { + name: string + type: CircuitType // resolved during parsing + parent?: Circuit // resolved to the circuit in question + children: Circuit[] // resolved from parent + phase?: string // resolved from parent + hidden?: boolean // defaults to false + sensor: PowerSensor + group?: string +} + +export type PowerSensorData = { + timestamp: number + circuit: Circuit + // Mandatory data. Undefined means the data was not available. + power?: number + // Optional data, not all sensor types support them + apparentPower?: number + powerFactor?: number +} diff --git a/webif/src/routes/Circuits.svelte b/webif/src/routes/Circuits.svelte index 3cc7b29..bdb69ba 100644 --- a/webif/src/routes/Circuits.svelte +++ b/webif/src/routes/Circuits.svelte @@ -1,7 +1,8 @@ diff --git a/webif/src/routes/group/[group]/+page.svelte b/webif/src/routes/group/[group]/+page.svelte index ede811b..3ac4935 100644 --- a/webif/src/routes/group/[group]/+page.svelte +++ b/webif/src/routes/group/[group]/+page.svelte @@ -3,12 +3,13 @@ import { circuitSensorDataStore } from '$lib/stores' import Circuits from '../../Circuits.svelte' import { derived } from 'svelte/store' + import type { PowerSensorData } from '$lib/types' // Create a derived store containing the sensor data for just the circuits belonging // to the current group const group = $page.params?.group let groupSensorData = derived(circuitSensorDataStore, (data) => { - return data.filter((data: any) => data.circuit.group === group) + return data.filter((data: PowerSensorData) => data.circuit.group === group) })