typescriptifying

This commit is contained in:
Wolfgang Hottgenroth
2018-01-09 16:36:14 +01:00
parent 9e39d74084
commit 8d85314fc9
21 changed files with 372 additions and 182 deletions

40
src/M433SwitchItem.ts Normal file
View File

@ -0,0 +1,40 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AItem } from './AItem'
export class M433SwitchItem extends AItem {
private offCode: string
private onCode: string
private oldState: string|undefined
private state: string
private actionTopic: string
private stateFeedbackTopic: string
private stateTopic: string
constructor(floor: string, room: string, item: string, onCode: string, offCode: string) {
super(floor, room, item)
this.stateTopic = `${this.topicFirstPart}/state`
this.subscribeTopics = [this.stateTopic]
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
this.actionTopic = 'IoT/Mqtt433Gateway/Message'
this.state = 'OFF'
this.oldState = undefined
this.onCode = onCode
this.offCode = offCode
}
processMessage(topic: string, payload: string) {
this.state = payload;
mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) {
if (this.state == 'ON') {
mqttHandler.send(this.actionTopic, this.onCode);
} else {
mqttHandler.send(this.actionTopic, this.offCode);
}
this.oldState = this.state;
}
}
}