sprinklers3/common/sprinklers/SectionRunner.ts

57 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 {
readonly sectionRunner: SectionRunner;
2017-10-05 09:07:07 -06:00
readonly id: number;
section: number;
2017-10-10 16:34:02 -06:00
duration: number = 0;
startTime: Date | null = null;
pauseTime: Date | null = null;
constructor(sectionRunner: SectionRunner, id: number = 0, section: number = 0) {
this.sectionRunner = sectionRunner;
this.id = id;
this.section = section;
}
2017-10-10 18:00:01 -06:00
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 {
2017-10-05 09:07:07 -06:00
readonly device: SprinklersDevice;
2017-10-05 09:07:07 -06:00
@observable queue: SectionRun[] = [];
@observable current: SectionRun | null = null;
@observable paused: boolean = false;
constructor(device: SprinklersDevice) {
this.device = device;
}
cancelRunById(runId: number) {
return this.device.cancelSectionRunId({ runId });
}
2017-10-10 18:00:01 -06:00
setPaused(paused: boolean) {
return this.device.pauseSectionRunner({ paused });
}
pause() {
return this.setPaused(true);
}
unpause() {
return this.setPaused(false);
}
toString(): string {
return `SectionRunner{queue="${this.queue}", current="${this.current}", paused=${this.paused}}`;
}
}