From fdf0c550942393ead12264dd23b7ecd56d94fa01 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 25 Jun 2018 11:28:02 +0200 Subject: [PATCH] separate actionTopic and feedbackTopic --- sample-configuration.json | 64 +++++++++++++++++++ src/app/app.component.html | 10 +-- src/app/app.component.ts | 58 +++-------------- .../led-button-group2.component.ts | 7 +- src/app/mqttclient.service.ts | 2 +- 5 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 sample-configuration.json diff --git a/sample-configuration.json b/sample-configuration.json new file mode 100644 index 0000000..af2fc09 --- /dev/null +++ b/sample-configuration.json @@ -0,0 +1,64 @@ +{ + "switches": [ + { + "room": "Wohnzimmer", + "switches": [ + { + "label": "kleine Lampe", + "actionTopic": "dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state/feedback" + }, + { + "label": "große Lampe", + "actionTopic": "dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state/feedback" + }, + { + "label": "Sterne", + "actionTopic": "dispatcher_ng/items/Gnd/LivingRoom/Stars/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/LivingRoom/Stars/state/feedback" + }, + { + "label": "Stehlampe", + "actionTopic": "dispatcher_ng/items/Gnd/LivingRoom/StandLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/LivingRoom/StandLight/state/feedback" + } + ] + }, + { + "room": "Esszimmer", + "switches": [ + { + "label": "kleine Lampe", + "actionTopic": "dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state/feedback" + }, + { + "label": "Stehlampe", + "actionTopic": "dispatcher_ng/items/Gnd/DiningRoom/StandLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/DiningRoom/StandLight/state/feedback" + }, + { + "label": "Schranklicht", + "actionTopic": "dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state/feedback" + }, + { + "label": "Naehkaestchenlicht", + "actionTopic": "dispatcher_ng/items/Gnd/DiningRoom/NaehkaestchenLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/DiningRoom/NaehkaestchenLight/state/feedback" + }, + { + "label": "Regallicht", + "actionTopic": "dispatcher_ng/items/Gnd/DiningRoom/ShelfLight/state", + "feedbackTopic": "dispatcher_ng/items/Gnd/DiningRoom/ShelfLight/state/feedback" + } + ] + } + ], + "windows": [ + { "label": "Fenster 1", "topic": "test/fenster1" }, + { "label": "Fenster 2", "topic": "test/fenster2" }, + { "label": "Fenster 3", "topic": "test/fenster3" } + ] +} \ No newline at end of file diff --git a/src/app/app.component.html b/src/app/app.component.html index afabe32..c9d44cf 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -8,16 +8,16 @@ {{room.room}} - +

- - -

- + +

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ed4f5ee..8f66281 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -9,56 +9,9 @@ import { MqttclientService } from './mqttclient.service' export class AppComponent implements OnInit { title = 'app'; private topic : string = 'smartclient/configuration' - configuration : any = { - 'switches': [ - { - 'room': 'Wohnzimmer', - 'switches': [ - { - 'label': 'kleine Lampe', - 'topic': 'dispatcher_ng/items/Gnd/LivingRoom/SmallLight' - }, - { - 'label': 'große Lampe', - 'topic': 'dispatcher_ng/items/Gnd/LivingRoom/LargeLight' - }, - { - 'label': 'Sterne', - 'topic': 'dispatcher_ng/items/Gnd/LivingRoom/Stars' - }, - { - 'label': 'Stehlampe', - 'topic': 'dispatcher_ng/items/Gnd/LivingRoom/StandLight' - } - ] - }, - { - 'room': 'Esszimmer', - 'switches': [ - { - 'label': 'kleine Lampe', - 'topic': 'dispatcher_ng/items/Gnd/DiningRoom/SmallLight' - }, - { - 'label': 'Stehlampe', - 'topic': 'dispatcher_ng/items/Gnd/DiningRoom/StandLight' - }, - { - 'label': 'Schranklicht', - 'topic': 'dispatcher_ng/items/Gnd/DiningRoom/CupboardLight' - }, - { - 'label': 'Naehkaestchenlicht', - 'topic': 'dispatcher_ng/items/Gnd/DiningRoom/NaehkaestchenLight' - }, - { - 'label': 'Regallicht', - 'topic': 'dispatcher_ng/items/Gnd/DiningRoom/ShelfLight' - } - ] - } - ] - + configuration : any = { + 'switches': [], + 'windows': [] } constructor(private mqttclientService : MqttclientService) { @@ -66,6 +19,11 @@ export class AppComponent implements OnInit { ngOnInit() { this.mqttclientService.register(this.topic, (message: string) => { + try { + this.configuration = JSON.parse(message) + } catch (e) { + alert(`Error when parsing received configuration: ${e}`) + } }) } diff --git a/src/app/led-button-group2/led-button-group2.component.ts b/src/app/led-button-group2/led-button-group2.component.ts index acb0cca..a418c98 100644 --- a/src/app/led-button-group2/led-button-group2.component.ts +++ b/src/app/led-button-group2/led-button-group2.component.ts @@ -16,16 +16,13 @@ import { MqttclientService } from '../mqttclient.service' }) export class LedButtonGroup2Component implements OnInit { - actionTopic : string - feedbackTopic : string - @Input('topic') topicPre : string + @Input() actionTopic : string + @Input() feedbackTopic : string @Input() label : string constructor(private mqttclientService : MqttclientService) { } ngOnInit() { - this.actionTopic = this.topicPre + '/state' - this.feedbackTopic = this.topicPre + '/state/feedback' } diff --git a/src/app/mqttclient.service.ts b/src/app/mqttclient.service.ts index 169584e..19ba0d2 100644 --- a/src/app/mqttclient.service.ts +++ b/src/app/mqttclient.service.ts @@ -9,7 +9,7 @@ export class MqttclientService { private callbacks : Map = new Map() constructor() { - this.mqttClient = Mqtt.connect('ws://mqttbroker:9001') + this.mqttClient = Mqtt.connect('ws://127.0.0.1:9001') this.mqttClient.on('connect', () => { console.log('MQTT connected') this.callbacks.forEach((value: callbackFunc, key: string) => {