EcoSwitch
This commit is contained in:
56
dist/MaxEcoSwitch.js
vendored
Normal file
56
dist/MaxEcoSwitch.js
vendored
Normal file
@ -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
|
6
dist/Scene.js
vendored
6
dist/Scene.js
vendored
@ -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;
|
||||
|
3
dist/main.js
vendored
3
dist/main.js
vendored
@ -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
|
||||
|
66
src/MaxEcoSwitch.ts
Normal file
66
src/MaxEcoSwitch.ts
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user