rename
This commit is contained in:
45
src/homematicDimmerItem.js
Normal file
45
src/homematicDimmerItem.js
Normal file
@ -0,0 +1,45 @@
|
||||
let logger = require('./log');
|
||||
let mqtt = require('./mqttHandler');
|
||||
|
||||
|
||||
|
||||
class HomematicDimmerItem {
|
||||
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 = actionTopic;
|
||||
this.state = 'OFF';
|
||||
this.oldState = undefined;
|
||||
this.bright = 0;
|
||||
this.oldBright = undefined;
|
||||
}
|
||||
|
||||
start() {
|
||||
mqtt.register([this.stateTopic, this.brightTopic], (topic, payload) => {
|
||||
payload = payload.toString('UTF-8');
|
||||
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
|
||||
if (topic == this.stateTopic) {
|
||||
this.state = payload;
|
||||
mqtt.send(this.stateFeedbackTopic, this.state);
|
||||
} else if (topic == this.brightTopic) {
|
||||
this.bright = payload;
|
||||
mqtt.send(this.brightFeedbackTopic, this.bright);
|
||||
}
|
||||
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
||||
if (this.state == 'ON') {
|
||||
mqtt.send(this.actionTopic, `${this.bright}`);
|
||||
} else {
|
||||
mqtt.send(this.actionTopic, '0');
|
||||
}
|
||||
this.oldState = this.state;
|
||||
this.oldBright = this.bright;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HomematicDimmerItem;
|
||||
|
Reference in New Issue
Block a user