Files
dispatcher_ng/src/DimmerAdaptor.js
Wolfgang Hottgenroth 7300fa6dbd dimmer handling part 2
2018-01-04 17:34:40 +01:00

52 lines
1.7 KiB
JavaScript

let AItem = require('./AItem')
let logger = require('./log')
let mqtt = require('./mqttHandler');
class DimmerAdaptor extends AItem {
constructor(floor, room, item) {
super(floor, room, item);
this.actionStateTopic = `${this.topicFirstPart}/state`;
this.actionBrightTopic = `${this.topicFirstPart}/bright`;
this.inTopic = `${this.topicFirstPart}/dimmerIn`;
this.subscribeTopics = [ this.inTopic ];
this.state = 'OFF';
this.bright = 100;
this.brightDirection = -1;
}
processMessage(topic, payload) {
switch (topic) {
case this.inTopic:
switch (payload) {
case 'SHORT':
if (this.state == 'OFF') {
this.state = 'ON';
} else {
this.state = 'OFF';
}
mqtt.send(this.actionStateTopic, this.state, true);
break;
case 'LONG_HOLD':
this.bright += (5 * this.brightDirection);
if (this.bright > 100) {
this.bright = 100;
}
if (this.bright < 0) {
this.bright = 0;
}
mqtt.send(this.actionBrightTopic, this.bright, true);
break;
case 'LONG_END':
this.brightDirection = this.brightDirection * -1;
break;
}
break;
}
}
}
module.exports = DimmerAdaptor;