19 lines
480 B
TypeScript
Raw Normal View History

2018-07-25 12:53:33 -06:00
import { update } from "serializr";
import * as s from "@common/sprinklersRpc";
import * as schema from "@common/sprinklersRpc/schema";
export class MqttProgram extends s.Program {
2018-09-02 02:57:55 -06:00
onMessage(payload: string, topic: string | undefined) {
if (topic === "running") {
this.running = payload === "true";
} else if (topic == null) {
this.updateFromJSON(JSON.parse(payload));
2018-07-25 12:53:33 -06:00
}
2018-09-02 02:57:55 -06:00
}
2018-07-25 12:53:33 -06:00
2018-09-02 02:57:55 -06:00
updateFromJSON(json: any) {
update(schema.program, this, json);
}
2018-07-25 12:53:33 -06:00
}