import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { AHomegearItem } from './AHomegearItem' import { ContactExport, ExportType } from './Export' export class MaxWindowContact extends AHomegearItem { private deviceFeedbackTopic: string private stateFeedbackTopic: string private stateTopic: string private state: string getStateFeedbackTopic(): string { return this.stateFeedbackTopic } 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) } }