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.
49 lines
1.3 KiB
49 lines
1.3 KiB
7 years ago
|
import { observable } from "mobx";
|
||
|
import { Schedule } from "./schedule";
|
||
|
import { SprinklersDevice } from "./SprinklersDevice";
|
||
|
|
||
|
export class ProgramItem {
|
||
|
// the section number
|
||
7 years ago
|
readonly section: number;
|
||
7 years ago
|
// duration of the run, in seconds
|
||
|
readonly duration: number;
|
||
7 years ago
|
|
||
7 years ago
|
constructor(section: number = 0, duration: number = 0) {
|
||
7 years ago
|
this.section = section;
|
||
|
this.duration = duration;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class Program {
|
||
7 years ago
|
readonly device: SprinklersDevice;
|
||
|
readonly id: number;
|
||
7 years ago
|
|
||
7 years ago
|
@observable name: string = "";
|
||
|
@observable enabled: boolean = false;
|
||
|
@observable schedule: Schedule = new Schedule();
|
||
|
@observable.shallow sequence: ProgramItem[] = [];
|
||
|
@observable running: boolean = false;
|
||
7 years ago
|
|
||
7 years ago
|
constructor(device: SprinklersDevice, id: number) {
|
||
7 years ago
|
this.device = device;
|
||
7 years ago
|
this.id = id;
|
||
7 years ago
|
}
|
||
|
|
||
|
run() {
|
||
7 years ago
|
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 });
|
||
7 years ago
|
}
|
||
|
|
||
|
toString(): string {
|
||
7 years ago
|
return `Program{name="${this.name}", enabled=${this.enabled}, schedule=${this.schedule}, ` +
|
||
|
`sequence=${this.sequence}, running=${this.running}}`;
|
||
7 years ago
|
}
|
||
|
}
|