rework thermostat
This commit is contained in:
3
dist/Disabler.js
vendored
Normal file
3
dist/Disabler.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Disabler.js.map
|
11
dist/Export.js
vendored
11
dist/Export.js
vendored
@ -16,8 +16,8 @@ function SwitchExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
|
||||
return { 'homekit': homekitOut, 'openhab': openhabOut };
|
||||
}
|
||||
exports.SwitchExport = SwitchExport;
|
||||
function ThermostatExport(itemId, label, temperatureTopic, temperatureFeedbackTopic) {
|
||||
return { 'homekit': ThermostatHomekitExport(itemId, label, temperatureTopic, temperatureFeedbackTopic), 'openhab': ThermostatOpenHAPExport(itemId, label, temperatureTopic, temperatureFeedbackTopic) };
|
||||
function ThermostatExport(itemId, label, temperatureTopic, temperatureFeedbackTopic, presetTemperatureTopic, presetTemperatureFeedbackTopic) {
|
||||
return { 'homekit': ThermostatHomekitExport(itemId, label, temperatureTopic, temperatureFeedbackTopic), 'openhab': ThermostatOpenHAPExport(itemId, label, temperatureTopic, temperatureFeedbackTopic, presetTemperatureTopic, presetTemperatureFeedbackTopic) };
|
||||
}
|
||||
exports.ThermostatExport = ThermostatExport;
|
||||
function ContactExport(itemId, label, status) {
|
||||
@ -117,8 +117,11 @@ function ContactOpenHABExport(id, label, status) {
|
||||
// Switch windowLightKitchen {mqtt=">[localbroker:nodered/items/windowLightKitchen:command:*:default]", mqtt="<[localbroker:nodered/items/windowLightKitchen/feedback:state:default]"}
|
||||
return `Contact ${id} "${label}" {mqtt="<[localbroker:${status}:state:default]"}`;
|
||||
}
|
||||
function ThermostatOpenHAPExport(id, label, setTemperature, statusTemperature) {
|
||||
return `Number ${id} "${label}" {mqtt=">[localbroker:${setTemperature}:command:*:default],<[localbroker:${statusTemperature}:state:default]"}`;
|
||||
function ThermostatOpenHAPExport(id, label, setTemperature, statusTemperature, presetTemperature, presetStatusTemperature) {
|
||||
let o = [];
|
||||
o.push(`Number ${id} "${label}" {mqtt=">[localbroker:${setTemperature}:command:*:default],<[localbroker:${statusTemperature}:state:default]"}`);
|
||||
o.push(`Number Preset-${id} "Preset-${label}" {mqtt=">[localbroker:${presetTemperature}:command:*:default],<[localbroker:${presetStatusTemperature}:state:default]"}`);
|
||||
return o;
|
||||
}
|
||||
function HueColorLightHomekitExport(id, label, stateTopic, stateFeedbackTopic, brightnessTopic, brightnessFeedbackTopic, hueTopic, hueFeedbackTopic, saturationTopic, saturationFeedbackTopic, colorTemperatureTopic, colorTemperatureFeedbackTopic) {
|
||||
let o = {
|
||||
|
55
dist/MaxThermostat.js
vendored
55
dist/MaxThermostat.js
vendored
@ -2,31 +2,37 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const AHomegearItem_1 = require("./AHomegearItem");
|
||||
// import { MaxWindowContact } from './MaxWindowContact';
|
||||
const Export_1 = require("./Export");
|
||||
const WINDOW_OPEN_TEMPERATURE = 4.5;
|
||||
const DISABLED_TEMPERATURE = 5.0;
|
||||
class MaxThermostat extends AHomegearItem_1.AHomegearItem {
|
||||
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
|
||||
getInTopic() {
|
||||
return this.temperatureTopic;
|
||||
}
|
||||
exportItem() {
|
||||
return Export_1.ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic);
|
||||
return Export_1.ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic, this.presetTemperatureTopic, this.presetTemperatureFeedbackTopic);
|
||||
}
|
||||
constructor(floor, room, item, label, hmId, windowContacts) {
|
||||
constructor(floor, room, item, label, hmId, hardDisablers) {
|
||||
super(floor, room, item, label, hmId);
|
||||
this.temperatureTopic = `${this.topicFirstPart}/temperature`;
|
||||
this.temperatureFeedbackTopic = `${this.topicFirstPart}/temperature/feedback`;
|
||||
this.presetTemperatureTopic = `${this.topicFirstPart}/presetTemperature`;
|
||||
this.presetTemperatureFeedbackTopic = `${this.topicFirstPart}/presetTemperature/feedback`;
|
||||
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/SET_TEMPERATURE`;
|
||||
this.actionTopic = `${this.actionTopicPre}/1/SET_TEMPERATURE`;
|
||||
this.commandTopic = `${this.topicFirstPart}/command`;
|
||||
this.subscribeTopics = [
|
||||
this.temperatureTopic,
|
||||
this.deviceFeedbackTopic
|
||||
this.presetTemperatureTopic,
|
||||
this.deviceFeedbackTopic,
|
||||
this.commandTopic
|
||||
];
|
||||
this.windowOpen = false;
|
||||
this.windowContactMap = {};
|
||||
windowContacts.forEach((windowContact) => {
|
||||
this.subscribeTopics.push(windowContact.getStateFeedbackTopic());
|
||||
this.windowContactMap[windowContact.getStateFeedbackTopic()] = { windowContact: windowContact, state: 'unknown' };
|
||||
this.hardDisabled = false;
|
||||
this.hardDisablerMap = {};
|
||||
hardDisablers.forEach((hardDisabler) => {
|
||||
this.subscribeTopics.push(hardDisabler.getStateFeedbackTopic());
|
||||
this.hardDisablerMap[hardDisabler.getStateFeedbackTopic()] = { disabler: hardDisabler, state: 'unknown' };
|
||||
});
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
@ -35,28 +41,41 @@ class MaxThermostat extends AHomegearItem_1.AHomegearItem {
|
||||
this.temperature = parseFloat(payload);
|
||||
setTemperature = true;
|
||||
}
|
||||
else if (topic == this.commandTopic) {
|
||||
if (payload == 'START') {
|
||||
this.temperature = this.presetTemperature;
|
||||
}
|
||||
else {
|
||||
this.temperature = DISABLED_TEMPERATURE;
|
||||
}
|
||||
setTemperature = true;
|
||||
}
|
||||
else if (topic == this.presetTemperatureTopic) {
|
||||
this.presetTemperature = parseFloat(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.presetTemperatureFeedbackTopic, `${this.presetTemperature}`);
|
||||
}
|
||||
else if (topic == this.deviceFeedbackTopic) {
|
||||
// this.temperature = parseFloat(payload)
|
||||
setTemperature = false;
|
||||
}
|
||||
else if (topic in this.windowContactMap) {
|
||||
this.windowContactMap[topic].state = payload;
|
||||
this.windowOpen = false;
|
||||
Object.values(this.windowContactMap).forEach((w) => {
|
||||
if (w.state == 'OPEN') {
|
||||
this.windowOpen = true;
|
||||
else if (topic in this.hardDisablerMap) {
|
||||
this.hardDisablerMap[topic].state = this.hardDisablerMap[topic].disabler.transform(payload);
|
||||
this.hardDisabled = false;
|
||||
Object.values(this.hardDisablerMap).forEach((w) => {
|
||||
if (w.state == 'DISABLE') {
|
||||
this.hardDisabled = true;
|
||||
}
|
||||
});
|
||||
setTemperature = true;
|
||||
}
|
||||
if (setTemperature) {
|
||||
if (!this.windowOpen) {
|
||||
if (!this.hardDisabled) {
|
||||
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${this.temperature}`);
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${WINDOW_OPEN_TEMPERATURE}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${WINDOW_OPEN_TEMPERATURE}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${DISABLED_TEMPERATURE}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${DISABLED_TEMPERATURE}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
dist/MaxWindowContact.js
vendored
13
dist/MaxWindowContact.js
vendored
@ -7,6 +7,19 @@ class MaxWindowContact extends AHomegearItem_1.AHomegearItem {
|
||||
getStateFeedbackTopic() {
|
||||
return this.stateFeedbackTopic;
|
||||
}
|
||||
transform(payload) {
|
||||
let res;
|
||||
if (payload == 'OPEN') {
|
||||
res = 'DISABLE';
|
||||
}
|
||||
else if (payload == 'CLOSED') {
|
||||
res = 'ENABLE';
|
||||
}
|
||||
else {
|
||||
res = 'UNKNOWN';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
constructor(floor, room, item, label, hmId) {
|
||||
super(floor, room, item, label, hmId);
|
||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||
|
Reference in New Issue
Block a user