3 Commits

9 changed files with 130 additions and 68 deletions

64
sample-configuration.json Normal file
View File

@ -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" }
]
}

View File

@ -6,7 +6,16 @@ ledbox {
float: left; float: left;
display: block; display: block;
} }
onoff {
float: left;
display: block;
}
p.clear { p.clear {
clear: both; clear: both;
}
div#scenes {
margin-top: 10px;
margin-bottom: 10px;
} }

View File

@ -1,64 +1,30 @@
<mat-tab-group> <mat-tab-group>
<mat-tab label="Licht"> <mat-tab label="Licht">
<mat-accordion> <div id="scenes">
<mat-expansion-panel> <onoff *ngFor="let scene of configuration.scenes"
<mat-expansion-panel-header> [label]="scene.label" [topic]="scene.actionTopic"></onoff>
<mat-panel-title> <p class="clear"></p>
Wohnzimmer </div>
</mat-panel-title> <mat-divider></mat-divider>
</mat-expansion-panel-header>
<ledbutton2 topic="led/test1" label="Küche Deckenlampe"></ledbutton2>
<ledbutton2 topic="led/test2" label="Keller normal"></ledbutton2>
<ledbutton2 topic="led/test3" label="Keller hell"></ledbutton2>
<ledbutton2 topic="led/test4" label="test4"></ledbutton2>
<ledbutton2 topic="led/test1" label="Küche Deckenlampe"></ledbutton2>
<ledbutton2 topic="led/test2" label="Keller normal"></ledbutton2>
<ledbutton2 topic="led/test3" label="Keller hell"></ledbutton2>
<ledbutton2 topic="led/test4" label="test4"></ledbutton2>
<ledbutton2 topic="led/test1" label="Küche Deckenlampe"></ledbutton2>
<ledbutton2 topic="led/test2" label="Keller normal"></ledbutton2>
<ledbutton2 topic="led/test3" label="Keller hell"></ledbutton2>
<ledbutton2 topic="led/test4" label="test4"></ledbutton2>
<p class="clear"></p>
</mat-expansion-panel>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
Esszimmer
</mat-panel-title>
</mat-expansion-panel-header>
<table id="maintable">
<tr>
<td>
<ledbutton2 topic="led/test1" label="Küche Deckenlampe"></ledbutton2>
</td>
<td>
<ledbutton2 topic="led/test2" label="Keller normal"></ledbutton2>
</td>
<td>
<ledbutton2 topic="led/test3" label="Keller hell"></ledbutton2>
</td>
<td>
<ledbutton2 topic="led/test4" label="test4"></ledbutton2>
</td>
</tr>
</table>
</mat-expansion-panel>
</mat-accordion>
<mat-accordion>
<mat-expansion-panel *ngFor="let room of configuration.switches">
<mat-expansion-panel-header>
<mat-panel-title>
{{room.room}}
</mat-panel-title>
</mat-expansion-panel-header >
<ledbutton2 *ngFor="let switch of room.switches"
[actionTopic]="switch.actionTopic" [feedbackTopic]="switch.feedbackTopic"
[label]="switch.label"></ledbutton2>
<p class="clear"></p>
</mat-expansion-panel>
</mat-accordion>
</mat-tab> </mat-tab>
<mat-tab label="Fenster"> <mat-tab label="Fenster">
<ledbox topic="led/test4" label="test4"></ledbox> <ledbox *ngFor="let window of configuration.windows" [topic]="window.topic" [label]="window.label"></ledbox>
<ledbox topic="led/test4" label="test4"></ledbox> <p class="clear"></p>
<p class="clear"></p>
</mat-tab> </mat-tab>
<mat-tab label="Heizung"> <mat-tab label="Heizung">

View File

@ -1,10 +1,30 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { MqttclientService } from './mqttclient.service'
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrls: ['./app.component.css'] styleUrls: ['./app.component.css']
}) })
export class AppComponent { export class AppComponent implements OnInit {
title = 'app'; title = 'app';
private topic : string = 'smartclient/configuration'
configuration : any = {
'switches': [],
'windows': []
}
constructor(private mqttclientService : MqttclientService) {
}
ngOnInit() {
this.mqttclientService.register(this.topic, (message: string) => {
try {
this.configuration = JSON.parse(message)
} catch (e) {
alert(`Error when parsing received configuration: ${e}`)
}
})
}
} }

