dimmer handling
This commit is contained in:
43
src/DimmerAdaptor.js
Normal file
43
src/DimmerAdaptor.js
Normal 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;
|
||||
|
Reference in New Issue
Block a user