You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
7 years ago
|
import { observable } from "mobx";
|
||
7 years ago
|
import { SprinklersDevice } from "./SprinklersDevice";
|
||
|
|
||
|
export class SectionRun {
|
||
7 years ago
|
readonly sectionRunner: SectionRunner;
|
||
7 years ago
|
readonly id: number;
|
||
7 years ago
|
section: number;
|
||
7 years ago
|
totalDuration: number = 0;
|
||
7 years ago
|
duration: number = 0;
|
||
7 years ago
|
startTime: Date | null = null;
|
||
|
pauseTime: Date | null = null;
|
||
7 years ago
|
unpauseTime: Date | null = null;
|
||
7 years ago
|
|
||
7 years ago
|
constructor(sectionRunner: SectionRunner, id: number = 0, section: number = 0) {
|
||
|
this.sectionRunner = sectionRunner;
|
||
7 years ago
|
this.id = id;
|
||
|
this.section = section;
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
cancel = () => this.sectionRunner.cancelRunById(this.id);
|
||
7 years ago
|
|
||
|
toString() {
|
||
|
return `SectionRun{id=${this.id}, section=${this.section}, duration=${this.duration},` +
|
||
|
` startTime=${this.startTime}, pauseTime=${this.pauseTime}}`;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class SectionRunner {
|
||
7 years ago
|
readonly device: SprinklersDevice;
|
||
7 years ago
|
|
||
7 years ago
|
@observable queue: SectionRun[] = [];
|
||
|
@observable current: SectionRun | null = null;
|
||
|
@observable paused: boolean = false;
|
||
7 years ago
|
|
||
|
constructor(device: SprinklersDevice) {
|
||
|
this.device = device;
|
||
|
}
|
||
|
|
||
7 years ago
|
cancelRunById(runId: number) {
|
||
|
return this.device.cancelSectionRunId({ runId });
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
setPaused(paused: boolean) {
|
||
|
return this.device.pauseSectionRunner({ paused });
|
||
|
}
|
||
|
|
||
|
pause() {
|
||
|
return this.setPaused(true);
|
||
|
}
|
||
|
|
||
|
unpause() {
|
||
|
return this.setPaused(false);
|
||
|
}
|
||
|
|
||
7 years ago
|
toString(): string {
|
||
|
return `SectionRunner{queue="${this.queue}", current="${this.current}", paused=${this.paused}}`;
|
||
|
}
|
||
|
}
|