dimmer handling

This commit is contained in:
Wolfgang Hottgenroth
2018-01-04 16:10:54 +01:00
parent ccf5bf8831
commit 717fa42451
5 changed files with 63 additions and 11 deletions

43
src/DimmerAdaptor.js Normal file
View File

@ -0,0 +1,43 @@
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);
mqtt.send(this.actionBrightTopic, this.bright, true);
break;
case 'LONG_HOLD':
break;
case 'LONG_END':
break;
}
break;
}
}
}
module.exports = DimmerAdaptor;