Skip to content

Commit

Permalink
add covers to config object;
Browse files Browse the repository at this point in the history
remove eggtimers from config for CG & LG;
change 'throw new' to 'return promise.reject';
add {val:0} if transform did not recieve a val;
implement https (no auth yet);
fix for using sys/state/webapp in interfaces;
rename intellichemwaterflow to chemcontrollerwaterflow
  • Loading branch information
tagyoureit committed Sep 17, 2020
1 parent 0c5daf6 commit 0344670
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 145 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ config.json
data/
poolConfig.json
poolState.json
*.crt
*.key
users.htpasswd
# ignore visual studio
*.csproj
*.njsproj
Expand All @@ -32,3 +35,4 @@ bin/
.vs/
.vscode/
# end

2 changes: 1 addition & 1 deletion controller/Equipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export class PoolSystem implements IPoolSystem {
this.schedules.clear();
this.security.clear();
this.valves.clear();
this.covers.clear();
this.chemControllers.clear();
//if (typeof this.data.intelliBrite !== 'undefined') this.intellibrite.clear();
if (typeof this.data.eggTimers !== 'undefined') this.eggTimers.clear();
Expand Down Expand Up @@ -300,6 +299,7 @@ export class PoolSystem implements IPoolSystem {
chlorinators: self.data.chlorinators || [],
remotes: self.data.remotes || [],
heaters: self.data.heaters || [],
covers: self.data.covers || [],
appVersion: self.data.appVersion || '0.0.0'
};
}
Expand Down
12 changes: 6 additions & 6 deletions controller/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ export interface ICircuitGroupState {
type: number;
name: string;
nameId?: number;
eggTimer: number;
// eggTimer: number;
isOn: boolean;
isActive: boolean;
dataName: string;
Expand Down Expand Up @@ -775,8 +775,8 @@ export class CircuitGroupState extends EqState implements ICircuitGroupState, IC
this.hasChanged = true;
}
}
public get eggTimer(): number { return this.data.eggTimer; }
public set eggTimer(val: number) { this.setDataVal('eggTimer', val); }
// public get eggTimer(): number { return this.data.eggTimer; }
// public set eggTimer(val: number) { this.setDataVal('eggTimer', val); }
public get isOn(): boolean { return this.data.isOn; }
public set isOn(val: boolean) { this.setDataVal('isOn', val); }
public get isActive(): boolean { return this.data.isActive; }
Expand Down Expand Up @@ -830,8 +830,8 @@ export class LightGroupState extends EqState implements ICircuitGroupState, ICir
this.hasChanged = true;
}
}
public get eggTimer(): number { return this.data.eggTimer; }
public set eggTimer(val: number) { this.setDataVal('eggTimer', val); }
// public get eggTimer(): number { return this.data.eggTimer; }
// public set eggTimer(val: number) { this.setDataVal('eggTimer', val); }
public get isOn(): boolean { return this.data.isOn; }
public set isOn(val: boolean) { this.setDataVal('isOn', val); }
public get isActive(): boolean { return this.data.isActive; }
Expand Down Expand Up @@ -1247,7 +1247,7 @@ export class ChemControllerState extends EqState {
public get waterFlow(): number { return this.data.waterFlow; }
public set waterFlow(val: number) {
if (this.waterFlow !== val) {
this.data.waterFlow = sys.board.valueMaps.intelliChemWaterFlow.transform(val);
this.data.waterFlow = sys.board.valueMaps.chemControllerWaterFlow.transform(val);
this.hasChanged = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions controller/boards/EasyTouchBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ class TouchCircuitCommands extends CircuitCommands {
// We are adding a circuit group.
id = sys.circuitGroups.getNextEquipmentId(sys.board.equipmentIds.circuitGroups);
}
if (typeof id === 'undefined') throw new InvalidEquipmentIdError(`Max circuit light group id exceeded`, id, 'LightGroup');
if (isNaN(id) || !sys.board.equipmentIds.circuitGroups.isInRange(id)) throw new InvalidEquipmentIdError(`Invalid circuit group id: ${obj.id}`, obj.id, 'LightGroup');
if (typeof id === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Max circuit light group id exceeded`, id, 'LightGroup'));
if (isNaN(id) || !sys.board.equipmentIds.circuitGroups.isInRange(id)) return Promise.reject(new InvalidEquipmentIdError(`Invalid circuit group id: ${obj.id}`, obj.id, 'LightGroup'));
group = sys.lightGroups.getItemById(id, true);

if (typeof obj.name !== 'undefined') group.name = obj.name;
Expand Down
25 changes: 13 additions & 12 deletions controller/boards/IntelliCenterBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { conn } from '../comms/Comms';
import { logger } from '../../logger/Logger';
import { state, ChlorinatorState, LightGroupState, VirtualCircuitState, ICircuitState, BodyTempState, CircuitGroupState, ICircuitGroupState } from '../State';
import { utils } from '../../controller/Constants';
import { InvalidEquipmentIdError, InvalidEquipmentDataError } from '../Errors';
import { InvalidEquipmentIdError, InvalidEquipmentDataError, EquipmentNotFoundError } from '../Errors';
export class IntelliCenterBoard extends SystemBoard {
public needsConfigChanges: boolean = false;
constructor(system: PoolSystem) {
Expand Down Expand Up @@ -737,7 +737,7 @@ class IntelliCenterSystemCommands extends SystemCommands {
payload: [12, 0, 0],
retries: 1,
onComplete: (err, msg) => {
if (err) throw new Error(err);
if (err) return Promise.reject(new Error(err));
else { sys.general.alias = obj.alias; resolve(); }
}
}).appendPayloadString(obj.alias, 16);
Expand Down Expand Up @@ -1210,8 +1210,8 @@ class IntelliCenterCircuitCommands extends CircuitCommands {
return new Promise<ICircuit>((resolve, reject) => {
let id = parseInt(data.id, 10);
let circuit = sys.circuits.getItemById(id, false);
if (isNaN(id)) throw new InvalidEquipmentIdError('Circuit Id has not been defined', data.id, 'Circuit');
if (!sys.board.equipmentIds.circuits.isInRange(id)) throw new InvalidEquipmentIdError(`Circuit Id ${id}: is out of range.`, id, 'Circuit');
if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError('Circuit Id has not been defined', data.id, 'Circuit'));
if (!sys.board.equipmentIds.circuits.isInRange(id)) return Promise.reject(new InvalidEquipmentIdError(`Circuit Id ${id}: is out of range.`, id, 'Circuit'));
let eggTimer = Math.min(typeof data.eggTimer !== 'undefined' ? parseInt(data.eggTimer, 10) : circuit.eggTimer, 1440);
if (isNaN(eggTimer)) eggTimer = circuit.eggTimer;
let eggHrs = Math.floor(eggTimer / 60);
Expand Down Expand Up @@ -1284,7 +1284,8 @@ class IntelliCenterCircuitCommands extends CircuitCommands {
onComplete: (err, msg) => {
if (err) reject(err);
else {
sgroup.eggTimer = group.eggTimer = eggTimer;
// sgroup.eggTimer = group.eggTimer = eggTimer;
group.eggTimer = eggTimer;
sgroup.type = group.type = 2;
if (typeof obj.circuits !== 'undefined') {
for (let i = 0; i < obj.circuits.length; i++) {
Expand Down Expand Up @@ -1353,7 +1354,7 @@ class IntelliCenterCircuitCommands extends CircuitCommands {
public async deleteCircuitGroupAsync(obj: any): Promise<CircuitGroup> {
let group: CircuitGroup = null;
let id = parseInt(obj.id, 10);
if (isNaN(id) || !sys.board.equipmentIds.circuitGroups.isInRange(id)) Promise.reject(new Error(`Invalid circuit group id: ${obj.id}`));
if (isNaN(id) || !sys.board.equipmentIds.circuitGroups.isInRange(id)) return Promise.reject(new EquipmentNotFoundError(`Invalid group id: ${obj.id}`, 'CircuitGroup'));
group = sys.circuitGroups.getItemById(id);
try {
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1433,7 +1434,7 @@ class IntelliCenterCircuitCommands extends CircuitCommands {
else {
group = sys.lightGroups.getItemById(id, false);
}
if (typeof id === 'undefined') throw new Error(`Max light group ids exceeded`);
if (typeof id === 'undefined') return Promise.reject(new Error(`Max light group ids exceeded`));
if (isNaN(id) || !sys.board.equipmentIds.circuitGroups.isInRange(id)) return Promise.reject(new Error(`Invalid light group id: ${obj.id}`));
try {
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1976,8 +1977,8 @@ class IntelliCenterFeatureCommands extends FeatureCommands {
}
else
feature = sys.features.getItemById(id, false);
if (isNaN(id)) throw new InvalidEquipmentIdError('feature Id has not been defined', data.id, 'Feature');
if (!sys.board.equipmentIds.features.isInRange(id)) throw new InvalidEquipmentIdError(`feature Id ${id}: is out of range.`, id, 'Feature');
if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError('feature Id has not been defined', data.id, 'Feature'));
if (!sys.board.equipmentIds.features.isInRange(id)) return Promise.reject(new InvalidEquipmentIdError(`feature Id ${id}: is out of range.`, id, 'Feature'));
let eggTimer = Math.min(typeof data.eggTimer !== 'undefined' ? parseInt(data.eggTimer, 10) : feature.eggTimer, 1440);
if (isNaN(eggTimer)) eggTimer = feature.eggTimer;
let eggHrs = Math.floor(eggTimer / 60);
Expand Down Expand Up @@ -2014,7 +2015,7 @@ class IntelliCenterFeatureCommands extends FeatureCommands {
public async deleteFeatureAsync(data: any): Promise<Feature> {
return new Promise<Feature>((resolve, reject) => {
let id = parseInt(data.id, 10);
if (isNaN(id)) throw new InvalidEquipmentIdError('feature Id has not been defined', data.id, 'Feature');
if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError('feature Id has not been defined', data.id, 'Feature'));
let feature = sys.features.getItemById(id, false);
let out = Outbound.create({
action: 168,
Expand Down Expand Up @@ -2409,7 +2410,7 @@ class IntelliCenterPumpCommands extends PumpCommands {
// We now need to get the type for the pump. If the incoming data doesn't include it then we need to
// get it from the current pump configuration.
let pump = sys.pumps.getItemById(id, false);
if (typeof pump.type === 'undefined') return Promise.reject(new Error(`Pump #${data.id} does not exist in configuration`));
if (typeof pump.type === 'undefined') return Promise.reject(new InvalidEquipmentIdError(`Pump #${data.id} does not exist in configuration`, data.id, 'Schedule'));
let outc = Outbound.create({ action: 168, payload: [4, 0, id - 1, 0, 0, id + 95] });
outc.appendPayloadInt(450); // 6
outc.appendPayloadInt(3450); // 8
Expand Down Expand Up @@ -2461,7 +2462,7 @@ class IntelliCenterBodyCommands extends BodyCommands {
let arr = [];
let byte = 0;
let id = parseInt(obj.id, 10);
if (isNaN(id)) throw new InvalidEquipmentIdError('Body Id is not defined', obj.id, 'Body');
if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError('Body Id is not defined', obj.id, 'Body'));
let body = sys.bodies.getItemById(id, false);
switch (body.id) {
case 1:
Expand Down
Loading

0 comments on commit 0344670

Please sign in to comment.