import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { AHomegearItem } from './AHomegearItem' import { ContactExport, ExportType } from './Export' import { Disabler } from './Disabler' export class MaxWindowContact extends AHomegearItem implements Disabler { private deviceFeedbackTopic: string private stateFeedbackTopic: string private stateTopic: string private state: string getStateFeedbackTopic(): string { return this.stateFeedbackTopic } transform(payload: string) : string { let res: string if (payload == 'OPEN') { res = 'DISABLE' } else if (payload == 'CLOSED') { res = 'ENABLE' } else { res = 'UNKNOWN' } return res } constructor(floor: string, room: string, item: string, label: string, hmId: number) { super(floor, room, item, label, hmId) this.stateTopic = `${this.topicFirstPart}/state` this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback` this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE` this.subscribeTopics = [ this.stateTopic, this.deviceFeedbackTopic ] } exportItem() : ExportType|null { return ContactExport(this.itemId, this.label, this.stateFeedbackTopic) } processMessage(topic: string, payload: string) : void { if (payload == 'true') { this.state = 'OPEN' } else { this.state = 'CLOSED' } mqttHandler.send(this.stateFeedbackTopic, this.state) } }