Skip to content

Commit

Permalink
Make "characteristics" and "publishers" optional
Browse files Browse the repository at this point in the history
The app is functional without either of these
  • Loading branch information
Jalle19 committed Oct 18, 2023
1 parent 558a865 commit e08e52f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { ConsolePublisher, ConsolePublisherImpl } from './publisher/console'
import { Characteristics } from './characteristics'

export interface Config {
characteristics: Characteristics[]
characteristics?: Characteristics[]
circuits: Circuit[]
publishers: Publisher[]
publishers?: Publisher[]
}

export const parseConfig = (configFileContents: string): Config => {
Expand Down Expand Up @@ -116,7 +116,7 @@ export const resolveAndValidateConfig = (config: Config): Config => {
}

// Attach poll function to characteristics sensors
for (const c of config.characteristics) {
for (const c of config?.characteristics ?? []) {
switch (c.sensor.type) {
case CharacteristicsSensorType.Iotawatt:
c.sensor.pollFunc = getIotawattCharacteristicsSensorData
Expand All @@ -129,7 +129,7 @@ export const resolveAndValidateConfig = (config: Config): Config => {

// Create publishers. Ignore any manually defined WebSocket publishers, we only support
// one right now and it's added separately during application startup.
for (const publisher of config.publishers) {
for (const publisher of config?.publishers ?? []) {
switch (publisher.type) {
case PublisherType.InfluxDB: {
const influxDbPublisher = publisher as InfluxDBPublisher
Expand Down

0 comments on commit e08e52f

Please sign in to comment.