From cc930e6bbc8119c56cc4ac5d716463cf31a39044 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 27 Mar 2018 21:50:48 +0200 Subject: [PATCH] export prepared --- dist/AItem.js | 3 +-- dist/Export.js | 11 +++++++++++ dist/MqttDispatcher.js | 4 ++-- dist/RelayBox.js | 6 +++++- src/Export.ts | 15 +++++++++++++++ src/MqttDispatcher.ts | 2 +- src/RelayBox.ts | 5 +++++ 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/dist/AItem.js b/dist/AItem.js index 4e3548d..d48bf09 100644 --- a/dist/AItem.js +++ b/dist/AItem.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const logger = require("./log"); const MqttDispatcher_1 = require("./MqttDispatcher"); class AItem { constructor(floor, room, item, label = '') { @@ -21,7 +20,7 @@ class AItem { } start() { MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => { - logger.info(`item ${this.itemId}: ${topic}, ${payload}`); + // logger.info(`item ${this.itemId}: ${topic}, ${payload}`) this.processMessage(topic, payload); }); } diff --git a/dist/Export.js b/dist/Export.js index 1b181cd..766a4ba 100644 --- a/dist/Export.js +++ b/dist/Export.js @@ -28,6 +28,17 @@ function HueColorLightExport(itemId, label, stateTopic, stateFeedbackTopic, brig return { 'homekit': HueColorLightHomekitExport(itemId, label, stateTopic, stateFeedbackTopic, brightnessTopic, brightnessFeedbackTopic, hueTopic, hueFeedbackTopic, saturationTopic, saturationFeedbackTopic, colorTemperatureTopic, colorTemperatureFeedbackTopic), 'openhab': '' }; } exports.HueColorLightExport = HueColorLightExport; +function RelayBoxExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { + return { 'homekit': RelayBoxHomekitExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames), + 'openhab': RelayBoxOpenHABExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) }; +} +exports.RelayBoxExport = RelayBoxExport; +function RelayBoxHomekitExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { + return { 'id': '', 'object': {} }; +} +function RelayBoxOpenHABExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { + return ''; +} function SwitchHomekitBulbExport(id, label, setOn, statusOn) { let o = { "id": id, diff --git a/dist/MqttDispatcher.js b/dist/MqttDispatcher.js index 8cfa26c..2a6fbfb 100644 --- a/dist/MqttDispatcher.js +++ b/dist/MqttDispatcher.js @@ -43,7 +43,7 @@ class MqttHandler { this.mqttClient.on('message', (topic, payload, packet) => { if (!packet.retain) { let payloadStr = payload.toString('UTF-8'); - logger.info(`Message received on topic ${topic}: ${payload}`); + // logger.info(`Message received on topic ${topic}: ${payload}`) this.processMessage(topic, payloadStr); } }); @@ -76,7 +76,7 @@ class MqttHandler { // sent = this.processMessage(topic, payload) //} //if (! sent) { - logger.info(`External sending required: ${topic}`); + logger.info(`External sending required: ${topic} ${payload}`); let options = { retain: true, qos: 0 }; this.mqttClient.publish(topic, payload, options); //} else { diff --git a/dist/RelayBox.js b/dist/RelayBox.js index 2b580f4..2245f0b 100644 --- a/dist/RelayBox.js +++ b/dist/RelayBox.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const logger = require("./log"); const MqttDispatcher_1 = require("./MqttDispatcher"); const AItem_1 = require("./AItem"); +const Export_1 = require("./Export"); class RelayBoxThing extends AItem_1.AItem { constructor(floor, room, item, deviceCommandTopic, deviceStatusTopic, itemNames) { super(floor, room, item, ''); @@ -18,10 +19,13 @@ class RelayBoxThing extends AItem_1.AItem { ]; this.oldSwitchStates = ''; } + exportItem() { + return Export_1.RelayBoxExport(this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames); + } processMessage(topic, payload) { // logger.info(`RT: ${topic}, ${payload}`) if (topic == this.deviceStatusTopic) { - logger.info(`RT: status received`); + // logger.info(`RT: status received`) this.status = JSON.parse(payload); let statusParsed = JSON.stringify(this.status); this.switchStates = JSON.stringify(this.status.data.switchStates); diff --git a/src/Export.ts b/src/Export.ts index 41024fb..cea9acf 100644 --- a/src/Export.ts +++ b/src/Export.ts @@ -45,6 +45,21 @@ export function HueColorLightExport(itemId: string, label: string, brightnessTopic, brightnessFeedbackTopic, hueTopic, hueFeedbackTopic, saturationTopic, saturationFeedbackTopic, colorTemperatureTopic, colorTemperatureFeedbackTopic), 'openhab': ''} } + +export function RelayBoxExport(stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : ExportType { + return {'homekit': RelayBoxHomekitExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames), + 'openhab': RelayBoxOpenHABExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames)} +} + +function RelayBoxHomekitExport(stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : HomekitExportType{ + return {'id': '', 'object': {}} +} + +function RelayBoxOpenHABExport(stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : string { + return '' +} + + function SwitchHomekitBulbExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType { let o : any = { "id": id, diff --git a/src/MqttDispatcher.ts b/src/MqttDispatcher.ts index 2d0cb8a..0a989f8 100644 --- a/src/MqttDispatcher.ts +++ b/src/MqttDispatcher.ts @@ -97,7 +97,7 @@ class MqttHandler { // sent = this.processMessage(topic, payload) //} //if (! sent) { - logger.info(`External sending required: ${topic}`) + logger.info(`External sending required: ${topic} ${payload}`) let options : IClientPublishOptions = { retain: true, qos: 0 } this.mqttClient.publish(topic, payload, options) //} else { diff --git a/src/RelayBox.ts b/src/RelayBox.ts index d9e0b2a..30fa2ce 100644 --- a/src/RelayBox.ts +++ b/src/RelayBox.ts @@ -1,6 +1,7 @@ import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { AItem } from './AItem' +import { RelayBoxExport, ExportType } from './Export' @@ -31,6 +32,10 @@ export class RelayBoxThing extends AItem { this.oldSwitchStates = '' } + exportItem() : ExportType|null { + return RelayBoxExport(this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames) + } + processMessage(topic: string, payload: string) { // logger.info(`RT: ${topic}, ${payload}`) if (topic == this.deviceStatusTopic) {