From 677f9c807db5b104e3c823c845a0f0ed9122a183 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 12 Jan 2018 22:02:08 +0100 Subject: [PATCH] fixes and start of UrlSwitchItem --- dist/AItem.js | 2 +- dist/Export.js | 2 +- dist/main.js | 2 +- homekit.json | 98 ++++++++++++++++++++++---------------------- openhab.items | 46 ++++++++++----------- src/AItem.ts | 2 +- src/Export.ts | 4 +- src/UrlSwitchItem.ts | 55 +++++++++++++++++++++++++ src/main.ts | 2 +- 9 files changed, 134 insertions(+), 79 deletions(-) create mode 100644 src/UrlSwitchItem.ts diff --git a/dist/AItem.js b/dist/AItem.js index bb267dd..4e3548d 100644 --- a/dist/AItem.js +++ b/dist/AItem.js @@ -7,7 +7,7 @@ class AItem { this.floor = floor; this.room = room; this.item = item; - this.itemId = `${this.floor}.${this.room}.${this.item}`; + this.itemId = `${this.floor}_${this.room}_${this.item}`; if (label == '') { this.label = this.itemId; } diff --git a/dist/Export.js b/dist/Export.js index f1768b0..d50899a 100644 --- a/dist/Export.js +++ b/dist/Export.js @@ -55,6 +55,6 @@ function SwitchHomekitOutletExport(id, label, setOn, statusOn) { } 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]"}`; + return `Switch ${id} {mqtt=">[localbroker:${setOn}:command:*:default],<[localbroker:${statusOn}:state:default]"}`; } //# sourceMappingURL=Export.js.map \ No newline at end of file diff --git a/dist/main.js b/dist/main.js index 330b4b3..cc4eef0 100644 --- a/dist/main.js +++ b/dist/main.js @@ -26,7 +26,7 @@ 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'); +let matthiasStandLights = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'StandLight', 'Stehlampen Matthias', '7 24 1', '6 24 1'); matthiasStandLights.start(); allLabeledItems.push(matthiasStandLights); // Matthias Bett 15 24 1 14 24 1 diff --git a/homekit.json b/homekit.json index cd4e2ce..ff20c8c 100644 --- a/homekit.json +++ b/homekit.json @@ -1,6 +1,6 @@ { - "1st.Anna.AquariumLight": { - "id": "1st.Anna.AquariumLight", + "1st_Anna_AquariumLight": { + "id": "1st_Anna_AquariumLight", "name": "Aquariumlicht", "service": "Lightbulb", "topic": { @@ -16,8 +16,8 @@ }, "config": {} }, - "1st.Anna.BedLight": { - "id": "1st.Anna.BedLight", + "1st_Anna_BedLight": { + "id": "1st_Anna_BedLight", "name": "Bettlicht Anna", "service": "Lightbulb", "topic": { @@ -33,13 +33,13 @@ }, "config": {} }, - "1st.Matthias.Stehlampen Matthias": { - "id": "1st.Matthias.Stehlampen Matthias", - "name": "StandLight", + "1st_Matthias_StandLight": { + "id": "1st_Matthias_StandLight", + "name": "Stehlampen Matthias", "service": "Lightbulb", "topic": { - "setOn": "dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state", - "statusOn": "dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state/feedback" + "setOn": "dispatcher_ng/items/1st/Matthias/StandLight/state", + "statusOn": "dispatcher_ng/items/1st/Matthias/StandLight/state/feedback" }, "payload": { "onTrue": "ON", @@ -50,8 +50,8 @@ }, "config": {} }, - "1st.Matthias.BedLight": { - "id": "1st.Matthias.BedLight", + "1st_Matthias_BedLight": { + "id": "1st_Matthias_BedLight", "name": "Bettlicht Matthias", "service": "Lightbulb", "topic": { @@ -67,8 +67,8 @@ }, "config": {} }, - "1st.Matthias.Speaker": { - "id": "1st.Matthias.Speaker", + "1st_Matthias_Speaker": { + "id": "1st_Matthias_Speaker", "name": "Lautsprecher Matthias", "service": "Outlet", "topic": { @@ -81,8 +81,8 @@ }, "config": {} }, - "Gnd.DiningRoom.SmallLight": { - "id": "Gnd.DiningRoom.SmallLight", + "Gnd_DiningRoom_SmallLight": { + "id": "Gnd_DiningRoom_SmallLight", "name": "kleine Lampe Esszimmer", "service": "Lightbulb", "topic": { @@ -98,8 +98,8 @@ }, "config": {} }, - "Gnd.DiningRoom.StandLight": { - "id": "Gnd.DiningRoom.StandLight", + "Gnd_DiningRoom_StandLight": { + "id": "Gnd_DiningRoom_StandLight", "name": "Stehlampe Esszimmer", "service": "Lightbulb", "topic": { @@ -115,8 +115,8 @@ }, "config": {} }, - "Gnd.DiningRoom.CupboardLight": { - "id": "Gnd.DiningRoom.CupboardLight", + "Gnd_DiningRoom_CupboardLight": { + "id": "Gnd_DiningRoom_CupboardLight", "name": "Schranklicht Esszimmer", "service": "Lightbulb", "topic": { @@ -132,8 +132,8 @@ }, "config": {} }, - "Gnd.LivingRoom.LargeLight": { - "id": "Gnd.LivingRoom.LargeLight", + "Gnd_LivingRoom_LargeLight": { + "id": "Gnd_LivingRoom_LargeLight", "name": "große Lampe Wohnzimmer", "service": "Lightbulb", "topic": { @@ -149,8 +149,8 @@ }, "config": {} }, - "Gnd.LivingRoom.SmallLight": { - "id": "Gnd.LivingRoom.SmallLight", + "Gnd_LivingRoom_SmallLight": { + "id": "Gnd_LivingRoom_SmallLight", "name": "kleine Lampe Wohnzimmer", "service": "Lightbulb", "topic": { @@ -166,8 +166,8 @@ }, "config": {} }, - "Gnd.LivingRoom.Stars": { - "id": "Gnd.LivingRoom.Stars", + "Gnd_LivingRoom_Stars": { + "id": "Gnd_LivingRoom_Stars", "name": "Sterne Wohnzimmer", "service": "Lightbulb", "topic": { @@ -183,8 +183,8 @@ }, "config": {} }, - "Gnd.LivingRoom.StandLight": { - "id": "Gnd.LivingRoom.StandLight", + "Gnd_LivingRoom_StandLight": { + "id": "Gnd_LivingRoom_StandLight", "name": "Stehlampe Wohnzimmer", "service": "Lightbulb", "topic": { @@ -200,8 +200,8 @@ }, "config": {} }, - "Gnd.Hallway.DeskLight": { - "id": "Gnd.Hallway.DeskLight", + "Gnd_Hallway_DeskLight": { + "id": "Gnd_Hallway_DeskLight", "name": "Schreibtischlampe Flur", "service": "Lightbulb", "topic": { @@ -217,8 +217,8 @@ }, "config": {} }, - "Gnd.Hallway.StandLight": { - "id": "Gnd.Hallway.StandLight", + "Gnd_Hallway_StandLight": { + "id": "Gnd_Hallway_StandLight", "name": "Stehlampe Flur", "service": "Lightbulb", "topic": { @@ -234,8 +234,8 @@ }, "config": {} }, - "Gnd.Hallway.WardrobeLight": { - "id": "Gnd.Hallway.WardrobeLight", + "Gnd_Hallway_WardrobeLight": { + "id": "Gnd_Hallway_WardrobeLight", "name": "Schranklicht Flur", "service": "Lightbulb", "topic": { @@ -251,8 +251,8 @@ }, "config": {} }, - "Gnd.Kitchen.WindowLight": { - "id": "Gnd.Kitchen.WindowLight", + "Gnd_Kitchen_WindowLight": { + "id": "Gnd_Kitchen_WindowLight", "name": "Fensterbanklicht Küche", "service": "Lightbulb", "topic": { @@ -268,8 +268,8 @@ }, "config": {} }, - "Gnd.Kitchen.CeilingLight": { - "id": "Gnd.Kitchen.CeilingLight", + "Gnd_Kitchen_CeilingLight": { + "id": "Gnd_Kitchen_CeilingLight", "name": "Deckenlampe Küche", "service": "Lightbulb", "topic": { @@ -285,8 +285,8 @@ }, "config": {} }, - "1st.BedRoom.WolfgangsSide": { - "id": "1st.BedRoom.WolfgangsSide", + "1st_BedRoom_WolfgangsSide": { + "id": "1st_BedRoom_WolfgangsSide", "name": "Wolfgangs Seite Schlafzimmer", "service": "Lightbulb", "topic": { @@ -302,8 +302,8 @@ }, "config": {} }, - "1st.BedRoom.PattysSide": { - "id": "1st.BedRoom.PattysSide", + "1st_BedRoom_PattysSide": { + "id": "1st_BedRoom_PattysSide", "name": "Pattys Seite Schlafzimmer", "service": "Lightbulb", "topic": { @@ -319,8 +319,8 @@ }, "config": {} }, - "1st.BedRoom.WindowLight": { - "id": "1st.BedRoom.WindowLight", + "1st_BedRoom_WindowLight": { + "id": "1st_BedRoom_WindowLight", "name": "Fensterbanklicht Schlafzimmer", "service": "Lightbulb", "topic": { @@ -336,8 +336,8 @@ }, "config": {} }, - "Gnd.Hallway.DayLight": { - "id": "Gnd.Hallway.DayLight", + "Gnd_Hallway_DayLight": { + "id": "Gnd_Hallway_DayLight", "name": "DayLight", "service": "Lightbulb", "topic": { @@ -353,8 +353,8 @@ }, "config": {} }, - "Gnd.Hallway.EcoLight": { - "id": "Gnd.Hallway.EcoLight", + "Gnd_Hallway_EcoLight": { + "id": "Gnd_Hallway_EcoLight", "name": "EcoLight", "service": "Lightbulb", "topic": { @@ -370,8 +370,8 @@ }, "config": {} }, - "Gnd.Hallway.MorningLight": { - "id": "Gnd.Hallway.MorningLight", + "Gnd_Hallway_MorningLight": { + "id": "Gnd_Hallway_MorningLight", "name": "MorningLight", "service": "Lightbulb", "topic": { diff --git a/openhab.items b/openhab.items index f495faa..82c31f7 100644 --- a/openhab.items +++ b/openhab.items @@ -1,23 +1,23 @@ -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.WardrobeLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/WardrobeLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/WardrobeLight/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]"} -Switch Gnd.Hallway.DayLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state/feedback:state:default]"} -Switch Gnd.Hallway.EcoLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state/feedback:state:default]"} -Switch Gnd.Hallway.MorningLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state:command:*:default]", mqtt="<[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state/feedback:state:default]"} \ No newline at end of file +Switch 1st_Anna_AquariumLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/AquariumLight/state:command:*:default],<[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],<[localbroker:dispatcher_ng/items/1st/Anna/BedLight/state/feedback:state:default]"} +Switch 1st_Matthias_StandLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/StandLight/state:command:*:default],<[localbroker:dispatcher_ng/items/1st/Matthias/StandLight/state/feedback:state:default]"} +Switch 1st_Matthias_BedLight {mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/BedLight/state:command:*:default],<[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],<[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],<[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],<[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],<[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],<[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],<[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],<[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],<[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],<[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],<[localbroker:dispatcher_ng/items/Gnd/Hallway/StandLight/state/feedback:state:default]"} +Switch Gnd_Hallway_WardrobeLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/WardrobeLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/WardrobeLight/state/feedback:state:default]"} +Switch Gnd_Kitchen_WindowLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowLight/state:command:*:default],<[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],<[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],<[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],<[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],<[localbroker:dispatcher_ng/items/1st/BedRoom/WindowLight/state/feedback:state:default]"} +Switch Gnd_Hallway_DayLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state/feedback:state:default]"} +Switch Gnd_Hallway_EcoLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state/feedback:state:default]"} +Switch Gnd_Hallway_MorningLight {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state/feedback:state:default]"} \ No newline at end of file diff --git a/src/AItem.ts b/src/AItem.ts index a44c2bf..2e3af6d 100644 --- a/src/AItem.ts +++ b/src/AItem.ts @@ -26,7 +26,7 @@ export abstract class AItem { this.floor = floor this.room = room this.item = item - this.itemId = `${this.floor}.${this.room}.${this.item}` + this.itemId = `${this.floor}_${this.room}_${this.item}` if (label == '') { this.label = this.itemId } else { diff --git a/src/Export.ts b/src/Export.ts index fabdeeb..098018d 100644 --- a/src/Export.ts +++ b/src/Export.ts @@ -70,5 +70,5 @@ function SwitchHomekitOutletExport(id: string, label: string, setOn: string, sta 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]"}` -} \ No newline at end of file + return `Switch ${id} {mqtt=">[localbroker:${setOn}:command:*:default],<[localbroker:${statusOn}:state:default]"}` +} diff --git a/src/UrlSwitchItem.ts b/src/UrlSwitchItem.ts new file mode 100644 index 0000000..8ee34c4 --- /dev/null +++ b/src/UrlSwitchItem.ts @@ -0,0 +1,55 @@ +import * as logger from './log' +import { mqttHandler } from './MqttDispatcher' +import { AItem, HasStateAndFeedbackTopic } from './AItem' +import { SwitchExport, ExportType } from './Export' + + +export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic { + private offUrl: string + private onUrl: string + private oldState: string|undefined + private state: string + private actionTopic: string + private stateFeedbackTopic: string + private stateTopic: string + private type: string + + getStateTopic() : string { + return this.stateTopic + } + + getStateFeedbackTopic() : string { + return this.stateFeedbackTopic + } + + constructor(floor: string, room: string, item: string, label: string, onUrl: string, offUrl: string, type: string = 'bulb') { + super(floor, room, item, label) + this.stateTopic = `${this.topicFirstPart}/state` + this.subscribeTopics = [this.stateTopic] + this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback` + this.actionTopic = 'IoT/Mqtt433Gateway/Message' + this.state = 'OFF' + this.oldState = undefined + this.onUrl = onUrl + this.offUrl = offUrl + this.type = type + } + + exportItem() : ExportType|null { + return SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type) + } + + processMessage(topic: string, payload: string) { + this.state = payload; + mqttHandler.send(this.stateFeedbackTopic, this.state); + if (this.state != this.oldState) { + if (this.state == 'ON') { + mqttHandler.send(this.actionTopic, this.onCode); + } else { + mqttHandler.send(this.actionTopic, this.offCode); + } + this.oldState = this.state; + } + } +} + diff --git a/src/main.ts b/src/main.ts index 7d2c4d2..c90692e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,7 +35,7 @@ allLabeledItems.push(annaBedLight) // Matthias ------------------------------------------------------------------------------------------------- // Matthias Stehlampen 7 24 1 6 24 1 -let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'Stehlampen Matthias', 'StandLight', '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)