Skip to content

Commit

Permalink
Copy some types from the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalle19 committed Nov 13, 2023
1 parent 03d09ac commit a3265ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
37 changes: 37 additions & 0 deletions webif/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion webif/src/routes/Circuits.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { formatPf } from '$lib/format'
import type { PowerSensorData } from '$lib/types'
export let sensorData: any[]
export let sensorData: PowerSensorData[]
</script>

<table class="pure-table pure-table-striped">
Expand Down
3 changes: 2 additions & 1 deletion webif/src/routes/group/[group]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
</script>

Expand Down

0 comments on commit a3265ae

Please sign in to comment.