action topic changed
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user