From f88cf5ee0dc4fea357d93ae3676af4d4db88d225 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 15 Jan 2018 16:20:59 +0100 Subject: [PATCH] some changes, not yet done with WindowContact, too cold in Q-West to complete --- src/MaxThermostat.ts | 60 +++++++++++++++++++++++++++++++++++++++++ src/MaxWindowContact.ts | 32 ++++++++++++++++++++++ src/MqttDispatcher.ts | 18 ++++++------- src/UrlSwitchItem.ts | 5 ++-- 4 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 src/MaxThermostat.ts create mode 100644 src/MaxWindowContact.ts diff --git a/src/MaxThermostat.ts b/src/MaxThermostat.ts new file mode 100644 index 0000000..4588fae --- /dev/null +++ b/src/MaxThermostat.ts @@ -0,0 +1,60 @@ +import * as logger from './log' +import { mqttHandler } from './MqttDispatcher' +import { AHomematicItem } from './AHomematicItem' +import { MaxWindowContact } from './MaxWindowContact'; +// import { SwitchExport, ExportType } from './Export' + +const WINDOW_OPEN_TEMPERATURE = 4.5 + + +export class MaxThermostat extends AHomematicItem { + private actionTopic: string + private deviceFeedbackTopic: string + private temperatureFeedbackTopic: string + private temperatureTopic: string + private temperature: number + private windowContacts: MaxWindowContact[] + private windowContactTopics: string[] + private windowOpen: boolean + // Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE + + constructor(floor: string, room: string, item: string, label: string, hmId: number, windowContacts: MaxWindowContact[]) { + super(floor, room, item, label, hmId) + this.temperatureTopic = `${this.topicFirstPart}/temperature` + this.temperatureFeedbackTopic = `${this.topicFirstPart}/temperature/feedback` + this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/SET_TEMPERATURE` + this.actionTopic = `${this.actionTopicPre}/1/SET_TEMPERATURE` + this.subscribeTopics = [ + this.temperatureTopic, + this.deviceFeedbackTopic + ] + this.windowContacts = windowContacts + this.windowOpen = false + this.windowContactTopics = [] + this.windowContacts.forEach((windowContact) => { + this.subscribeTopics.push(windowContact.getStateFeedbackTopic()) + this.windowContactTopics.push(windowContact.getStateFeedbackTopic()) + }) + } + + processMessage(topic: string, payload: string) : void { + if (topic == this.temperatureTopic) { + this.temperature = parseFloat(payload) + mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`) + mqttHandler.send(this.actionTopic, `${this.temperature}`) + } else if (topic == this.deviceFeedbackTopic) { + this.temperature = parseFloat(payload) + mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`) + } else if (this.windowContactTopics.indexOf(topic) >= 0) { + if (payload == 'CLOSED') { + + } else { + + } + } + + + } + + +} \ No newline at end of file diff --git a/src/MaxWindowContact.ts b/src/MaxWindowContact.ts new file mode 100644 index 0000000..67324f1 --- /dev/null +++ b/src/MaxWindowContact.ts @@ -0,0 +1,32 @@ +import * as logger from './log' +import { mqttHandler } from './MqttDispatcher' +import { AHomematicItem } from './AHomematicItem' +// import { SwitchExport, ExportType } from './Export' + +export class MaxWindowContact extends AHomematicItem { + 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 + ] + } + + processMessage(topic: string, payload: string) : void { + this.state = payload + mqttHandler.send(this.stateFeedbackTopic, this.state) + } + +} \ No newline at end of file diff --git a/src/MqttDispatcher.ts b/src/MqttDispatcher.ts index 5ff59b8..2b03cc8 100644 --- a/src/MqttDispatcher.ts +++ b/src/MqttDispatcher.ts @@ -90,17 +90,17 @@ class MqttHandler { } send(topic: string, payload: string, internalFirst: boolean = false) : void { - let sent = false - if (internalFirst) { - logger.info(`Try internal sending: ${topic}`) - sent = this.processMessage(topic, payload) - } - if (! sent) { + //let sent = false + //if (internalFirst) { + // logger.info(`Try internal sending: ${topic}`) + // sent = this.processMessage(topic, payload) + //} + //if (! sent) { logger.info(`External sending required: ${topic}`) this.mqttClient.publish(topic, payload) - } else { - logger.info(`Internally delivered: ${topic}`) - } + //} else { + // logger.info(`Internally delivered: ${topic}`) + //} } } diff --git a/src/UrlSwitchItem.ts b/src/UrlSwitchItem.ts index 8ee34c4..bd9fa46 100644 --- a/src/UrlSwitchItem.ts +++ b/src/UrlSwitchItem.ts @@ -2,6 +2,7 @@ import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { AItem, HasStateAndFeedbackTopic } from './AItem' import { SwitchExport, ExportType } from './Export' +import * as http from 'http' export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic { @@ -44,9 +45,9 @@ export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic { mqttHandler.send(this.stateFeedbackTopic, this.state); if (this.state != this.oldState) { if (this.state == 'ON') { - mqttHandler.send(this.actionTopic, this.onCode); + http.get(this.onUrl) } else { - mqttHandler.send(this.actionTopic, this.offCode); + http.get(this.offUrl) } this.oldState = this.state; }