add all existing items, homekit export

This commit is contained in:
Wolfgang Hottgenroth
2018-01-10 14:15:43 +01:00
parent 153b8570e4
commit 8a6547ff91
20 changed files with 746 additions and 42 deletions

View File

@ -2,8 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
class AHomematicItem extends AItem_1.AItem {
constructor(floor, room, item, hmId) {
super(floor, room, item);
constructor(floor, room, item, label, hmId) {
super(floor, room, item, label);
this.hmId = hmId;
this.homegearTopicPre = 'homegear/instance1';
this.actionTopicPre = `${this.homegearTopicPre}/set/${this.hmId}`;

11
dist/AItem.js vendored
View File

@ -3,13 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
class AItem {
constructor(floor, room, item) {
constructor(floor, room, item, label = '') {
this.floor = floor;
this.room = room;
this.item = item;
this.itemId = `${this.floor}.${this.room}.${this.item}`;
if (label == '') {
this.label = this.itemId;
}
else {
this.label = label;
}
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
}
exportHomekit() {
return { 'id': this.itemId, 'object': null };
}
start() {
MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => {
logger.info(`item ${this.itemId}: ${topic}, ${payload}`);

55
dist/Export.js vendored Normal file
View File

@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function SwitchHomekitExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
let out;
switch (type) {
case 'bulb':
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
case 'outlet':
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
default:
throw new Error(`no homekit export function for type ${type}`);
}
return out;
}
exports.SwitchHomekitExport = SwitchHomekitExport;
function SwitchHomekitBulbExport(id, label, setOn, statusOn) {
let o = {
"id": id,
"name": label,
"service": "Lightbulb",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
};
return { 'id': id, 'object': o };
}
function SwitchHomekitOutletExport(id, label, setOn, statusOn) {
let o = {
"id": id,
"name": label,
"service": "Outlet",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF"
},
"config": {}
};
return { 'id': id, 'object': o };
}
//# sourceMappingURL=Export.js.map

4
dist/Forwarder.js vendored
View File

@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
const MqttDispatcher_1 = require("./MqttDispatcher");
class Forwarder extends AItem_1.AItem {
constructor(floor, room, item, topicLastPart, targetTopics) {
super(floor, room, item);
constructor(floor, room, item, label, topicLastPart, targetTopics) {
super(floor, room, item, label);
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
this.subscribeTopics = [this.inTopic];
this.targetTopics = targetTopics;

View File

@ -4,8 +4,8 @@ const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
class HomematicDimmerItem extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId) {
super(floor, room, item, hmId);
constructor(floor, room, item, label, hmId) {
super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;
this.brightTopic = `${this.topicFirstPart}/bright`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;

View File

@ -28,7 +28,7 @@ class HomematicFourButtonSingleItem {
exports.HomematicFourButtonSingleItem = HomematicFourButtonSingleItem;
class HomematicFourButtonThing extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId, itemObjs) {
super(floor, room, item, hmId);
super(floor, room, item, '', hmId);
this.itemObjs = itemObjs;
if (this.itemObjs.length != 4) {
throw new Error('itemObjs for HomematicFourButtonThing must have four elements');

View File

@ -2,9 +2,10 @@
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
const Export_1 = require("./Export");
class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId) {
super(floor, room, item, hmId);
constructor(floor, room, item, label, hmId, type = 'bulb') {
super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`;
@ -15,6 +16,10 @@ class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
];
this.state = 'OFF';
this.oldState = undefined;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
switch (topic) {

View File

@ -2,9 +2,10 @@
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AItem_1 = require("./AItem");
const Export_1 = require("./Export");
class M433SwitchItem extends AItem_1.AItem {
constructor(floor, room, item, onCode, offCode) {
super(floor, room, item);
constructor(floor, room, item, label, onCode, offCode, type = 'bulb') {
super(floor, room, item, label);
this.stateTopic = `${this.topicFirstPart}/state`;
this.subscribeTopics = [this.stateTopic];
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
@ -13,6 +14,10 @@ class M433SwitchItem extends AItem_1.AItem {
this.oldState = undefined;
this.onCode = onCode;
this.offCode = offCode;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
this.state = payload;

110
dist/main.js vendored
View File

@ -1,5 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const config = require("./config");
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const M433SwitchItem_1 = require("./M433SwitchItem");
@ -10,10 +12,95 @@ const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
const Forwarder_1 = require("./Forwarder");
logger.info("Dispatcher starting");
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
let allLabeledItems = new Array();
// Anna -----------------------------------------------------------------------------------------------------
// Anna Aquarium 14665044 24 1 14665041 24 1
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', 'Aquariumlicht', '14665044 24 1', '14665041 24 1');
aquariumLight.start();
let deskLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1');
deskLight.start();
allLabeledItems.push(aquariumLight);
// Anna Bett 14668116 24 1 14668113 24 1
let annaBedLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1');
annaBedLight.start();
allLabeledItems.push(annaBedLight);
// Matthias -------------------------------------------------------------------------------------------------
// Matthias Stehlampen 7 24 1 6 24 1
let matthiasStandLights = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'Stehlampen Matthias', 'StandLight', '7 24 1', '6 24 1');
matthiasStandLights.start();
allLabeledItems.push(matthiasStandLights);
// Matthias Bett 15 24 1 14 24 1
let matthiasBedLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1');
matthiasBedLight.start();
allLabeledItems.push(matthiasBedLight);
// Matthias Lautsprecher 11 24 1 10 24 1
let matthiasSpeaker = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet');
matthiasSpeaker.start();
allLabeledItems.push(matthiasSpeaker);
// Esszimmer ------------------------------------------------------------------------------------------------
// Esszimmer kleine Lampe 69653 24 1 69652 24 1
let diningRoomSmallLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1');
diningRoomSmallLight.start();
allLabeledItems.push(diningRoomSmallLight);
// Esszimmer Stehlampe 86037 24 1 86036 24 1
let diningRoomStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1');
diningRoomStandLight.start();
allLabeledItems.push(diningRoomStandLight);
// Esszimmer Schranklicht 65813 24 1 65812 24 1
let diningRoomCupboardLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1');
diningRoomCupboardLight.start();
allLabeledItems.push(diningRoomCupboardLight);
// Wohnzimmer -----------------------------------------------------------------------------------------------
// Wohnzimmer grosse Lampe 65557 24 1 65556 24 1
let livingRoomLargeLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1');
livingRoomLargeLight.start();
allLabeledItems.push(livingRoomLargeLight);
// Wohnzimmer kleine Lampe 87061 24 1 87060 24 1
let livingRoomSmallLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1');
livingRoomSmallLight.start();
allLabeledItems.push(livingRoomSmallLight);
// Wohnzimmer Sterne 69909 24 1 69908 24 1
let livingRoomStars = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1');
livingRoomStars.start();
allLabeledItems.push(livingRoomStars);
// Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1
let livingRoomStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1');
livingRoomStandLight.start();
allLabeledItems.push(livingRoomStandLight);
// Flur -----------------------------------------------------------------------------------------------------
// Flur Schreibtisch 83221 24 1 83220 24 1
let hallwayDeskLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1');
hallwayDeskLight.start();
allLabeledItems.push(hallwayDeskLight);
// Flur Stehlampe 8704914 24 5 8793154 24 5
let hallwayStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5');
hallwayStandLight.start();
allLabeledItems.push(hallwayStandLight);
// Flur Schranklicht 66581 24 1 66580 24 1
let hallwayWardrobeLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1');
hallwayWardrobeLight.start();
allLabeledItems.push(hallwayWardrobeLight);
// Küche ----------------------------------------------------------------------------------------------------
// Küche Fensterbank 66837 24 1 66836 24 1
let kitchenWindowLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1');
kitchenWindowLight.start();
allLabeledItems.push(kitchenWindowLight);
// Küche Deckenlampe 82197 24 1 82196 24 1
let kitchenCeilingLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1');
kitchenWindowLight.start();
allLabeledItems.push(kitchenCeilingLight);
// Schlafzimmer ---------------------------------------------------------------------------------------------
// Schlafzimmer Wolfgangs Seite 13976916 24 1 13976913 24 1
let bedRoomWolfgangsSide = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1');
bedRoomWolfgangsSide.start();
allLabeledItems.push(bedRoomWolfgangsSide);
// Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1
let bedRoomPattysSide = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1');
bedRoomPattysSide.start();
allLabeledItems.push(bedRoomPattysSide);
// Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1
let bedRoomWindowLight = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1');
bedRoomWindowLight.start();
allLabeledItems.push(bedRoomWindowLight);
// ----------------------------------------------------------------------------------------------------------
let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
@ -25,15 +112,26 @@ let testDimmerAdaptor = new DimmerAdaptor_1.DimmerAdaptor('Gnd', 'Hallway', 'Tes
testDimmerAdaptor.start();
let testTimerAdaptor = new TimerAdaptor_1.TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10);
testTimerAdaptor.start();
let testLight = new HomematicDimmerItem_1.HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8);
let testLight = new HomematicDimmerItem_1.HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 'Testlampe mit Dimmer', 8);
testLight.start();
let testLight2 = new HomematicSwitchItem_1.HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5);
let testLight2 = new HomematicSwitchItem_1.HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 'Testlampe ohne Dimmer', 5);
testLight2.start();
let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', 'TestForwarder', [
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
]);
testForwarder.start();
// ----------------------------------------------------------------------------------------------------------
// Homekit export
let homekitObject = {};
allLabeledItems.forEach((item) => {
let homekitExport = item.exportHomekit();
if ('id' in homekitExport) {
homekitObject[homekitExport['id']] = homekitExport['object'];
}
});
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4));
// ----------------------------------------------------------------------------------------------------------
MqttDispatcher_1.mqttHandler.exec();
logger.info("Dispatcher running");
//# sourceMappingURL=main.js.map