diff --git a/dist/MaxEcoSwitch.js b/dist/MaxEcoSwitch.js new file mode 100644 index 0000000..7e2373f --- /dev/null +++ b/dist/MaxEcoSwitch.js @@ -0,0 +1,56 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const MqttDispatcher_1 = require("./MqttDispatcher"); +const AHomematicItem_1 = require("./AHomematicItem"); +class MaxEcoSwitch extends AHomematicItem_1.AHomematicItem { + constructor(floor, room, item, label, hmId, mainScene, ecoScene) { + super(floor, room, item, label, hmId); + this.buttonTopic1 = `${this.deviceTopicPre}/1/PRESS`; + this.buttonTopic2 = `${this.deviceTopicPre}/2/PRESS`; + this.subscribeTopics = [this.buttonTopic1, this.buttonTopic2]; + this.mainTopic = mainScene.getStateTopic(); + this.ecoTopic = ecoScene.getStateTopic(); + this.state = 'OFF'; + } + processMessage(topic, payload) { + switch (this.state) { + case 'OFF': + if (topic == this.mainTopic) { + this.state = 'ON'; + } + else if (topic == this.ecoTopic) { + this.state = 'ECO'; + } + break; + case 'ON': + if (topic == this.mainTopic) { + this.state = 'OFF'; + } + else if (topic == this.ecoTopic) { + this.state = 'ECO'; + } + break; + case 'ECO': + if (topic == this.mainTopic) { + this.state = 'ON'; + } + else if (topic == this.ecoTopic) { + this.state = 'OFF'; + } + break; + } + switch (this.state) { + case 'OFF': + MqttDispatcher_1.mqttHandler.send(this.mainTopic, 'OFF'); + break; + case 'ON': + MqttDispatcher_1.mqttHandler.send(this.mainTopic, 'ON'); + break; + case 'ECO': + MqttDispatcher_1.mqttHandler.send(this.ecoTopic, 'ON'); + break; + } + } +} +exports.MaxEcoSwitch = MaxEcoSwitch; +//# sourceMappingURL=MaxEcoSwitch.js.map \ No newline at end of file diff --git a/dist/Scene.js b/dist/Scene.js index 80177de..00368be 100644 --- a/dist/Scene.js +++ b/dist/Scene.js @@ -4,6 +4,12 @@ const AItem_1 = require("./AItem"); const MqttDispatcher_1 = require("./MqttDispatcher"); const Export_1 = require("./Export"); class LightScene extends AItem_1.AItem { + getStateTopic() { + return this.stateTopic; + } + getStateFeedbackTopic() { + return this.stateFeedbackTopic; + } constructor(floor, room, item, label = '', onItems, offItems) { super(floor, room, item, label); this.onItems = onItems; diff --git a/dist/main.js b/dist/main.js index b7fbbbb..dad15d6 100644 --- a/dist/main.js +++ b/dist/main.js @@ -12,6 +12,7 @@ const HomematicDimmerItem_1 = require("./HomematicDimmerItem"); const HomematicSwitchItem_1 = require("./HomematicSwitchItem"); const Forwarder_1 = require("./Forwarder"); const Scene_1 = require("./Scene"); +const MaxEcoSwitch_1 = require("./MaxEcoSwitch"); logger.info("Dispatcher starting"); let allLabeledItems = new Array(); // Anna ----------------------------------------------------------------------------------------------------- @@ -119,6 +120,8 @@ let ecoLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLig ]); ecoLightScene.start(); allLabeledItems.push(ecoLightScene); +let ecoSwitch = new MaxEcoSwitch_1.MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 5, dayLightScene, ecoLightScene); +ecoSwitch.start(); let morningLightScene = new Scene_1.LightScene('Gnd', 'Hallway', 'MorningLight', 'MorningLight', [ kitchenWindowLight, kitchenCeilingLight, hallwayDeskLight, hallwayWardrobeLight, hallwayStandLight diff --git a/src/MaxEcoSwitch.ts b/src/MaxEcoSwitch.ts new file mode 100644 index 0000000..af7419b --- /dev/null +++ b/src/MaxEcoSwitch.ts @@ -0,0 +1,66 @@ +import * as logger from './log' +import { mqttHandler } from './MqttDispatcher' +import { AHomematicItem } from './AHomematicItem' +import { LightScene } from './Scene' + +export class MaxEcoSwitch extends AHomematicItem { + private ecoTopic: string + private mainTopic: string + private buttonTopic2: string + private buttonTopic1: string + private state: string + + constructor(floor: string, room: string, item: string, label: string, hmId: number, + mainScene: LightScene, ecoScene: LightScene) { + super(floor, room, item, label, hmId) + + this.buttonTopic1 = `${this.deviceTopicPre}/1/PRESS` + this.buttonTopic2 = `${this.deviceTopicPre}/2/PRESS` + + this.subscribeTopics = [ this.buttonTopic1, this.buttonTopic2 ] + + this.mainTopic = mainScene.getStateTopic() + this.ecoTopic = ecoScene.getStateTopic() + + this.state = 'OFF' + } + + + + processMessage(topic: string, payload: string) : void { + switch(this.state) { + case 'OFF': + if (topic == this.mainTopic) { + this.state = 'ON' + } else if (topic == this.ecoTopic) { + this.state = 'ECO' + } + break + case 'ON': + if (topic == this.mainTopic) { + this.state = 'OFF' + } else if (topic == this.ecoTopic) { + this.state = 'ECO' + } + break + case 'ECO': + if (topic == this.mainTopic) { + this.state = 'ON' + } else if (topic == this.ecoTopic) { + this.state = 'OFF' + } + break + } + switch(this.state) { + case 'OFF': + mqttHandler.send(this.mainTopic, 'OFF') + break + case 'ON': + mqttHandler.send(this.mainTopic, 'ON') + break + case 'ECO': + mqttHandler.send(this.ecoTopic, 'ON') + break + } + } +} \ No newline at end of file diff --git a/src/Scene.ts b/src/Scene.ts index 222021d..95bb267 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -3,7 +3,7 @@ import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { ExportType, SwitchExport } from './Export' -export class LightScene extends AItem { +export class LightScene extends AItem implements HasStateAndFeedbackTopic { private onFeedbackTopics: string[] private offFeedbackTopics: string[] private onTopics: string[] @@ -17,6 +17,13 @@ export class LightScene extends AItem { private onItems: HasStateAndFeedbackTopic[] private myLastFeedbackState: string + getStateTopic() { + return this.stateTopic + } + getStateFeedbackTopic() { + return this.stateFeedbackTopic + } + constructor(floor: string, room: string, item: string, label: string = '', onItems: HasStateAndFeedbackTopic[], offItems: HasStateAndFeedbackTopic[]) { super(floor, room, item, label) diff --git a/src/main.ts b/src/main.ts index 8eef01f..3e0cf22 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ import { HomematicDimmerItem } from './HomematicDimmerItem' import { HomematicSwitchItem } from './HomematicSwitchItem' import { Forwarder } from './Forwarder' import { LightScene } from './Scene' +import { MaxEcoSwitch } from './MaxEcoSwitch' logger.info("Dispatcher starting") @@ -158,6 +159,9 @@ let ecoLightScene = new LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight', ecoLightScene.start() allLabeledItems.push(ecoLightScene) +let ecoSwitch = new MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 5, dayLightScene, ecoLightScene) +ecoSwitch.start() + let morningLightScene = new LightScene('Gnd', 'Hallway', 'MorningLight', 'MorningLight', [ kitchenWindowLight, kitchenCeilingLight, hallwayDeskLight, hallwayWardrobeLight,