Files
dispatcher_ng/dist/HueColorBulbItem.js

130 lines
6.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomegearItem_1 = require("./AHomegearItem");
const Export_1 = require("./Export");
class HueColorBulbItem extends AHomegearItem_1.AHomegearItem {
constructor(floor, room, item, label, hmId) {
super(floor, room, item, label, hmId);
this.BRIGHT_FACTOR = 2.54;
this.HUE_FACTOR = (65535 / 360);
this.SATURATION_FACTOR = 2.54;
this.stateTopic = `${this.topicFirstPart}/state`;
this.brightTopic = `${this.topicFirstPart}/bright`;
this.colorTemperatureTopic = `${this.topicFirstPart}/colorTemperature`;
this.hueTopic = `${this.topicFirstPart}/hue`;
this.saturationTopic = `${this.topicFirstPart}/saturation`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`;
this.hueFeedbackTopic = `${this.topicFirstPart}/bright/hue`;
this.saturationFeedbackTopic = `${this.topicFirstPart}/bright/saturation`;
this.colorTemperatureFeedbackTopic = `${this.topicFirstPart}/colorTemperature/feedback`;
this.stateActionTopic = `${this.actionTopicPre}/1/STATE`;
this.brightActionTopic = `${this.actionTopicPre}/1/FAST_BRIGHTNESS`;
this.hueActionTopic = `${this.actionTopicPre}/1/HUE`;
this.saturationActionTopic = `${this.actionTopicPre}/1/SATURATION`;
this.colorTemperatureActionTopic = `${this.actionTopicPre}/1/COLOR_TEMPERATURE`;
this.stateDeviceTopic = `${this.deviceTopicPre}/1/STATE`;
this.brightDeviceTopic = `${this.deviceTopicPre}/1/FAST_BRIGHTNESS`;
this.hueDeviceTopic = `${this.deviceTopicPre}/1/HUE`;
this.saturationDeviceTopic = `${this.deviceTopicPre}/1/SATURATION`;
this.colorTemperatureDeviceTopic = `${this.deviceTopicPre}/1/COLOR_TEMPERATURE`;
this.subscribeTopics = [
this.stateTopic,
this.brightTopic,
this.colorTemperatureTopic,
this.hueTopic,
this.saturationTopic,
this.stateDeviceTopic,
this.brightDeviceTopic,
this.colorTemperatureDeviceTopic,
this.hueDeviceTopic,
this.saturationDeviceTopic
];
this.state = 'OFF';
this.bright = 0;
this.colorTemperature = 0;
this.hue = 0;
this.saturation = 0;
}
getLabel() {
return this.label;
}
getRoom() {
return this.room;
}
getStateTopic() {
return this.stateTopic;
}
getInTopic() {
return this.stateTopic;
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic;
}
exportItem() {
return Export_1.HueColorLightExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.brightTopic, this.brightFeedbackTopic, this.hueTopic, this.hueFeedbackTopic, this.saturationTopic, this.saturationFeedbackTopic, this.colorTemperatureTopic, this.colorTemperatureFeedbackTopic);
}
processMessage(topic, payload) {
switch (topic) {
case this.stateTopic:
this.state = payload;
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state == "ON") {
MqttDispatcher_1.mqttHandler.send(this.stateActionTopic, "true");
}
else {
MqttDispatcher_1.mqttHandler.send(this.stateActionTopic, "false");
}
break;
case this.stateDeviceTopic:
this.state = payload;
if (payload == "true") {
this.state = "ON";
}
else {
this.state = "OFF";
}
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
break;
case this.brightTopic:
this.bright = parseFloat(payload);
MqttDispatcher_1.mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`);
MqttDispatcher_1.mqttHandler.send(this.brightActionTopic, `${this.bright * this.BRIGHT_FACTOR}`);
break;
case this.brightDeviceTopic:
this.bright = parseFloat(payload) / this.BRIGHT_FACTOR;
MqttDispatcher_1.mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`);
break;
case this.hueTopic:
this.hue = parseFloat(payload);
MqttDispatcher_1.mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`);
MqttDispatcher_1.mqttHandler.send(this.hueActionTopic, `${this.hue * this.HUE_FACTOR}`);
break;
case this.hueDeviceTopic:
this.hue = parseFloat(payload) / this.HUE_FACTOR;
MqttDispatcher_1.mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`);
break;
case this.saturationTopic:
this.saturation = parseFloat(payload);
MqttDispatcher_1.mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`);
MqttDispatcher_1.mqttHandler.send(this.saturationActionTopic, `${this.saturation * this.SATURATION_FACTOR}`);
break;
case this.saturationDeviceTopic:
this.saturation = parseFloat(payload) / this.SATURATION_FACTOR;
MqttDispatcher_1.mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`);
break;
case this.colorTemperatureTopic:
this.colorTemperature = parseInt(payload);
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`);
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureActionTopic, `${this.colorTemperature}`);
break;
case this.colorTemperatureDeviceTopic:
this.colorTemperature = parseInt(payload);
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`);
break;
}
}
}
exports.HueColorBulbItem = HueColorBulbItem;
//# sourceMappingURL=HueColorBulbItem.js.map