sprinklers3/common/sprinklersRpc/SectionRunner.ts

71 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-10-05 14:31:07 -06:00
import { observable } from "mobx";
import { SprinklersDevice } from "./SprinklersDevice";
export class SectionRun {
2018-09-02 02:57:55 -06:00
readonly sectionRunner: SectionRunner;
readonly id: number;
section: number;
totalDuration: number = 0;
duration: number = 0;
startTime: Date | null = null;
pauseTime: Date | null = null;
unpauseTime: Date | null = null;
constructor(
sectionRunner: SectionRunner,
id: number = 0,
section: number = 0
) {
this.sectionRunner = sectionRunner;
this.id = id;
this.section = section;
}
cancel = () => this.sectionRunner.cancelRunById(this.id);
toString() {
return (
`SectionRun{id=${this.id}, section=${this.section}, duration=${
this.duration
},` + ` startTime=${this.startTime}, pauseTime=${this.pauseTime}}`
);
}
}
export class SectionRunner {
2018-09-02 02:57:55 -06:00
readonly device: SprinklersDevice;
2018-09-02 02:57:55 -06:00
@observable
queue: SectionRun[] = [];
@observable
current: SectionRun | null = null;
@observable
paused: boolean = false;
2018-09-02 02:57:55 -06:00
constructor(device: SprinklersDevice) {
this.device = device;
}
2018-09-02 02:57:55 -06:00
cancelRunById(runId: number) {
return this.device.cancelSectionRunId({ runId });
}
2018-09-02 02:57:55 -06:00
setPaused(paused: boolean) {
return this.device.pauseSectionRunner({ paused });
}
2017-10-10 18:00:01 -06:00
2018-09-02 02:57:55 -06:00
pause() {
return this.setPaused(true);
}
2017-10-10 18:00:01 -06:00
2018-09-02 02:57:55 -06:00
unpause() {
return this.setPaused(false);
}
2017-10-10 18:00:01 -06:00
2018-09-02 02:57:55 -06:00
toString(): string {
return `SectionRunner{queue="${this.queue}", current="${
this.current
}", paused=${this.paused}}`;
}
}