UNPKG

homebridge-smartsystem

Version:

SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)

55 lines (40 loc) 1.1 kB
import { debug, LogLevel, logSettings } from "../duotecno/logger"; import { setSubConfig, getSubConfig, setAPIConfig } from '../duotecno/config'; /////////////// // Log Class // /////////////// export class Base { type: string; debug: boolean; config: any; constructor(type: string, config?) { this.type = type || "base"; if (config) this.config = config; else this.readConfig(); if (this.debug) logSettings[this.type] = LogLevel.debug; else if (logSettings[this.type] == LogLevel.debug) logSettings[this.type] = LogLevel.log; debug("system", "==== read config -> " + JSON.stringify(this.config)) } ////////////////// // Config stuff // ////////////////// readConfig() { this.config = this.read(this.type); this.debug = (!!this.config.debug) || false; } writeConfig() { this.write(this.type, this.config); } read(type: string) { return getSubConfig(type); } write(type: string, config) { setSubConfig(type, config); // but better to much than not enough setAPIConfig(); } }