diff --git a/src/config.ts b/src/config.ts index 69807fe..a2f5720 100644 --- a/src/config.ts +++ b/src/config.ts @@ -30,8 +30,10 @@ export interface Config { } export const parseConfig = (configFileContents: string): Config => { - const config = YAML.parse(configFileContents) as Config + return YAML.parse(configFileContents) as Config +} +export const resolveAndValidateConfig = (config: Config): Config => { // Set various defaults for (const circuit of config.circuits) { // Use Circuit as default circuit type diff --git a/src/eachwatt.ts b/src/eachwatt.ts index 55c5f17..28718a7 100644 --- a/src/eachwatt.ts +++ b/src/eachwatt.ts @@ -1,7 +1,7 @@ import http from 'http' import yargs from 'yargs' import fs from 'fs' -import { Config, parseConfig } from './config' +import { Config, parseConfig, resolveAndValidateConfig } from './config' import { SensorType } from './sensor' import { pollPowerSensors } from './circuit' import { httpRequestHandler } from './http/server' @@ -71,7 +71,8 @@ const mainPollerFunc = async (config: Config) => { } const configFileContents = fs.readFileSync(configFile, 'utf8') - const config = parseConfig(configFileContents) + const rawConfig = parseConfig(configFileContents) + const config = resolveAndValidateConfig(rawConfig) // Create and start HTTP server const httpServer = http.createServer(httpRequestHandler)