49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { observable } from "mobx";
import { Schedule } from "./schedule";
import { SprinklersDevice } from "./SprinklersDevice";
export class ProgramItem {
// the section number
2017-10-05 09:07:07 -06:00
readonly section: number;
2017-10-10 16:34:02 -06:00
// duration of the run, in seconds
readonly duration: number;
2017-10-10 16:34:02 -06:00
constructor(section: number = 0, duration: number = 0) {
this.section = section;
this.duration = duration;
}
}
export class Program {
2017-10-05 09:07:07 -06:00
readonly device: SprinklersDevice;
readonly id: number;
2017-10-05 09:07:07 -06:00
@observable name: string = "";
@observable enabled: boolean = false;
@observable schedule: Schedule = new Schedule();
@observable.shallow sequence: ProgramItem[] = [];
@observable running: boolean = false;
2017-10-05 09:07:07 -06:00
constructor(device: SprinklersDevice, id: number) {
this.device = device;
2017-10-05 09:07:07 -06:00
this.id = id;
}
run() {
return this.device.runProgram({ programId: this.id });
}
cancel() {
return this.device.cancelProgram({ programId: this.id });
}
update(data: any) {
return this.device.updateProgram({ programId: this.id, data });
}
toString(): string {
2017-10-04 13:51:06 -06:00
return `Program{name="${this.name}", enabled=${this.enabled}, schedule=${this.schedule}, ` +
`sequence=${this.sequence}, running=${this.running}}`;
}
}