openhab export added

This commit is contained in:
Wolfgang Hottgenroth
2018-01-10 15:06:58 +01:00
parent 8a6547ff91
commit 91f8dd929e
12 changed files with 85 additions and 36 deletions

4
dist/AItem.js vendored
View File

@ -16,8 +16,8 @@ class AItem {
}
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
}
exportHomekit() {
return { 'id': this.itemId, 'object': null };
exportItem() {
return null;
}
start() {
MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => {

17
dist/Export.js vendored
View File

@ -1,20 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function SwitchHomekitExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
let out;
function SwitchExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
let homekitOut;
switch (type) {
case 'bulb':
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
homekitOut = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
case 'outlet':
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
homekitOut = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
default:
throw new Error(`no homekit export function for type ${type}`);
}
return out;
let openhabOut = SwitchOpenHABExport(itemId, label, stateTopic, stateFeedbackTopic);
return { 'homekit': homekitOut, 'openhab': openhabOut };
}
exports.SwitchHomekitExport = SwitchHomekitExport;
exports.SwitchExport = SwitchExport;
function SwitchHomekitBulbExport(id, label, setOn, statusOn) {
let o = {
"id": id,
@ -52,4 +53,8 @@ function SwitchHomekitOutletExport(id, label, setOn, statusOn) {
};
return { 'id': id, 'object': o };
}
function SwitchOpenHABExport(id, label, setOn, statusOn) {
// Switch windowLightKitchen {mqtt=">[localbroker:nodered/items/windowLightKitchen:command:*:default]", mqtt="<[localbroker:nodered/items/windowLightKitchen/feedback:state:default]"}
return `Switch ${id} {mqtt=">[localbroker:${setOn}:command:*:default]", mqtt="<[localbroker:${statusOn}:state:default]"}`;
}
//# sourceMappingURL=Export.js.map

View File

@ -18,8 +18,8 @@ class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
this.oldState = undefined;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
exportItem() {
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
switch (topic) {

View File

@ -16,8 +16,8 @@ class M433SwitchItem extends AItem_1.AItem {
this.offCode = offCode;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
exportItem() {
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
this.state = payload;

11
dist/main.js vendored
View File

@ -124,13 +124,18 @@ testForwarder.start();
// ----------------------------------------------------------------------------------------------------------
// Homekit export
let homekitObject = {};
let openhabList = [];
allLabeledItems.forEach((item) => {
let homekitExport = item.exportHomekit();
if ('id' in homekitExport) {
homekitObject[homekitExport['id']] = homekitExport['object'];
let exportData = item.exportItem();
if (exportData != null) {
if ('id' in exportData['homekit']) {
homekitObject[exportData['homekit']['id']] = exportData['homekit']['object'];
}
openhabList.push(exportData['openhab']);
}
});
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4));
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'));
// ----------------------------------------------------------------------------------------------------------
MqttDispatcher_1.mqttHandler.exec();
logger.info("Dispatcher running");