Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor interfaces;
add influxdb interface;
rstrouse/nodejs-poolController-dashPanel#7;
add watch on config.json
  • Loading branch information
tagyoureit committed Sep 17, 2020
1 parent 706909e commit 9cd427a
Show file tree
Hide file tree
Showing 13 changed files with 998 additions and 193 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,26 @@ Ready for 6.0;
* [Vera Home Automation Hub](https://github.com/rstrouse/nodejs-poolController-veraPlugin) - A plugin that integrates with nodejs-poolController.
* [SmartThings/Hubitat](https://github.com/bsileo/hubitat_poolcontroller) by @bsileo (prev help from @johnny2678, @donkarnag, @arrmo)
* [Homebridge/Siri/EVE](https://github.com/gadget-monk/homebridge-poolcontroller) by @gadget-monk, adopted from @leftyflip
* InfluxDB

Need to be updated:
* [Another SmartThings Controller](https://github.com/dhop90/pentair-pool-controller/blob/master/README.md) by @dhop90
* [ISY](src/integrations/socketISY.js). Original credit to @blueman2, enhancements by @mayermd
* [ISY Polyglot NodeServer](https://github.com/brianmtreese/nodejs-pool-controller-polyglotv2) created by @brianmtreese
* [MQTT](https://github.com/crsherman/nodejs-poolController-mqtt) created by @crsherman.
* InfluxDB

# Support
1. For discussions, recommendations, designs, and clarifications, we recommend you join our [Gitter Chat room](https://gitter.im/pentair_pool/Lobby).
1. Check the [wiki](https://github.com/tagyoureit/nodejs-poolController/wiki) for tips, tricks and additional documentation.
1. For bug reports you can open a [github issue](https://github.com/tagyoureit/nodejs-poolController/issues/new),



### Virtual Controller
v6 adds all new configuration and support for virtual pumps, chlorinators (and soon, Intellichem)

* [Virtual Pump Directions](https://github.com/tagyoureit/nodejs-poolController/wiki/Virtual-Pump-Controller---v6)
* [Virtual Chlorinator Directions](https://github.com/tagyoureit/nodejs-poolController/wiki/Virtual-Chlorinator-Controller-v6)



# Changed/dropped since 5.3
1. Ability to load different config.json files
1. Automatic upgrade of config.json files (tbd)
Expand Down
50 changes: 34 additions & 16 deletions config/Config.ts
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");
Expand All @@ -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.
Expand All @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions controller/State.ts
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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions controller/boards/EasyTouchBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ class TouchCircuitCommands extends CircuitCommands {
sys.board.virtualPumpControllers.start();
// sys.board.virtualPumpControllers.setTargetSpeed();
state.emitEquipmentChanges();
resolve(cstate.get(true));
resolve(cstate);
}
}
});
Expand All @@ -883,6 +883,9 @@ class TouchCircuitCommands extends CircuitCommands {
public async setLightGroupStateAsync(id: number, val: boolean): Promise<ICircuitGroupState> { return this.setCircuitGroupStateAsync(id, val); }
public async toggleCircuitStateAsync(id: number) {
let cstate = state.circuits.getInterfaceById(id);
if (cstate instanceof LightGroupState) {
return this.setLightGroupThemeAsync(id, sys.board.valueMaps.lightThemes.getValue(cstate.isOn?'off':'on'));
}
return this.setCircuitStateAsync(id, !cstate.isOn);
}
private createLightGroupMessages(group: LightGroup) {
Expand Down Expand Up @@ -1044,17 +1047,16 @@ class TouchCircuitCommands extends CircuitCommands {
if (err) reject(err);
else {
try {
/* for (let i = 0; i < sys.intellibrite.circuits.length; i++) {
let c = sys.intellibrite.circuits.getItemByIndex(i);
let cstate = state.circuits.getItemById(c.circuit);
if (!cstate.isOn) await sys.board.circuits.setCircuitStateAsync(c.circuit, true);
} */
// Let everyone know we turned these on. The theme messages will come later.
for (let i = 0; i < grp.circuits.length; i++) {
let c = grp.circuits.getItemByIndex(i);
let cstate = state.circuits.getItemById(c.circuit);
if (!cstate.isOn) await sys.board.circuits.setCircuitStateAsync(c.circuit, true);
// if theme is 'off' light groups should not turn on
if (cstate.isOn && sys.board.valueMaps.lightThemes.getName(theme) === 'off')
await sys.board.circuits.setCircuitStateAsync(c.circuit, false);
else if (!cstate.isOn && sys.board.valueMaps.lightThemes.getName(theme) !== 'off') await sys.board.circuits.setCircuitStateAsync(c.circuit, true);
}
sgrp.isOn = sys.board.valueMaps.lightThemes.getName(theme) === 'off' ? false: true;
switch (theme) {
case 0: // off
case 1: // on
Expand Down
2 changes: 1 addition & 1 deletion controller/boards/SystemBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ export class CircuitCommands extends BoardCommands {
}
state.emitEquipmentChanges();
sys.board.virtualPumpControllers.start();
return Promise.resolve(circ);
return Promise.resolve(state.circuits.getInterfaceById(circ.id));
}

public toggleCircuitStateAsync(id: number): Promise<ICircuitState> {
Expand Down
34 changes: 17 additions & 17 deletions logger/Logger.ts
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';
Expand All @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs-poolcontroller",
"version": "6.0.0",
"version": "6.0.1",
"description": "nodejs-poolController",
"main": "app.js",
"author": {
Expand Down
Loading

0 comments on commit 9cd427a

Please sign in to comment.