Skip to content

Commit

Permalink
Add DummySensor, helps implementing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalle19 committed Oct 19, 2023
1 parent 3c84379 commit eeaf7f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from './iotawatt'
import { getSensorData as getVirtualSensorData } from './virtual'
import { getSensorData as getUnmeteredSensorData } from './unmetered'
import { getSensorData as getDummySensorData } from './dummy'
import {
CharacteristicsSensorType,
SensorType,
Expand Down Expand Up @@ -118,6 +119,9 @@ export const resolveAndValidateConfig = (config: Config): Config => {
case SensorType.Unmetered:
circuit.sensor.pollFunc = getUnmeteredSensorData
break
case SensorType.Dummy:
circuit.sensor.pollFunc = getDummySensorData
break
default:
throw new Error(`Unrecognized sensor type ${circuit.sensor.type}`)
}
Expand Down
11 changes: 11 additions & 0 deletions src/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { emptySensorData, PowerSensorData, PowerSensorPollFunction } from './sensor'
import { Circuit } from './circuit'

export const getSensorData: PowerSensorPollFunction = async (
timestamp: number,
circuit: Circuit,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
existingSensorData?: PowerSensorData[],
): Promise<PowerSensorData> => {
return emptySensorData(timestamp, circuit)
}
1 change: 1 addition & 0 deletions src/sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum SensorType {
Shelly = 'shelly',
Virtual = 'virtual',
Unmetered = 'unmetered',
Dummy = 'dummy',
}

export enum ShellyType {
Expand Down

0 comments on commit eeaf7f6

Please sign in to comment.