2017-10-04 13:22:10 -06:00
|
|
|
import { observable } from "mobx";
|
|
|
|
import { SprinklersDevice } from "./SprinklersDevice";
|
|
|
|
|
|
|
|
export class Section {
|
2017-10-05 09:07:07 -06:00
|
|
|
readonly device: SprinklersDevice;
|
|
|
|
readonly id: number;
|
2017-10-04 13:22:10 -06:00
|
|
|
|
2017-10-05 09:07:07 -06:00
|
|
|
@observable name: string = "";
|
|
|
|
@observable state: boolean = false;
|
2017-10-04 13:22:10 -06:00
|
|
|
|
2017-10-05 09:07:07 -06:00
|
|
|
constructor(device: SprinklersDevice, id: number) {
|
2017-10-04 13:22:10 -06:00
|
|
|
this.device = device;
|
2017-10-05 09:07:07 -06:00
|
|
|
this.id = id;
|
2017-10-04 13:22:10 -06:00
|
|
|
}
|
|
|
|
|
2017-10-10 16:34:02 -06:00
|
|
|
/** duration is in seconds */
|
|
|
|
run(duration: number) {
|
2017-10-10 16:25:21 -06:00
|
|
|
return this.device.runSection({ sectionId: this.id, duration });
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
return this.device.cancelSection({ sectionId: this.id });
|
2017-10-04 13:22:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
toString(): string {
|
2018-07-23 19:20:41 -06:00
|
|
|
return `Section ${this.id}: '${this.name}'`;
|
2017-10-04 13:22:10 -06:00
|
|
|
}
|
|
|
|
}
|