51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const AItem_1 = require("./AItem");
|
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
|
class DimmerAdaptor extends AItem_1.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;
|
|
}
|
|
getInTopic() {
|
|
return this.inTopic;
|
|
}
|
|
processMessage(topic, payload) {
|
|
switch (topic) {
|
|
case this.inTopic:
|
|
switch (payload) {
|
|
case 'SHORT':
|
|
if (this.state == 'OFF') {
|
|
this.state = 'ON';
|
|
}
|
|
else {
|
|
this.state = 'OFF';
|
|
}
|
|
MqttDispatcher_1.mqttHandler.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;
|
|
}
|
|
MqttDispatcher_1.mqttHandler.send(this.actionBrightTopic, this.bright.toString(), true);
|
|
break;
|
|
case 'LONG_END':
|
|
this.brightDirection = this.brightDirection * -1;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
exports.DimmerAdaptor = DimmerAdaptor;
|
|
//# sourceMappingURL=DimmerAdaptor.js.map
|