31 lines
644 B
TypeScript
Raw Normal View History

import { observable } from "mobx";
import { SprinklersDevice } from "./SprinklersDevice";
export class Section {
2018-09-02 02:57:55 -06:00
readonly device: SprinklersDevice;
readonly id: number;
2018-09-02 02:57:55 -06:00
@observable
name: string = "";
@observable
state: boolean = false;
2018-09-02 02:57:55 -06:00
constructor(device: SprinklersDevice, id: number) {
this.device = device;
this.id = id;
}
2018-09-02 02:57:55 -06:00
/** duration is in seconds */
run(duration: number) {
return this.device.runSection({ sectionId: this.id, duration });
}
2018-09-02 02:57:55 -06:00
cancel() {
return this.device.cancelSection({ sectionId: this.id });
}
2018-09-02 02:57:55 -06:00
toString(): string {
return `Section ${this.id}: '${this.name}'`;
}
}