From 8350b21161d146eff9038dc419dfbf062d0f1580 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 3 Apr 2018 00:00:42 +0200 Subject: [PATCH] export relaybox --- dist/Export.js | 16 +++++---- dist/RelayBox.js | 2 +- dist/main.js | 85 ++++++++++++++++++++++++------------------------ src/Export.ts | 18 ++++++---- src/RelayBox.ts | 2 +- src/main.ts | 85 ++++++++++++++++++++++++------------------------ 6 files changed, 109 insertions(+), 99 deletions(-) diff --git a/dist/Export.js b/dist/Export.js index 7299cfc..bae4777 100644 --- a/dist/Export.js +++ b/dist/Export.js @@ -28,16 +28,20 @@ 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) }; +function RelayBoxExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { + return { 'homekit': RelayBoxHomekitExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames), + 'openhab': RelayBoxOpenHABExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) }; } exports.RelayBoxExport = RelayBoxExport; -function RelayBoxHomekitExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { +function RelayBoxHomekitExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { return { 'id': '', 'object': {} }; } -function RelayBoxOpenHABExport(stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { - return ''; +function RelayBoxOpenHABExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames) { + let o = []; + itemNames.forEach((label, index) => { + o.push(`Switch ${itemId}${index} "${label} "{mqtt=">[localbroker:${stateTopicPre}/${index}:command:*:default],<[localbroker:${feedbackTopicPre}/${index}:state:default]"}`); + }); + return o; } function SwitchHomekitBulbExport(id, label, setOn, statusOn) { let o = { diff --git a/dist/RelayBox.js b/dist/RelayBox.js index f58023d..28e2b28 100644 --- a/dist/RelayBox.js +++ b/dist/RelayBox.js @@ -20,7 +20,7 @@ class RelayBoxThing extends AItem_1.AItem { this.oldSwitchStates = ''; } exportItem() { - return Export_1.RelayBoxExport(this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames); + return Export_1.RelayBoxExport(this.itemId, this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames); } processMessage(topic, payload) { // logger.info(`RT: ${topic}, ${payload}`) diff --git a/dist/main.js b/dist/main.js index dd1a149..c32a8a8 100644 --- a/dist/main.js +++ b/dist/main.js @@ -26,7 +26,7 @@ let allLabeledItems = new Array(); // 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(); -allLabeledItems.push(aquariumLight); +allLabeledItems.concat(aquariumLight); let aquariumLightCron = new Cron_1.Cron('aquariumLightCron', aquariumLight, [ { cronTime: '00 00 07 * * 1-5', output: 'ON' }, { cronTime: '00 00 09 * * 6,0', output: 'ON' }, @@ -38,13 +38,13 @@ aquariumLightCron.start(); // 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); +allLabeledItems.concat(annaBedLight); let windowContactAnna1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Anna', 'WindowContact', 'Fenster Anna', 20); windowContactAnna1st.start(); -allLabeledItems.push(windowContactAnna1st); +allLabeledItems.concat(windowContactAnna1st); let thermostatAnna1st = new MaxThermostat_1.MaxThermostat('1st', 'Anna', 'Thermostat', 'Thermostat Anna', 21, [windowContactAnna1st]); thermostatAnna1st.start(); -allLabeledItems.push(thermostatAnna1st); +allLabeledItems.concat(thermostatAnna1st); let thermostatAnna1stCron = new Cron_1.Cron('thermostatAnna1stCron', thermostatAnna1st, [ { cronTime: '00 05 06 * * *', output: '23.0' }, { cronTime: '00 05 08 * * 1-5', output: '5.0' }, @@ -60,82 +60,82 @@ thermostatAnna1stCron.start(); // Matthias Stehlampen 7 24 1 6 24 1 let matthiasStandLights = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'StandLight', 'Stehlampen Matthias', '7 24 1', '6 24 1'); matthiasStandLights.start(); -allLabeledItems.push(matthiasStandLights); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(diningRoomCupboardLight); // Esszimmer Regallicht let diningRoomShelfLight = new UrlSwitchItem_1.UrlSwitchItem('Gnd', 'DiningRoom', 'ShelfLight', 'Regallicht Esszimmer', 'http://regallampe/dv?dv=1023', 'http://regallampe/dv?dv=0'); diningRoomShelfLight.start(); -allLabeledItems.push(diningRoomShelfLight); +allLabeledItems.concat(diningRoomShelfLight); let diningRoomNaehkaestchenLight = new HueColorBulbItem_1.HueColorBulbItem('Gnd', 'DiningRoom', 'NaehkaestchenLight', 'Lampe Naehkaestchen', 15); diningRoomNaehkaestchenLight.start(); -allLabeledItems.push(diningRoomNaehkaestchenLight); +allLabeledItems.concat(diningRoomNaehkaestchenLight); // 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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(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); +allLabeledItems.concat(hallwayStandLight); // Flur Schranklicht 66581 24 1 66580 24 1 let hallwayWardrobeLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'WardrobeLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1'); hallwayWardrobeLight.start(); -allLabeledItems.push(hallwayWardrobeLight); +allLabeledItems.concat(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); +allLabeledItems.concat(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'); kitchenCeilingLight.start(); -allLabeledItems.push(kitchenCeilingLight); +allLabeledItems.concat(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); +allLabeledItems.concat(bedRoomWolfgangsSide); let bedRoomWolfgangBedLight = new HueColorBulbItem_1.HueColorBulbItem('1st', 'BedRoom', 'WolfgangBedLight', 'Bettlicht', 16); bedRoomWolfgangBedLight.start(); -allLabeledItems.push(bedRoomWolfgangBedLight); +allLabeledItems.concat(bedRoomWolfgangBedLight); let bedRoomWolfgangBedLightDimmerAdaptor = new DimmerAdaptor_1.DimmerAdaptor('1st', 'BedRoom', 'WolfgangBedLight'); bedRoomWolfgangBedLightDimmerAdaptor.start(); let touchSwitchMultiButtonThing = new TouchSwitchMultiButtonThing_1.TouchSwitchMultiButtonThing('1st', 'Bedroom', 'Wolfgang', [new TouchSwitchMultiButtonThing_1.TouchSwitchButtonSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic())]); @@ -143,23 +143,23 @@ touchSwitchMultiButtonThing.start(); // 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); +allLabeledItems.concat(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); +allLabeledItems.concat(bedRoomWindowLight); let windowContactBedroomStreet1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Bedroom', 'WindowContactStreet', 'Fenster Schlafzimmer Strasse', 17); windowContactBedroomStreet1st.start(); -allLabeledItems.push(windowContactBedroomStreet1st); +allLabeledItems.concat(windowContactBedroomStreet1st); let windowContact1BedroomGarden1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Bedroom', 'WindowContact1Garden', 'Fenster Schlafzimmer 1 Garten', 18); windowContact1BedroomGarden1st.start(); -allLabeledItems.push(windowContact1BedroomGarden1st); +allLabeledItems.concat(windowContact1BedroomGarden1st); let windowContact2BedroomGarden1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Bedroom', 'WindowContact2Garden', 'Fenster Schlafzimmer 2 Garten', 22); windowContact2BedroomGarden1st.start(); -allLabeledItems.push(windowContact2BedroomGarden1st); +allLabeledItems.concat(windowContact2BedroomGarden1st); let thermostatBedroom1st = new MaxThermostat_1.MaxThermostat('1st', 'Bedroom', 'Thermostat', 'Thermostat Schlafzimmer', 19, [windowContact1BedroomGarden1st, windowContact2BedroomGarden1st, windowContactBedroomStreet1st]); thermostatBedroom1st.start(); -allLabeledItems.push(thermostatBedroom1st); +allLabeledItems.concat(thermostatBedroom1st); let thermostatBedroom1stCron = new Cron_1.Cron('thermostatBedroom1stCron', thermostatBedroom1st, [ { cronTime: '00 01 06 * * 1-5', output: '19.0' }, { cronTime: '00 01 09 * * 1-5', output: '5.0' }, @@ -176,7 +176,7 @@ let dayLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'DayLight', 'DayLig livingRoomLargeLight, livingRoomSmallLight, livingRoomStars, livingRoomStandLight, diningRoomNaehkaestchenLight ], []); dayLightScene.start(); -allLabeledItems.push(dayLightScene); +allLabeledItems.concat(dayLightScene); let ecoLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight', [ kitchenWindowLight, hallwayDeskLight, hallwayWardrobeLight, diningRoomSmallLight, diningRoomStandLight, diningRoomCupboardLight, diningRoomShelfLight, @@ -186,7 +186,7 @@ let ecoLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLig livingRoomLargeLight, livingRoomSmallLight ]); ecoLightScene.start(); -allLabeledItems.push(ecoLightScene); +allLabeledItems.concat(ecoLightScene); let ecoSwitch = new MaxEcoSwitch_1.MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 6, dayLightScene, ecoLightScene); ecoSwitch.start(); let morningLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'MorningLight', 'MorningLight', [ @@ -197,14 +197,14 @@ let morningLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'MorningLight', livingRoomStars, livingRoomStandLight, livingRoomLargeLight, livingRoomSmallLight, diningRoomNaehkaestchenLight ]); morningLightScene.start(); -allLabeledItems.push(morningLightScene); +allLabeledItems.concat(morningLightScene); // ---------------------------------------------------------------------------------------------------------- let windowContactBathroomGnd = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Bathroom', 'WindowContact', 'Fenster Bad unten', 7); windowContactBathroomGnd.start(); -allLabeledItems.push(windowContactBathroomGnd); +allLabeledItems.concat(windowContactBathroomGnd); let thermostatBathroomGnd = new MaxThermostat_1.MaxThermostat('Gnd', 'Bathroom', 'Thermostat', 'Thermostat Bad unten', 4, [windowContactBathroomGnd]); thermostatBathroomGnd.start(); -allLabeledItems.push(thermostatBathroomGnd); +allLabeledItems.concat(thermostatBathroomGnd); let thermostatBathroomGndCron = new Cron_1.Cron('thermostatBathroomGndCron', thermostatBathroomGnd, [ { cronTime: '00 02 06 * * 1-5', output: '21.0' }, { cronTime: '00 02 08 * * 6,0', output: '21.0' }, @@ -215,10 +215,10 @@ let thermostatBathroomGndCron = new Cron_1.Cron('thermostatBathroomGndCron', the thermostatBathroomGndCron.start(); let windowContactBathroom1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Bathroom', 'WindowContact', 'Fenster Bad oben', 2); windowContactBathroom1st.start(); -allLabeledItems.push(windowContactBathroom1st); +allLabeledItems.concat(windowContactBathroom1st); let thermostatBathroom1st = new MaxThermostat_1.MaxThermostat('1st', 'Bathroom', 'Thermostat', 'Thermostat Bad oben', 3, [windowContactBathroom1st]); thermostatBathroom1st.start(); -allLabeledItems.push(thermostatBathroom1st); +allLabeledItems.concat(thermostatBathroom1st); let thermostatBathroom1stCron = new Cron_1.Cron('thermostatBathroom1stCron', thermostatBathroom1st, [ { cronTime: '00 00 06 * * 1-5', output: '21.0' }, { cronTime: '00 00 08 * * 6,0', output: '21.0' }, @@ -229,21 +229,21 @@ let thermostatBathroom1stCron = new Cron_1.Cron('thermostatBathroom1stCron', the thermostatBathroom1stCron.start(); let windowContactKitchen1 = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Kitchen', 'WindowContact1', 'Fenster Küche Garten', 11); windowContactKitchen1.start(); -allLabeledItems.push(windowContactKitchen1); +allLabeledItems.concat(windowContactKitchen1); let windowContactKitchen2 = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Kitchen', 'WindowContact2', 'Fenster Küche Terassentür Garten', 10); windowContactKitchen2.start(); -allLabeledItems.push(windowContactKitchen2); +allLabeledItems.concat(windowContactKitchen2); let windowContactKitchen3 = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Kitchen', 'WindowContact3', 'Fenster Küche Straße 1', 12); windowContactKitchen3.start(); -allLabeledItems.push(windowContactKitchen3); +allLabeledItems.concat(windowContactKitchen3); let windowContactKitchen4 = new MaxWindowContact_1.MaxWindowContact('Gnd', 'Kitchen', 'WindowContact4', 'Fenster Küche Straße 2', 13); windowContactKitchen4.start(); -allLabeledItems.push(windowContactKitchen4); +allLabeledItems.concat(windowContactKitchen4); let thermostatKitchen = new MaxThermostat_1.MaxThermostat('Gnd', 'Kitchen', 'Thermostat', 'Thermostat Küche', 14, [ windowContactKitchen1, windowContactKitchen2, windowContactKitchen3, windowContactKitchen4 ]); thermostatKitchen.start(); -allLabeledItems.push(thermostatKitchen); +allLabeledItems.concat(thermostatKitchen); let thermostatKitchenCron = new Cron_1.Cron('thermostatKitchenCron', thermostatKitchen, [ { cronTime: '00 00 06 * * 1-5', output: '19.0' }, { cronTime: '00 00 08 * * 6,0', output: '19.0' }, @@ -257,6 +257,7 @@ let relayBox = new RelayBox_1.RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Co "Küche", "Herd", "Waschküche" ]); relayBox.start(); +allLabeledItems.concat(relayBox); // ---------------------------------------------------------------------------------------------------------- let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [ new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'), @@ -290,7 +291,7 @@ allLabeledItems.forEach((item) => { if ('id' in exportData['homekit']) { homekitObject[exportData['homekit']['id']] = exportData['homekit']['object']; } - openhabList.push(exportData['openhab']); + openhabList.concat(exportData['openhab']); } }); fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4)); diff --git a/src/Export.ts b/src/Export.ts index fb12653..89e51b5 100644 --- a/src/Export.ts +++ b/src/Export.ts @@ -1,6 +1,6 @@ export type ExportType = { 'homekit': HomekitExportType, - 'openhab': string + 'openhab': string | string[] } export type HomekitExportType = { @@ -46,17 +46,21 @@ export function HueColorLightExport(itemId: string, label: string, 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)} +export function RelayBoxExport(itemId: string, stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : ExportType { + return {'homekit': RelayBoxHomekitExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames), + 'openhab': RelayBoxOpenHABExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames)} } -function RelayBoxHomekitExport(stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : HomekitExportType{ +function RelayBoxHomekitExport(itemId: string, 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 RelayBoxOpenHABExport(itemId: string, stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : string[] { + let o : string[] = [] + itemNames.forEach((label: string, index: number) => { + o.push(`Switch ${itemId}${index} "${label} "{mqtt=">[localbroker:${stateTopicPre}/${index}:command:*:default],<[localbroker:${feedbackTopicPre}/${index}:state:default]"}`) + }) + return o } diff --git a/src/RelayBox.ts b/src/RelayBox.ts index a3fbe19..0294c03 100644 --- a/src/RelayBox.ts +++ b/src/RelayBox.ts @@ -33,7 +33,7 @@ export class RelayBoxThing extends AItem { } exportItem() : ExportType|null { - return RelayBoxExport(this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames) + return RelayBoxExport(this.itemId, this.stateTopicPre, this.feedbackTopicPre, this.conflictTopicPre, this.itemNames) } processMessage(topic: string, payload: string) { diff --git a/src/main.ts b/src/main.ts index c521581..1f9a4e6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,7 +33,7 @@ let allLabeledItems : Array = new Array() // Anna Aquarium 14665044 24 1 14665041 24 1 let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', 'Aquariumlicht', '14665044 24 1', '14665041 24 1') aquariumLight.start() -allLabeledItems.push(aquariumLight) +allLabeledItems.concat(aquariumLight) let aquariumLightCron = new Cron('aquariumLightCron', aquariumLight, [ {cronTime: '00 00 07 * * 1-5', output: 'ON'}, @@ -48,16 +48,16 @@ aquariumLightCron.start() // Anna Bett 14668116 24 1 14668113 24 1 let annaBedLight = new M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1') annaBedLight.start() -allLabeledItems.push(annaBedLight) +allLabeledItems.concat(annaBedLight) let windowContactAnna1st = new MaxWindowContact('1st', 'Anna', 'WindowContact', 'Fenster Anna', 20) windowContactAnna1st.start() -allLabeledItems.push(windowContactAnna1st) +allLabeledItems.concat(windowContactAnna1st) let thermostatAnna1st = new MaxThermostat('1st', 'Anna', 'Thermostat', 'Thermostat Anna', 21, [windowContactAnna1st]) thermostatAnna1st.start() -allLabeledItems.push(thermostatAnna1st) +allLabeledItems.concat(thermostatAnna1st) let thermostatAnna1stCron = new Cron('thermostatAnna1stCron', thermostatAnna1st, [ {cronTime: '00 05 06 * * *', output: '23.0'}, @@ -75,103 +75,103 @@ thermostatAnna1stCron.start() // Matthias Stehlampen 7 24 1 6 24 1 let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'StandLight', 'Stehlampen Matthias', '7 24 1', '6 24 1') matthiasStandLights.start() -allLabeledItems.push(matthiasStandLights) +allLabeledItems.concat(matthiasStandLights) // Matthias Bett 15 24 1 14 24 1 let matthiasBedLight = new M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1') matthiasBedLight.start() -allLabeledItems.push(matthiasBedLight) +allLabeledItems.concat(matthiasBedLight) // Matthias Lautsprecher 11 24 1 10 24 1 let matthiasSpeaker = new M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet') matthiasSpeaker.start() -allLabeledItems.push(matthiasSpeaker) +allLabeledItems.concat(matthiasSpeaker) // Esszimmer ------------------------------------------------------------------------------------------------ // Esszimmer kleine Lampe 69653 24 1 69652 24 1 let diningRoomSmallLight = new M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1') diningRoomSmallLight.start() -allLabeledItems.push(diningRoomSmallLight) +allLabeledItems.concat(diningRoomSmallLight) // Esszimmer Stehlampe 86037 24 1 86036 24 1 let diningRoomStandLight = new M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1') diningRoomStandLight.start() -allLabeledItems.push(diningRoomStandLight) +allLabeledItems.concat(diningRoomStandLight) // Esszimmer Schranklicht 65813 24 1 65812 24 1 let diningRoomCupboardLight = new M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1') diningRoomCupboardLight.start() -allLabeledItems.push(diningRoomCupboardLight) +allLabeledItems.concat(diningRoomCupboardLight) // Esszimmer Regallicht let diningRoomShelfLight = new UrlSwitchItem('Gnd', 'DiningRoom', 'ShelfLight', 'Regallicht Esszimmer', 'http://regallampe/dv?dv=1023', 'http://regallampe/dv?dv=0') diningRoomShelfLight.start() -allLabeledItems.push(diningRoomShelfLight) +allLabeledItems.concat(diningRoomShelfLight) let diningRoomNaehkaestchenLight = new HueColorBulbItem('Gnd', 'DiningRoom', 'NaehkaestchenLight', 'Lampe Naehkaestchen', 15) diningRoomNaehkaestchenLight.start() -allLabeledItems.push(diningRoomNaehkaestchenLight) +allLabeledItems.concat(diningRoomNaehkaestchenLight) // Wohnzimmer ----------------------------------------------------------------------------------------------- // Wohnzimmer grosse Lampe 65557 24 1 65556 24 1 let livingRoomLargeLight = new M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1') livingRoomLargeLight.start() -allLabeledItems.push(livingRoomLargeLight) +allLabeledItems.concat(livingRoomLargeLight) // Wohnzimmer kleine Lampe 87061 24 1 87060 24 1 let livingRoomSmallLight = new M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1') livingRoomSmallLight.start() -allLabeledItems.push(livingRoomSmallLight) +allLabeledItems.concat(livingRoomSmallLight) // Wohnzimmer Sterne 69909 24 1 69908 24 1 let livingRoomStars = new M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1') livingRoomStars.start() -allLabeledItems.push(livingRoomStars) +allLabeledItems.concat(livingRoomStars) // Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1 let livingRoomStandLight = new M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1') livingRoomStandLight.start() -allLabeledItems.push(livingRoomStandLight) +allLabeledItems.concat(livingRoomStandLight) // Flur ----------------------------------------------------------------------------------------------------- // Flur Schreibtisch 83221 24 1 83220 24 1 let hallwayDeskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1') hallwayDeskLight.start() -allLabeledItems.push(hallwayDeskLight) +allLabeledItems.concat(hallwayDeskLight) // Flur Stehlampe 8704914 24 5 8793154 24 5 let hallwayStandLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5') hallwayStandLight.start() -allLabeledItems.push(hallwayStandLight) +allLabeledItems.concat(hallwayStandLight) // Flur Schranklicht 66581 24 1 66580 24 1 let hallwayWardrobeLight = new M433SwitchItem('Gnd', 'Hallway', 'WardrobeLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1') hallwayWardrobeLight.start() -allLabeledItems.push(hallwayWardrobeLight) +allLabeledItems.concat(hallwayWardrobeLight) // Küche ---------------------------------------------------------------------------------------------------- // Küche Fensterbank 66837 24 1 66836 24 1 let kitchenWindowLight = new M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1') kitchenWindowLight.start() -allLabeledItems.push(kitchenWindowLight) +allLabeledItems.concat(kitchenWindowLight) // Küche Deckenlampe 82197 24 1 82196 24 1 let kitchenCeilingLight = new M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1') kitchenCeilingLight.start() -allLabeledItems.push(kitchenCeilingLight) +allLabeledItems.concat(kitchenCeilingLight) // Schlafzimmer --------------------------------------------------------------------------------------------- // Schlafzimmer Wolfgangs Seite 13976916 24 1 13976913 24 1 let bedRoomWolfgangsSide = new M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1') bedRoomWolfgangsSide.start() -allLabeledItems.push(bedRoomWolfgangsSide) +allLabeledItems.concat(bedRoomWolfgangsSide) let bedRoomWolfgangBedLight = new HueColorBulbItem('1st', 'BedRoom', 'WolfgangBedLight', 'Bettlicht', 16) bedRoomWolfgangBedLight.start() -allLabeledItems.push(bedRoomWolfgangBedLight) +allLabeledItems.concat(bedRoomWolfgangBedLight) let bedRoomWolfgangBedLightDimmerAdaptor = new DimmerAdaptor('1st', 'BedRoom', 'WolfgangBedLight') bedRoomWolfgangBedLightDimmerAdaptor.start() @@ -183,28 +183,28 @@ touchSwitchMultiButtonThing.start() // Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1 let bedRoomPattysSide = new M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1') bedRoomPattysSide.start() -allLabeledItems.push(bedRoomPattysSide) +allLabeledItems.concat(bedRoomPattysSide) // Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1 let bedRoomWindowLight = new M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1') bedRoomWindowLight.start() -allLabeledItems.push(bedRoomWindowLight) +allLabeledItems.concat(bedRoomWindowLight) let windowContactBedroomStreet1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContactStreet', 'Fenster Schlafzimmer Strasse', 17) windowContactBedroomStreet1st.start() -allLabeledItems.push(windowContactBedroomStreet1st) +allLabeledItems.concat(windowContactBedroomStreet1st) let windowContact1BedroomGarden1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContact1Garden', 'Fenster Schlafzimmer 1 Garten', 18) windowContact1BedroomGarden1st.start() -allLabeledItems.push(windowContact1BedroomGarden1st) +allLabeledItems.concat(windowContact1BedroomGarden1st) let windowContact2BedroomGarden1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContact2Garden', 'Fenster Schlafzimmer 2 Garten', 22) windowContact2BedroomGarden1st.start() -allLabeledItems.push(windowContact2BedroomGarden1st) +allLabeledItems.concat(windowContact2BedroomGarden1st) let thermostatBedroom1st = new MaxThermostat('1st', 'Bedroom', 'Thermostat', 'Thermostat Schlafzimmer', 19, [windowContact1BedroomGarden1st, windowContact2BedroomGarden1st, windowContactBedroomStreet1st]) thermostatBedroom1st.start() -allLabeledItems.push(thermostatBedroom1st) +allLabeledItems.concat(thermostatBedroom1st) let thermostatBedroom1stCron = new Cron('thermostatBedroom1stCron', thermostatBedroom1st, [ {cronTime: '00 01 06 * * 1-5', output: '19.0'}, @@ -226,7 +226,7 @@ let dayLightScene = new LightScene('Gnd', 'Hallway', 'DayLight', 'DayLight', [] ) dayLightScene.start() -allLabeledItems.push(dayLightScene) +allLabeledItems.concat(dayLightScene) let ecoLightScene = new LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight', [ @@ -240,7 +240,7 @@ let ecoLightScene = new LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight', ] ) ecoLightScene.start() -allLabeledItems.push(ecoLightScene) +allLabeledItems.concat(ecoLightScene) let ecoSwitch = new MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 6, dayLightScene, ecoLightScene) ecoSwitch.start() @@ -256,17 +256,17 @@ let morningLightScene = new LightScene('Gnd', 'Hallway', 'MorningLight', 'Mornin ] ) morningLightScene.start() -allLabeledItems.push(morningLightScene) +allLabeledItems.concat(morningLightScene) // ---------------------------------------------------------------------------------------------------------- let windowContactBathroomGnd = new MaxWindowContact('Gnd', 'Bathroom', 'WindowContact', 'Fenster Bad unten', 7) windowContactBathroomGnd.start() -allLabeledItems.push(windowContactBathroomGnd) +allLabeledItems.concat(windowContactBathroomGnd) let thermostatBathroomGnd = new MaxThermostat('Gnd', 'Bathroom', 'Thermostat', 'Thermostat Bad unten', 4, [windowContactBathroomGnd]) thermostatBathroomGnd.start() -allLabeledItems.push(thermostatBathroomGnd) +allLabeledItems.concat(thermostatBathroomGnd) let thermostatBathroomGndCron = new Cron('thermostatBathroomGndCron', thermostatBathroomGnd, [ {cronTime: '00 02 06 * * 1-5', output: '21.0'}, @@ -280,11 +280,11 @@ thermostatBathroomGndCron.start() let windowContactBathroom1st = new MaxWindowContact('1st', 'Bathroom', 'WindowContact', 'Fenster Bad oben', 2) windowContactBathroom1st.start() -allLabeledItems.push(windowContactBathroom1st) +allLabeledItems.concat(windowContactBathroom1st) let thermostatBathroom1st = new MaxThermostat('1st', 'Bathroom', 'Thermostat', 'Thermostat Bad oben', 3, [windowContactBathroom1st]) thermostatBathroom1st.start() -allLabeledItems.push(thermostatBathroom1st) +allLabeledItems.concat(thermostatBathroom1st) let thermostatBathroom1stCron = new Cron('thermostatBathroom1stCron', thermostatBathroom1st, [ {cronTime: '00 00 06 * * 1-5', output: '21.0'}, @@ -299,21 +299,21 @@ thermostatBathroom1stCron.start() let windowContactKitchen1 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact1', 'Fenster Küche Garten', 11) windowContactKitchen1.start() -allLabeledItems.push(windowContactKitchen1) +allLabeledItems.concat(windowContactKitchen1) let windowContactKitchen2 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact2', 'Fenster Küche Terassentür Garten', 10) windowContactKitchen2.start() -allLabeledItems.push(windowContactKitchen2) +allLabeledItems.concat(windowContactKitchen2) let windowContactKitchen3 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact3', 'Fenster Küche Straße 1', 12) windowContactKitchen3.start() -allLabeledItems.push(windowContactKitchen3) +allLabeledItems.concat(windowContactKitchen3) let windowContactKitchen4 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact4', 'Fenster Küche Straße 2', 13) windowContactKitchen4.start() -allLabeledItems.push(windowContactKitchen4) +allLabeledItems.concat(windowContactKitchen4) let thermostatKitchen = new MaxThermostat('Gnd', 'Kitchen', 'Thermostat', 'Thermostat Küche', 14, [ windowContactKitchen1, windowContactKitchen2, windowContactKitchen3, windowContactKitchen4]) thermostatKitchen.start() -allLabeledItems.push(thermostatKitchen) +allLabeledItems.concat(thermostatKitchen) let thermostatKitchenCron = new Cron('thermostatKitchenCron', thermostatKitchen, [ {cronTime: '00 00 06 * * 1-5', output: '19.0'}, @@ -329,6 +329,7 @@ let relayBox = new RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Command/Relay "Küche", "Herd", "Waschküche" ]) relayBox.start() +allLabeledItems.concat(relayBox) // ---------------------------------------------------------------------------------------------------------- let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [ @@ -377,7 +378,7 @@ allLabeledItems.forEach((item: AItem) => { if ('id' in exportData['homekit']) { homekitObject[exportData['homekit']['id']] = exportData['homekit']['object'] } - openhabList.push(exportData['openhab']) + openhabList.concat(exportData['openhab']) } }) fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))