Skip to content

Commit

Permalink
updates for end time
Browse files Browse the repository at this point in the history
  • Loading branch information
tagyoureit committed Jul 8, 2021
1 parent e2ab8ed commit 026db48
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 216 deletions.
5 changes: 3 additions & 2 deletions controller/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ export class Heliotrope {
export class Timestamp {
private _dt: Date;
public emitter: EventEmitter;
constructor(dt?: Date) {
this._dt = dt || new Date();
constructor(dt?: Date | string) {
if (typeof dt === 'string') this._dt = new Date(dt);
else this._dt = dt || new Date();
this.emitter = new EventEmitter();
}
private _isUpdating: boolean = false;
Expand Down
10 changes: 5 additions & 5 deletions controller/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ export class CircuitGroupState extends EqState implements ICircuitGroupState, IC
if (typeof this.data.endTime === 'undefined') return undefined;
return new Timestamp(this.data.endTime);
}
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate()), false) : this.setDataVal('endTime', undefined); }
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate())) : this.setDataVal('endTime', undefined); }
public get isActive(): boolean { return this.data.isActive; }
public set isActive(val: boolean) { this.setDataVal('isActive', val); }
public get showInFeatures(): boolean { return typeof this.data.showInFeatures === 'undefined' ? true : this.data.showInFeatures; }
Expand Down Expand Up @@ -1170,7 +1170,7 @@ export class LightGroupState extends EqState implements ICircuitGroupState, ICir
if (typeof this.data.endTime === 'undefined') return undefined;
return new Timestamp(this.data.endTime);
}
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate()), false) : this.setDataVal('endTime', undefined); }
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate())) : this.setDataVal('endTime', undefined); }
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 @@ -1412,7 +1412,7 @@ export class FeatureState extends EqState implements ICircuitState {
if (typeof this.data.endTime === 'undefined') return undefined;
return new Timestamp(this.data.endTime);
}
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate()), false) : this.setDataVal('endTime', undefined); }
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate())) : this.setDataVal('endTime', undefined); }
}
export class VirtualCircuitState extends EqState implements ICircuitState {
public dataName: string = 'virtualCircuit';
Expand All @@ -1435,7 +1435,7 @@ export class VirtualCircuitState extends EqState implements ICircuitState {
if (typeof this.data.endTime === 'undefined') return undefined;
return new Timestamp(this.data.endTime);
}
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate()), false) : this.setDataVal('endTime', undefined); }
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate())) : this.setDataVal('endTime', undefined); }
}
export class VirtualCircuitStateCollection extends EqStateCollection<VirtualCircuitState> {
public createItem(data: any): VirtualCircuitState { return new VirtualCircuitState(data); }
Expand Down Expand Up @@ -1513,7 +1513,7 @@ export class CircuitState extends EqState implements ICircuitState {
if (typeof this.data.endTime === 'undefined') return undefined;
return new Timestamp(this.data.endTime);
}
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate()), false) : this.setDataVal('endTime', undefined); }
public set endTime(val: Timestamp) { typeof val !== 'undefined' ? this.setDataVal('endTime', Timestamp.toISOLocal(val.toDate())) : this.setDataVal('endTime', undefined); }
}
export class ValveStateCollection extends EqStateCollection<ValveState> {
public createItem(data: any): ValveState { return new ValveState(data); }
Expand Down
24 changes: 17 additions & 7 deletions controller/boards/EasyTouchBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export class TouchConfigQueue extends ConfigQueue {
action: this.curr.setcategory,
payload: [itm],
retries: 3,
response: Response.create({response: true, callback: () => {self.processNext(out);}})
response: Response.create({ response: true, callback: () => { self.processNext(out); } })
// response: true,
// onResponseProcessed: function () { self.processNext(out); }
});
Expand Down Expand Up @@ -985,7 +985,7 @@ class TouchSystemCommands extends SystemCommands {
if (circ.nameId === data.id + 200) {
let cstate = state.circuits.getItemById(circ.id);
cstate.name = circ.name = data.name;
for (let j = 0; j < state.schedules.length; j++){
for (let j = 0; j < state.schedules.length; j++) {
let ssched = state.schedules.getItemByIndex(j);
if (ssched.circuit === cstate.id) {
ssched.hasChanged = true;
Expand All @@ -999,7 +999,7 @@ class TouchSystemCommands extends SystemCommands {
if (cg.nameId === data.id + 200) {
let cgstate = state.circuitGroups.getItemById(cg.id);
cgstate.name = cg.name = data.name;
for (let j = 0; j < state.schedules.length; j++){
for (let j = 0; j < state.schedules.length; j++) {
let ssched = state.schedules.getItemByIndex(j);
if (ssched.circuit === cgstate.id) {
ssched.hasChanged = true;
Expand All @@ -1013,7 +1013,7 @@ class TouchSystemCommands extends SystemCommands {
if (lg.nameId === data.id + 200) {
let lgstate = state.lightGroups.getItemById(lg.id);
lgstate.name = lg.name = data.name;
for (let j = 0; j < state.schedules.length; j++){
for (let j = 0; j < state.schedules.length; j++) {
let ssched = state.schedules.getItemByIndex(j);
if (ssched.circuit === lgstate.id) {
ssched.hasChanged = true;
Expand All @@ -1027,7 +1027,7 @@ class TouchSystemCommands extends SystemCommands {
if (f.nameId === data.id + 200) {
let fstate = state.features.getItemById(f.id);
fstate.name = f.name = data.name;
for (let j = 0; j < state.schedules.length; j++){
for (let j = 0; j < state.schedules.length; j++) {
let ssched = state.schedules.getItemByIndex(j);
if (ssched.circuit === fstate.id) {
ssched.hasChanged = true;
Expand Down Expand Up @@ -1329,6 +1329,15 @@ export class TouchCircuitCommands extends CircuitCommands {
if (c.master !== 0) return await super.setCircuitStateAsync(id, val);
if (id === 192 || c.type === 3) return await sys.board.circuits.setLightGroupThemeAsync(id - 191, val ? 1 : 0);
if (id >= 192) return await sys.board.circuits.setCircuitGroupStateAsync(id, val);

// for some dumb reason, if the spa is on and the pool circuit is desired to be on,
// it will ignore the packet.
// We can override that by emulating a click to turn off the spa instead of turning
// on the pool
if (sys.equipment.maxBodies > 1 && id === 6 && val && state.circuits.getItemById(1).isOn) {
id = 1;
val = false;
}
return new Promise<ICircuitState>((resolve, reject) => {
let cstate = state.circuits.getInterfaceById(id);
let out = Outbound.create({
Expand All @@ -1349,6 +1358,7 @@ export class TouchCircuitCommands extends CircuitCommands {
});
conn.queueSendMessage(out);
});

}
public async setLightGroupStateAsync(id: number, val: boolean): Promise<ICircuitGroupState> { return this.setCircuitGroupStateAsync(id, val); }
public async toggleCircuitStateAsync(id: number) {
Expand Down Expand Up @@ -1529,7 +1539,7 @@ export class TouchCircuitCommands extends CircuitCommands {
else if (!cstate.isOn && sys.board.valueMaps.lightThemes.getName(theme) !== 'off') await sys.board.circuits.setCircuitStateAsync(c.circuit, true);
}
let isOn = sys.board.valueMaps.lightThemes.getName(theme) === 'off' ? false : true;
sys.board.circuits.setEndTime(grp, sgrp, isOn);
sys.board.circuits.setEndTime(grp, sgrp, isOn);
sgrp.isOn = isOn;
switch (theme) {
case 0: // off
Expand Down Expand Up @@ -2336,7 +2346,7 @@ class TouchChemControllerCommands extends ChemControllerCommands {
action: 211,
payload: [],
retries: 3, // We are going to try 4 times.
response: Response.create({ protocol: Protocol.IntelliChem, action: 1, payload:[211] }),
response: Response.create({ protocol: Protocol.IntelliChem, action: 1, payload: [211] }),
onAbort: () => { },
onComplete: (err) => {
if (err) reject(err);
Expand Down
Loading

0 comments on commit 026db48

Please sign in to comment.