forked from tagyoureit/nodejs-poolController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor interfaces; add influxdb interface; rstrouse/nodejs-poolController-dashPanel#7; add watch on config.json
- Loading branch information
1 parent
706909e
commit 9cd427a
Showing
13 changed files
with
998 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
const extend = require("extend"); | ||
|
@@ -22,15 +22,31 @@ class Config { | |
private cfgPath: string; | ||
private _cfg: any; | ||
private _isInitialized: boolean=false; | ||
private _fileTime: Date = new Date(0); | ||
private _isLoading: boolean = false; | ||
constructor() { | ||
let self=this; | ||
this.cfgPath = path.posix.join(process.cwd(), "/config.json"); | ||
// RKS 05-18-20: This originally had multiple points of failure where it was not in the try/catch. | ||
try { | ||
this._isLoading = true; | ||
this._cfg = fs.existsSync(this.cfgPath) ? JSON.parse(fs.readFileSync(this.cfgPath, "utf8")) : {}; | ||
const def = JSON.parse(fs.readFileSync(path.join(process.cwd(), "/defaultConfig.json"), "utf8").trim()); | ||
const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), "/package.json"), "utf8").trim()); | ||
this._cfg = extend(true, {}, def, this._cfg, { appVersion: packageJson.version }); | ||
this._isInitialized = true; | ||
fs.watch(this.cfgPath, (event, fileName) => { | ||
if (fileName && event === 'change') { | ||
if (self._isLoading) return; // Need a debounce here. We will use a semaphore to cause it not to load more than once. | ||
const stats = fs.statSync(self.cfgPath); | ||
if (stats.mtime.valueOf() === self._fileTime.valueOf()) return; | ||
this._cfg = fs.existsSync(this.cfgPath) ? JSON.parse(fs.readFileSync(this.cfgPath, "utf8")) : {}; | ||
this._cfg = extend(true, {}, def, this._cfg, { appVersion: packageJson.version }); | ||
logger.init(); // only reload logger for now; possibly expand to other areas of app | ||
logger.info(`Reloading app config: ${fileName}`); | ||
} | ||
}); | ||
this._isLoading = false; | ||
} catch (err) { | ||
console.log(`Error reading configuration information. Aborting startup: ${ err }`); | ||
// Rethrow this error so we exit the app with the appropriate pause in the console. | ||
|
@@ -41,10 +57,12 @@ class Config { | |
// Don't overwrite the configuration if we failed during the initialization. | ||
try { | ||
if (!this._isInitialized) return; | ||
this._isLoading = true; | ||
fs.writeFileSync( | ||
this.cfgPath, | ||
JSON.stringify(this._cfg, undefined, 2) | ||
); | ||
setTimeout(()=>{this._isLoading = false;}, 2000); | ||
} | ||
catch (err) { | ||
logger.error("Error writing configuration file %s", err); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as extend from 'extend'; | ||
|
@@ -1008,7 +1008,7 @@ export class VirtualCircuitStateCollection extends EqStateCollection<VirtualCirc | |
} | ||
export class CircuitStateCollection extends EqStateCollection<CircuitState> { | ||
public createItem(data: any): CircuitState { return new CircuitState(data); } | ||
public setCircuitState(id: number, val: boolean) { return sys.board.circuits.setCircuitStateAsync(id, val); } | ||
public setCircuitStateAsync(id: number, val: boolean):Promise<ICircuitState> { return sys.board.circuits.setCircuitStateAsync(id, val); } | ||
public async toggleCircuitStateAsync(id: number) { return sys.board.circuits.toggleCircuitStateAsync(id); } | ||
public async setLightThemeAsync(id: number, theme: number) { return sys.board.circuits.setLightThemeAsync(id, theme); } | ||
public getInterfaceById(id: number, add?: boolean): ICircuitState { | ||
|
@@ -1301,7 +1301,7 @@ export class ChemControllerState extends EqState { | |
let chem = sys.chemControllers.getItemById(this.id); | ||
let obj = this.get(true); | ||
obj.saturationIndex = this.saturationIndex || 0; | ||
obj.alkalinty = chem.alkalinity; | ||
obj.alkalinity = chem.alkalinity; | ||
obj.body = sys.board.valueMaps.bodies.transform(chem.body); | ||
obj.calciumHardness = chem.calciumHardness; | ||
obj.cyanuricAcid = chem.cyanuricAcid; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
/* nodejs-poolController. An application to control pool equipment. | ||
Copyright (C) 2016, 2017. Russell Goldin, tagyoureit. [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as winston from 'winston'; | ||
|
@@ -30,7 +30,6 @@ class Logger { | |
this.pktPath = path.join(process.cwd(), '/logs', this.getPacketPath()); | ||
this.captureForReplayBaseDir = path.join(process.cwd(), '/logs/', this.getLogTimestamp()); | ||
/* this.captureForReplayPath = path.join(this.captureForReplayBaseDir, '/packetCapture.json'); */ | ||
this.cfg = config.getSection('log'); | ||
this.pkts = []; | ||
} | ||
private cfg; | ||
|
@@ -61,6 +60,7 @@ class Logger { | |
|
||
private _logger: winston.Logger; | ||
public init() { | ||
this.cfg = config.getSection('log'); | ||
logger._logger = winston.createLogger({ | ||
format: winston.format.combine(winston.format.colorize(), winston.format.splat(), winston.format.simple()), | ||
transports: [this.transports.console] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.