View File

@ -5,6 +5,7 @@ import { NgModule } from '@angular/core';
import { MatTabsModule } from '@angular/material/tabs'; import { MatTabsModule } from '@angular/material/tabs';
import { MatExpansionModule } from '@angular/material/expansion'; import { MatExpansionModule } from '@angular/material/expansion';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatDividerModule } from '@angular/material/divider';
import { MqttclientService } from './mqttclient.service' import { MqttclientService } from './mqttclient.service'
@ -32,7 +33,8 @@ import { LedBoxComponent } from './led-box/led-box.component';
BrowserAnimationsModule, BrowserAnimationsModule,
MatTabsModule, MatTabsModule,
MatExpansionModule, MatExpansionModule,
MatButtonModule MatButtonModule,
MatDividerModule
], ],
providers: [ providers: [
MqttclientService MqttclientService

View File

@ -5,7 +5,7 @@ import { MqttclientService } from '../mqttclient.service'
selector: 'ledbox', selector: 'ledbox',
template: ` template: `
<div [ngStyle]="{ 'text-align': 'center', 'background-color':'lightgrey', 'border-radius':'10px', <div [ngStyle]="{ 'text-align': 'center', 'background-color':'lightgrey', 'border-radius':'10px',
'width': '100px', 'padding':'5px', 'margin': '5px', 'width': '100px', 'height':'80px', 'padding':'5px', 'margin': '5px',
'font-family': 'sans-serif' }"> 'font-family': 'sans-serif' }">
{{label}}<br/> {{label}}<br/>
<led [topic]="topic" greenToken="CLOSED" redToken="OPEN"></led> <led [topic]="topic" greenToken="CLOSED" redToken="OPEN"></led>

View File

@ -16,16 +16,13 @@ import { MqttclientService } from '../mqttclient.service'
}) })
export class LedButtonGroup2Component implements OnInit { export class LedButtonGroup2Component implements OnInit {
actionTopic : string @Input() actionTopic : string
feedbackTopic : string @Input() feedbackTopic : string
@Input('topic') topicPre : string
@Input() label : string @Input() label : string
constructor(private mqttclientService : MqttclientService) { } constructor(private mqttclientService : MqttclientService) { }
ngOnInit() { ngOnInit() {
this.actionTopic = this.topicPre + '/state'
this.feedbackTopic = this.topicPre + '/feedback'
} }

View File

@ -9,7 +9,7 @@ export class MqttclientService {
private callbacks : Map<string, callbackFunc> = new Map() private callbacks : Map<string, callbackFunc> = new Map()
constructor() { constructor() {
this.mqttClient = Mqtt.connect('ws://localhost:9001') this.mqttClient = Mqtt.connect('ws://127.0.0.1:9001')
this.mqttClient.on('connect', () => { this.mqttClient.on('connect', () => {
console.log('MQTT connected') console.log('MQTT connected')
this.callbacks.forEach((value: callbackFunc, key: string) => { this.callbacks.forEach((value: callbackFunc, key: string) => {

View File

@ -4,14 +4,18 @@ import { MqttclientService } from '../mqttclient.service'
@Component({ @Component({
selector: 'onoff', selector: 'onoff',
template: ` template: `
<div class="button"> <div [ngStyle]="{ 'text-align': 'center', 'background-color':'lightgrey', 'border-radius':'10px',
<button (click)="clickOn()" [ngStyle]="{'font-size':'150%'}">on</button> 'width': '150px', 'padding':'5px', 'margin': '5px',
<button (click)="clickOff()" [ngStyle]="{'font-size':'150%'}">off</button> 'font-family': 'sans-serif' }">
{{label}}<br/>
<button mat-mini-fab color="primary" (click)="clickOff()" [ngStyle]="{'font-size':'100%'}">off</button>
<button mat-mini-fab color="primary" (click)="clickOn()" [ngStyle]="{'font-size':'100%'}">on</button>
</div> </div>
` `
}) })
export class OnOffButtonComponent implements OnInit { export class OnOffButtonComponent implements OnInit {
@Input() topic : string = 'invalid' @Input() topic : string = 'invalid'
@Input() label : string = 'invalid'
constructor(private mqttclientService : MqttclientService) { } constructor(private mqttclientService : MqttclientService) { }