action topic changed

This commit is contained in:
Wolfgang Hottgenroth
2018-01-02 12:38:00 +01:00
parent c9dbb119fd
commit f4823a73ac
2 changed files with 8 additions and 4 deletions

View File

@ -4,13 +4,13 @@ let mqtt = require('./mqttHandler');
class GenericItem {
constructor(itemId) {
constructor(itemId, actionTopic) {
this.itemId = itemId;
this.stateTopic = `dispatcher_ng/items/${this.itemId}/state`;
this.brightTopic = `dispatcher_ng/items/${this.itemId}/bright`;
this.stateFeedbackTopic = `dispatcher_ng/items/${this.itemId}/state/feedback`;
this.brightFeedbackTopic = `dispatcher_ng/items/${this.itemId}/bright/feedback`;
this.actionTopic = `dispatcher_ng/items/${this.itemId}/action`;
this.actionTopic = actionTopic;
this.state = 'OFF';
this.oldState = undefined;
this.bright = 0;
@ -28,7 +28,11 @@ class GenericItem {
mqtt.send(this.brightFeedbackTopic, this.bright);
}
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
mqtt.send(this.actionTopic, `${this.state} ${this.bright}`);
if (this.state == 'ON') {
mqtt.send(this.actionTopic, `${this.bright}`);
} else {
mqtt.send(this.actionTopic, '0');
}
this.oldState = this.state;
this.oldBright = this.bright;
}

View File

@ -7,6 +7,6 @@ logger.info("Hello world!");
require('./item1');
let genericItemClass = require('./genericItem');
let item2 = new genericItemClass(2);
let item2 = new genericItemClass(2, 'homegear/instance1/items/8/state');
mqtt.start();