openhab export added
This commit is contained in:
@ -7,5 +7,6 @@
|
|||||||
"smtpPort": 25,
|
"smtpPort": 25,
|
||||||
"smtpSender": "dispatcher@hottis.de",
|
"smtpSender": "dispatcher@hottis.de",
|
||||||
"smtpReceiver": "woho@hottis.de",
|
"smtpReceiver": "woho@hottis.de",
|
||||||
"homekitFile": "homekit.json"
|
"homekitFile": "homekit.json",
|
||||||
|
"openhabItemFile": "openhab.items"
|
||||||
}
|
}
|
||||||
|
4
dist/AItem.js
vendored
4
dist/AItem.js
vendored
@ -16,8 +16,8 @@ class AItem {
|
|||||||
}
|
}
|
||||||
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
|
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
|
||||||
}
|
}
|
||||||
exportHomekit() {
|
exportItem() {
|
||||||
return { 'id': this.itemId, 'object': null };
|
return null;
|
||||||
}
|
}
|
||||||
start() {
|
start() {
|
||||||
MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => {
|
MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => {
|
||||||
|
17
dist/Export.js
vendored
17
dist/Export.js
vendored
@ -1,20 +1,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
function SwitchHomekitExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
|
function SwitchExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
|
||||||
let out;
|
let homekitOut;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'bulb':
|
case 'bulb':
|
||||||
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
|
homekitOut = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
|
||||||
break;
|
break;
|
||||||
case 'outlet':
|
case 'outlet':
|
||||||
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
|
homekitOut = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`no homekit export function for type ${type}`);
|
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) {
|
function SwitchHomekitBulbExport(id, label, setOn, statusOn) {
|
||||||
let o = {
|
let o = {
|
||||||
"id": id,
|
"id": id,
|
||||||
@ -52,4 +53,8 @@ function SwitchHomekitOutletExport(id, label, setOn, statusOn) {
|
|||||||
};
|
};
|
||||||
return { 'id': id, 'object': o };
|
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
|
//# sourceMappingURL=Export.js.map
|
4
dist/HomematicSwitchItem.js
vendored
4
dist/HomematicSwitchItem.js
vendored
@ -18,8 +18,8 @@ class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
|
|||||||
this.oldState = undefined;
|
this.oldState = undefined;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
exportHomekit() {
|
exportItem() {
|
||||||
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
|
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
|
||||||
}
|
}
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
|
4
dist/M433SwitchItem.js
vendored
4
dist/M433SwitchItem.js
vendored
@ -16,8 +16,8 @@ class M433SwitchItem extends AItem_1.AItem {
|
|||||||
this.offCode = offCode;
|
this.offCode = offCode;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
exportHomekit() {
|
exportItem() {
|
||||||
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
|
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
|
||||||
}
|
}
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
this.state = payload;
|
this.state = payload;
|
||||||
|
11
dist/main.js
vendored
11
dist/main.js
vendored
@ -124,13 +124,18 @@ testForwarder.start();
|
|||||||
// ----------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------
|
||||||
// Homekit export
|
// Homekit export
|
||||||
let homekitObject = {};
|
let homekitObject = {};
|
||||||
|
let openhabList = [];
|
||||||
allLabeledItems.forEach((item) => {
|
allLabeledItems.forEach((item) => {
|
||||||
let homekitExport = item.exportHomekit();
|
let exportData = item.exportItem();
|
||||||
if ('id' in homekitExport) {
|
if (exportData != null) {
|
||||||
homekitObject[homekitExport['id']] = homekitExport['object'];
|
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.homekitFile, JSON.stringify(homekitObject, null, 4));
|
||||||
|
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'));
|
||||||
// ----------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------
|
||||||
MqttDispatcher_1.mqttHandler.exec();
|
MqttDispatcher_1.mqttHandler.exec();
|
||||||
logger.info("Dispatcher running");
|
logger.info("Dispatcher running");
|
||||||
|
20
openhab.items
Normal file
20
openhab.items
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Switch 1st.Anna.AquariumLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/AquariumLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/Anna/AquariumLight/state/feedback:state:default]"}
|
||||||
|
Switch 1st.Anna.BedLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/BedLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/Anna/BedLight/state/feedback:state:default]"}
|
||||||
|
Switch 1st.Matthias.Stehlampen Matthias {mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state/feedback:state:default]"}
|
||||||
|
Switch 1st.Matthias.BedLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/BedLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/Matthias/BedLight/state/feedback:state:default]"}
|
||||||
|
Switch 1st.Matthias.Speaker {mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/Speaker/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/Matthias/Speaker/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.DiningRoom.SmallLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.DiningRoom.StandLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/DiningRoom/StandLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/DiningRoom/StandLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.DiningRoom.CupboardLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.LivingRoom.LargeLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.LivingRoom.SmallLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.LivingRoom.Stars {mqtt=">[localbroker:dispatcher_ng/items/Gnd/LivingRoom/Stars/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/LivingRoom/Stars/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.LivingRoom.StandLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/LivingRoom/StandLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/LivingRoom/StandLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.Hallway.DeskLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/DeskLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/DeskLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.Hallway.StandLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/StandLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/StandLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.Hallway.StandLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/StandLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/StandLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.Kitchen.WindowLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowLight/state/feedback:state:default]"}
|
||||||
|
Switch Gnd.Kitchen.CeilingLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Kitchen/CeilingLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/CeilingLight/state/feedback:state:default]"}
|
||||||
|
Switch 1st.BedRoom.WolfgangsSide {mqtt=">[localbroker:dispatcher_ng/items/1st/BedRoom/WolfgangsSide/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/BedRoom/WolfgangsSide/state/feedback:state:default]"}
|
||||||
|
Switch 1st.BedRoom.PattysSide {mqtt=">[localbroker:dispatcher_ng/items/1st/BedRoom/PattysSide/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/BedRoom/PattysSide/state/feedback:state:default]"}
|
||||||
|
Switch 1st.BedRoom.WindowLight {mqtt=">[localbroker:dispatcher_ng/items/1st/BedRoom/WindowLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/1st/BedRoom/WindowLight/state/feedback:state:default]"}
|
@ -1,6 +1,6 @@
|
|||||||
import * as logger from './log'
|
import * as logger from './log'
|
||||||
import { mqttHandler } from './MqttDispatcher'
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
import { HomekitExportType } from './Export'
|
import { ExportType } from './Export'
|
||||||
|
|
||||||
|
|
||||||
export abstract class AItem {
|
export abstract class AItem {
|
||||||
@ -28,8 +28,8 @@ export abstract class AItem {
|
|||||||
|
|
||||||
abstract processMessage(topic: string, payload: string) : void
|
abstract processMessage(topic: string, payload: string) : void
|
||||||
|
|
||||||
exportHomekit() : HomekitExportType {
|
exportItem() : ExportType|null {
|
||||||
return {'id': this.itemId, 'object': null }
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
start() : void {
|
start() : void {
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
|
export type ExportType = {
|
||||||
|
'homekit': HomekitExportType,
|
||||||
|
'openhab': string
|
||||||
|
}
|
||||||
|
|
||||||
export type HomekitExportType = {
|
export type HomekitExportType = {
|
||||||
'id': string,
|
'id': string,
|
||||||
'object': any
|
'object': any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function SwitchHomekitExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : HomekitExportType {
|
export function SwitchExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : ExportType {
|
||||||
let out: HomekitExportType
|
let homekitOut: HomekitExportType
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'bulb':
|
case 'bulb':
|
||||||
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
|
homekitOut = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||||
break
|
break
|
||||||
case 'outlet':
|
case 'outlet':
|
||||||
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
|
homekitOut = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`no homekit export function for type ${type}`)
|
throw new Error(`no homekit export function for type ${type}`)
|
||||||
}
|
}
|
||||||
return out
|
|
||||||
|
let openhabOut : string = SwitchOpenHABExport(itemId, label, stateTopic, stateFeedbackTopic)
|
||||||
|
|
||||||
|
return { 'homekit': homekitOut, 'openhab': openhabOut }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -58,3 +66,9 @@ function SwitchHomekitOutletExport(id: string, label: string, setOn: string, sta
|
|||||||
}
|
}
|
||||||
return { 'id': id, 'object': o }
|
return { 'id': id, 'object': o }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function SwitchOpenHABExport(id: string, label: string, setOn: string, statusOn: string): string {
|
||||||
|
// 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]"}`
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import * as logger from './log'
|
import * as logger from './log'
|
||||||
import { mqttHandler } from './MqttDispatcher'
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
import { AHomematicItem } from './AHomematicItem'
|
import { AHomematicItem } from './AHomematicItem'
|
||||||
import { SwitchHomekitExport, HomekitExportType } from './Export'
|
import { SwitchExport, ExportType } from './Export'
|
||||||
|
|
||||||
export class HomematicSwitchItem extends AHomematicItem {
|
export class HomematicSwitchItem extends AHomematicItem {
|
||||||
private oldState: string|undefined
|
private oldState: string|undefined
|
||||||
@ -27,8 +27,8 @@ export class HomematicSwitchItem extends AHomematicItem {
|
|||||||
this.type = type
|
this.type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
exportHomekit() : HomekitExportType {
|
exportItem() : ExportType|null {
|
||||||
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
return SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic: string, payload: string) : void {
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as logger from './log'
|
import * as logger from './log'
|
||||||
import { mqttHandler } from './MqttDispatcher'
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
import { AItem } from './AItem'
|
import { AItem } from './AItem'
|
||||||
import { SwitchHomekitExport, HomekitExportType } from './Export'
|
import { SwitchExport, ExportType } from './Export'
|
||||||
|
|
||||||
|
|
||||||
export class M433SwitchItem extends AItem {
|
export class M433SwitchItem extends AItem {
|
||||||
@ -27,8 +27,8 @@ export class M433SwitchItem extends AItem {
|
|||||||
this.type = type
|
this.type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
exportHomekit() : HomekitExportType {
|
exportItem() : ExportType|null {
|
||||||
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
return SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic: string, payload: string) {
|
processMessage(topic: string, payload: string) {
|
||||||
|
14
src/main.ts
14
src/main.ts
@ -5,7 +5,7 @@ import * as logger from './log'
|
|||||||
import { mqttHandler } from './MqttDispatcher'
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
|
||||||
import { AItem } from './AItem'
|
import { AItem } from './AItem'
|
||||||
import { HomekitExportType } from './Export'
|
import { HomekitExportType, ExportType } from './Export'
|
||||||
import { M433SwitchItem } from './M433SwitchItem'
|
import { M433SwitchItem } from './M433SwitchItem'
|
||||||
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
||||||
import { DimmerAdaptor } from './DimmerAdaptor'
|
import { DimmerAdaptor } from './DimmerAdaptor'
|
||||||
@ -164,15 +164,19 @@ testForwarder.start()
|
|||||||
// ----------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------
|
||||||
// Homekit export
|
// Homekit export
|
||||||
let homekitObject : { [key:string]:{} } = {}
|
let homekitObject : { [key:string]:{} } = {}
|
||||||
|
let openhabList : string[] = []
|
||||||
|
|
||||||
allLabeledItems.forEach((item: AItem) => {
|
allLabeledItems.forEach((item: AItem) => {
|
||||||
let homekitExport : HomekitExportType = item.exportHomekit()
|
let exportData : ExportType|null = item.exportItem()
|
||||||
if ('id' in homekitExport) {
|
if (exportData != null) {
|
||||||
homekitObject[homekitExport['id']] = homekitExport['object']
|
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.homekitFile, JSON.stringify(homekitObject, null, 4))
|
||||||
|
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'))
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------
|
||||||
mqttHandler.exec()
|
mqttHandler.exec()
|
||||||
|
Reference in New Issue
Block a user