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`;
|
||||
|
@ -2,6 +2,7 @@ Switch 1st_Anna_AquariumLight "Aquariumlicht"{mqtt=">[localbroker:dispatcher_ng/
|
||||
Switch 1st_Anna_BedLight "Bettlicht Anna"{mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/BedLight/state:command:*:default],<[localbroker:dispatcher_ng/items/1st/Anna/BedLight/state/feedback:state:default]"}
|
||||
Contact 1st_Anna_WindowContact "Fenster Anna" {mqtt="<[localbroker:dispatcher_ng/items/1st/Anna/WindowContact/state/feedback:state:default]"}
|
||||
Number 1st_Anna_Thermostat "Thermostat Anna" {mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/Thermostat/temperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Anna/Thermostat/temperature/feedback:state:default]"}
|
||||
Number Preset-1st_Anna_Thermostat "Preset-Thermostat Anna" {mqtt=">[localbroker:dispatcher_ng/items/1st/Anna/Thermostat/presetTemperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Anna/Thermostat/presetTemperature/feedback:state:default]"}
|
||||
Switch 1st_Matthias_StandLight "Stehlampen Matthias"{mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/StandLight/state:command:*:default],<[localbroker:dispatcher_ng/items/1st/Matthias/StandLight/state/feedback:state:default]"}
|
||||
Switch 1st_Matthias_BedLight "Bettlicht Matthias"{mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/BedLight/state:command:*:default],<[localbroker:dispatcher_ng/items/1st/Matthias/BedLight/state/feedback:state:default]"}
|
||||
Switch 1st_Matthias_Speaker "Lautsprecher Matthias"{mqtt=">[localbroker:dispatcher_ng/items/1st/Matthias/Speaker/state:command:*:default],<[localbroker:dispatcher_ng/items/1st/Matthias/Speaker/state/feedback:state:default]"}
|
||||
@ -27,18 +28,22 @@ Contact 1st_Bedroom_WindowContactStreet "Fenster Schlafzimmer Strasse" {mqtt="<[
|
||||
Contact 1st_Bedroom_WindowContact1Garden "Fenster Schlafzimmer 1 Garten" {mqtt="<[localbroker:dispatcher_ng/items/1st/Bedroom/WindowContact1Garden/state/feedback:state:default]"}
|
||||
Contact 1st_Bedroom_WindowContact2Garden "Fenster Schlafzimmer 2 Garten" {mqtt="<[localbroker:dispatcher_ng/items/1st/Bedroom/WindowContact2Garden/state/feedback:state:default]"}
|
||||
Number 1st_Bedroom_Thermostat "Thermostat Schlafzimmer" {mqtt=">[localbroker:dispatcher_ng/items/1st/Bedroom/Thermostat/temperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Bedroom/Thermostat/temperature/feedback:state:default]"}
|
||||
Number Preset-1st_Bedroom_Thermostat "Preset-Thermostat Schlafzimmer" {mqtt=">[localbroker:dispatcher_ng/items/1st/Bedroom/Thermostat/presetTemperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Bedroom/Thermostat/presetTemperature/feedback:state:default]"}
|
||||
Switch Gnd_Hallway_DayLight "DayLight"{mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/DayLight/state/feedback:state:default]"}
|
||||
Switch Gnd_Hallway_EcoLight "EcoLight"{mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/EcoLight/state/feedback:state:default]"}
|
||||
Switch Gnd_Hallway_MorningLight "MorningLight"{mqtt=">[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Hallway/MorningLight/state/feedback:state:default]"}
|
||||
Contact Gnd_Bathroom_WindowContact "Fenster Bad unten" {mqtt="<[localbroker:dispatcher_ng/items/Gnd/Bathroom/WindowContact/state/feedback:state:default]"}
|
||||
Number Gnd_Bathroom_Thermostat "Thermostat Bad unten" {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Bathroom/Thermostat/temperature:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Bathroom/Thermostat/temperature/feedback:state:default]"}
|
||||
Number Preset-Gnd_Bathroom_Thermostat "Preset-Thermostat Bad unten" {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Bathroom/Thermostat/presetTemperature:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Bathroom/Thermostat/presetTemperature/feedback:state:default]"}
|
||||
Contact 1st_Bathroom_WindowContact "Fenster Bad oben" {mqtt="<[localbroker:dispatcher_ng/items/1st/Bathroom/WindowContact/state/feedback:state:default]"}
|
||||
Number 1st_Bathroom_Thermostat "Thermostat Bad oben" {mqtt=">[localbroker:dispatcher_ng/items/1st/Bathroom/Thermostat/temperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Bathroom/Thermostat/temperature/feedback:state:default]"}
|
||||
Number Preset-1st_Bathroom_Thermostat "Preset-Thermostat Bad oben" {mqtt=">[localbroker:dispatcher_ng/items/1st/Bathroom/Thermostat/presetTemperature:command:*:default],<[localbroker:dispatcher_ng/items/1st/Bathroom/Thermostat/presetTemperature/feedback:state:default]"}
|
||||
Contact Gnd_Kitchen_WindowContact1 "Fenster Küche Garten" {mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowContact1/state/feedback:state:default]"}
|
||||
Contact Gnd_Kitchen_WindowContact2 "Fenster Küche Terassentür Garten" {mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowContact2/state/feedback:state:default]"}
|
||||
Contact Gnd_Kitchen_WindowContact3 "Fenster Küche Straße 1" {mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowContact3/state/feedback:state:default]"}
|
||||
Contact Gnd_Kitchen_WindowContact4 "Fenster Küche Straße 2" {mqtt="<[localbroker:dispatcher_ng/items/Gnd/Kitchen/WindowContact4/state/feedback:state:default]"}
|
||||
Number Gnd_Kitchen_Thermostat "Thermostat Küche" {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Kitchen/Thermostat/temperature:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Kitchen/Thermostat/temperature/feedback:state:default]"}
|
||||
Number Preset-Gnd_Kitchen_Thermostat "Preset-Thermostat Küche" {mqtt=">[localbroker:dispatcher_ng/items/Gnd/Kitchen/Thermostat/presetTemperature:command:*:default],<[localbroker:dispatcher_ng/items/Gnd/Kitchen/Thermostat/presetTemperature/feedback:state:default]"}
|
||||
Switch base_labor_relaybox0 "Küche" {mqtt=">[localbroker:dispatcher_ng/items/base/labor/relaybox/state/0:command:*:default],<[localbroker:dispatcher_ng/items/base/labor/relaybox/feedback/0:state:default]"}
|
||||
Switch base_labor_relaybox0Conflict "Küche [%s]" {mqtt="<[localbroker:dispatcher_ng/items/base/labor/relaybox/conflict/0:state:default]"}
|
||||
Switch base_labor_relaybox1 "Herd" {mqtt=">[localbroker:dispatcher_ng/items/base/labor/relaybox/state/1:command:*:default],<[localbroker:dispatcher_ng/items/base/labor/relaybox/feedback/1:state:default]"}
|
||||
|
4
src/Disabler.ts
Normal file
4
src/Disabler.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface Disabler {
|
||||
transform(payload: string) : string
|
||||
getStateFeedbackTopic(): string
|
||||
}
|
@ -27,8 +27,8 @@ export function SwitchExport(itemId: string, label: string, stateTopic: string,
|
||||
return { 'homekit': homekitOut, 'openhab': openhabOut }
|
||||
}
|
||||
|
||||
export function ThermostatExport(itemId: string, label: string, temperatureTopic: string, temperatureFeedbackTopic: string) : ExportType {
|
||||
return {'homekit': ThermostatHomekitExport(itemId, label, temperatureTopic, temperatureFeedbackTopic), 'openhab': ThermostatOpenHAPExport(itemId, label, temperatureTopic, temperatureFeedbackTopic)}
|
||||
export function ThermostatExport(itemId: string, label: string, temperatureTopic: string, temperatureFeedbackTopic: string, presetTemperatureTopic: string, presetTemperatureFeedbackTopic: string) : ExportType {
|
||||
return {'homekit': ThermostatHomekitExport(itemId, label, temperatureTopic, temperatureFeedbackTopic), 'openhab': ThermostatOpenHAPExport(itemId, label, temperatureTopic, temperatureFeedbackTopic, presetTemperatureTopic, presetTemperatureFeedbackTopic)}
|
||||
}
|
||||
|
||||
export function ContactExport(itemId: string, label: string, status: string) : ExportType {
|
||||
@ -145,8 +145,11 @@ function ContactOpenHABExport(id: string, label: string, status: string): string
|
||||
return `Contact ${id} "${label}" {mqtt="<[localbroker:${status}:state:default]"}`
|
||||
}
|
||||
|
||||
function ThermostatOpenHAPExport(id: string, label: string, setTemperature: string, statusTemperature: string) : string {
|
||||
return `Number ${id} "${label}" {mqtt=">[localbroker:${setTemperature}:command:*:default],<[localbroker:${statusTemperature}:state:default]"}`
|
||||
function ThermostatOpenHAPExport(id: string, label: string, setTemperature: string, statusTemperature: string, presetTemperature: string, presetStatusTemperature: string) : string[] {
|
||||
let o : string[] = []
|
||||
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: string, label: string,
|
||||
|
@ -2,14 +2,15 @@ import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HasInTopic } from './AItem'
|
||||
import { AHomegearItem } from './AHomegearItem'
|
||||
import { MaxWindowContact } from './MaxWindowContact';
|
||||
// import { MaxWindowContact } from './MaxWindowContact';
|
||||
import { ThermostatExport, ExportType } from './Export'
|
||||
import { Disabler } from './Disabler'
|
||||
|
||||
const WINDOW_OPEN_TEMPERATURE = 4.5
|
||||
const DISABLED_TEMPERATURE = 5.0
|
||||
|
||||
|
||||
type WindowContactHolder = {
|
||||
windowContact : MaxWindowContact
|
||||
type DisabledHolder = {
|
||||
disabler : Disabler
|
||||
state : string
|
||||
}
|
||||
|
||||
@ -19,8 +20,13 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
|
||||
private temperatureFeedbackTopic: string
|
||||
private temperatureTopic: string
|
||||
private temperature: number
|
||||
private windowContactMap: { [key:string]: WindowContactHolder }
|
||||
private windowOpen: boolean
|
||||
private presetTemperatureFeedbackTopic: string
|
||||
private presetTemperatureTopic: string
|
||||
private presetTemperature: number
|
||||
private hardDisablerMap: { [key:string]: DisabledHolder }
|
||||
private hardDisabled: boolean
|
||||
private commandTopic: string
|
||||
|
||||
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
|
||||
|
||||
getInTopic() : string {
|
||||
@ -28,24 +34,29 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
|
||||
}
|
||||
|
||||
exportItem() : ExportType|null {
|
||||
return ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic)
|
||||
return ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic, this.presetTemperatureTopic, this.presetTemperatureFeedbackTopic)
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number, windowContacts: MaxWindowContact[]) {
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number, hardDisablers: Disabler[]) {
|
||||
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' }
|
||||
})
|
||||
}
|
||||
|
||||
@ -54,27 +65,37 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
|
||||
if (topic == this.temperatureTopic) {
|
||||
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)
|
||||
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) {
|
||||
mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`)
|
||||
mqttHandler.send(this.actionTopic, `${this.temperature}`)
|
||||
} else {
|
||||
mqttHandler.send(this.temperatureFeedbackTopic, `${WINDOW_OPEN_TEMPERATURE}`)
|
||||
mqttHandler.send(this.actionTopic, `${WINDOW_OPEN_TEMPERATURE}`)
|
||||
mqttHandler.send(this.temperatureFeedbackTopic, `${DISABLED_TEMPERATURE}`)
|
||||
mqttHandler.send(this.actionTopic, `${DISABLED_TEMPERATURE}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AHomegearItem } from './AHomegearItem'
|
||||
import { ContactExport, ExportType } from './Export'
|
||||
import { Disabler } from './Disabler'
|
||||
|
||||
export class MaxWindowContact extends AHomegearItem {
|
||||
export class MaxWindowContact extends AHomegearItem implements Disabler {
|
||||
private deviceFeedbackTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private stateTopic: string
|
||||
@ -13,6 +14,18 @@ export class MaxWindowContact extends AHomegearItem {
|
||||
return this.stateFeedbackTopic
|
||||
}
|
||||
|
||||
transform(payload: string) : string {
|
||||
let res: string
|
||||
if (payload == 'OPEN') {
|
||||
res = 'DISABLE'
|
||||
} else if (payload == 'CLOSED') {
|
||||
res = 'ENABLE'
|
||||
} else {
|
||||
res = 'UNKNOWN'
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
|
Reference in New Issue
Block a user