switch adaptor

This commit is contained in:
2018-05-24 23:42:07 +02:00
parent f75de912ba
commit e413f2871c
6 changed files with 109 additions and 3 deletions

3
dist/Forwarder.js vendored
View File

@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
const MqttDispatcher_1 = require("./MqttDispatcher");
class Forwarder extends AItem_1.AItem {
getInTopic() {
return this.inTopic;
}
constructor(floor, room, item, topicLastPart, label, targetTopics) {
super(floor, room, item, label);
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;

35
dist/SwitchAdaptor.js vendored Normal file
View File

@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
const MqttDispatcher_1 = require("./MqttDispatcher");
class SwitchAdaptor extends AItem_1.AItem {
constructor(floor, room, item) {
super(floor, room, item);
this.actionStateTopic = `${this.topicFirstPart}/state`;
this.inTopic = `${this.topicFirstPart}/in`;
this.subscribeTopics = [this.inTopic];
this.state = 'OFF';
}
getInTopic() {
return this.inTopic;
}
processMessage(topic, payload) {
switch (topic) {
case this.inTopic:
switch (payload) {
case 'SHORT':
if (this.state == 'OFF') {
this.state = 'ON';
}
else {
this.state = 'OFF';
}
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
break;
}
break;
}
}
}
exports.SwitchAdaptor = SwitchAdaptor;
//# sourceMappingURL=SwitchAdaptor.js.map

11
dist/main.js vendored
View File

@ -8,6 +8,7 @@ const M433SwitchItem_1 = require("./M433SwitchItem");
const HomematicFourButtonThing_1 = require("./HomematicFourButtonThing");
const DimmerAdaptor_1 = require("./DimmerAdaptor");
const TimerAdaptor_1 = require("./TimerAdaptor");
const SwitchAdaptor_1 = require("./SwitchAdaptor");
const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
const Forwarder_1 = require("./Forwarder");
@ -389,13 +390,21 @@ basementLargeLight.on('somethingChanged', () => {
MqttDispatcher_1.mqttHandler.send(basementSmallLight.getStateTopic(), 'OFF');
}
});
let basementForwarder = new Forwarder_1.Forwarder('Base', 'All', 'Forwarder', 'state', 'BasementForwarder', [
basementLargeLight.getState(),
basementSmallLight.getState(),
workshopLight.getState()
]);
basementForwarder.start();
let basementForwarderSwitchAdaptor = new SwitchAdaptor_1.SwitchAdaptor('Base', 'All', 'Forwarder');
basementForwarderSwitchAdaptor.start();
// ----------------------------------------------------------------------------------------------------------
let twoLedSignal1 = new TwoLedSignal_1.TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger', allRelevantLights, "OFF", "ON", allWindows, "CLOSED", "OPEN");
twoLedSignal1.start();
// MySwitchTHing
let mySwitchThingWolfgang = new MySwitchThing_1.MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
new MySwitchThing_1.MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
new MySwitchThing_1.MySwitchSingleItem('IoT/InsLeere/1'),
new MySwitchThing_1.MySwitchSingleItem(basementForwarderSwitchAdaptor.getInTopic()),
new MySwitchThing_1.MySwitchSingleItem('IoT/InsLeere/2'),
]);
mySwitchThingWolfgang.start();