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;