switch adaptor
This commit is contained in:
3
dist/Forwarder.js
vendored
3
dist/Forwarder.js
vendored
@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
const AItem_1 = require("./AItem");
|
const AItem_1 = require("./AItem");
|
||||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||||
class Forwarder extends AItem_1.AItem {
|
class Forwarder extends AItem_1.AItem {
|
||||||
|
getInTopic() {
|
||||||
|
return this.inTopic;
|
||||||
|
}
|
||||||
constructor(floor, room, item, topicLastPart, label, targetTopics) {
|
constructor(floor, room, item, topicLastPart, label, targetTopics) {
|
||||||
super(floor, room, item, label);
|
super(floor, room, item, label);
|
||||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
|
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
|
||||||
|
35
dist/SwitchAdaptor.js
vendored
Normal file
35
dist/SwitchAdaptor.js
vendored
Normal 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
11
dist/main.js
vendored
@ -8,6 +8,7 @@ const M433SwitchItem_1 = require("./M433SwitchItem");
|
|||||||
const HomematicFourButtonThing_1 = require("./HomematicFourButtonThing");
|
const HomematicFourButtonThing_1 = require("./HomematicFourButtonThing");
|
||||||
const DimmerAdaptor_1 = require("./DimmerAdaptor");
|
const DimmerAdaptor_1 = require("./DimmerAdaptor");
|
||||||
const TimerAdaptor_1 = require("./TimerAdaptor");
|
const TimerAdaptor_1 = require("./TimerAdaptor");
|
||||||
|
const SwitchAdaptor_1 = require("./SwitchAdaptor");
|
||||||
const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
|
const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
|
||||||
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
|
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
|
||||||
const Forwarder_1 = require("./Forwarder");
|
const Forwarder_1 = require("./Forwarder");
|
||||||
@ -389,13 +390,21 @@ basementLargeLight.on('somethingChanged', () => {
|
|||||||
MqttDispatcher_1.mqttHandler.send(basementSmallLight.getStateTopic(), 'OFF');
|
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");
|
let twoLedSignal1 = new TwoLedSignal_1.TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger', allRelevantLights, "OFF", "ON", allWindows, "CLOSED", "OPEN");
|
||||||
twoLedSignal1.start();
|
twoLedSignal1.start();
|
||||||
// MySwitchTHing
|
// MySwitchTHing
|
||||||
let mySwitchThingWolfgang = new MySwitchThing_1.MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
let mySwitchThingWolfgang = new MySwitchThing_1.MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
||||||
new MySwitchThing_1.MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
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'),
|
new MySwitchThing_1.MySwitchSingleItem('IoT/InsLeere/2'),
|
||||||
]);
|
]);
|
||||||
mySwitchThingWolfgang.start();
|
mySwitchThingWolfgang.start();
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
import { AItem } from './AItem'
|
import { AItem } from './AItem'
|
||||||
import * as logger from './log'
|
import * as logger from './log'
|
||||||
import { mqttHandler } from './MqttDispatcher'
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
import { HasInTopic } from './AItem';
|
||||||
|
|
||||||
|
|
||||||
export class Forwarder extends AItem {
|
export class Forwarder extends AItem implements HasInTopic {
|
||||||
private targetTopics: string[]
|
private targetTopics: string[]
|
||||||
private inTopic: string
|
private inTopic: string
|
||||||
|
|
||||||
|
getInTopic() : string {
|
||||||
|
return this.inTopic
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(floor: string, room: string, item: string, topicLastPart: string, label: string, targetTopics: string[]) {
|
constructor(floor: string, room: string, item: string, topicLastPart: string, label: string, targetTopics: string[]) {
|
||||||
super(floor, room, item, label)
|
super(floor, room, item, label)
|
||||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
|
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
|
||||||
|
41
src/SwitchAdaptor.ts
Normal file
41
src/SwitchAdaptor.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { AItem, HasInTopic } from './AItem'
|
||||||
|
import * as logger from './log'
|
||||||
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
|
||||||
|
export class SwitchAdaptor extends AItem implements HasInTopic {
|
||||||
|
private state: string
|
||||||
|
private inTopic: string
|
||||||
|
private actionStateTopic: string
|
||||||
|
|
||||||
|
constructor(floor: string, room: string, item: string) {
|
||||||
|
super(floor, room, item)
|
||||||
|
this.actionStateTopic = `${this.topicFirstPart}/state`
|
||||||
|
this.inTopic = `${this.topicFirstPart}/in`
|
||||||
|
this.subscribeTopics = [ this.inTopic ]
|
||||||
|
this.state = 'OFF'
|
||||||
|
}
|
||||||
|
|
||||||
|
getInTopic() : string {
|
||||||
|
return this.inTopic
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
switch (topic) {
|
||||||
|
case this.inTopic:
|
||||||
|
switch (payload) {
|
||||||
|
case 'SHORT':
|
||||||
|
if (this.state == 'OFF') {
|
||||||
|
this.state = 'ON'
|
||||||
|
} else {
|
||||||
|
this.state = 'OFF'
|
||||||
|
}
|
||||||
|
mqttHandler.send(this.actionStateTopic, this.state, true)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
14
src/main.ts
14
src/main.ts
@ -10,6 +10,7 @@ import { M433SwitchItem } from './M433SwitchItem'
|
|||||||
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
||||||
import { DimmerAdaptor } from './DimmerAdaptor'
|
import { DimmerAdaptor } from './DimmerAdaptor'
|
||||||
import { TimerAdaptor } from './TimerAdaptor'
|
import { TimerAdaptor } from './TimerAdaptor'
|
||||||
|
import { SwitchAdaptor } from './SwitchAdaptor'
|
||||||
import { HomematicDimmerItem } from './HomematicDimmerItem'
|
import { HomematicDimmerItem } from './HomematicDimmerItem'
|
||||||
import { HomematicSwitchItem } from './HomematicSwitchItem'
|
import { HomematicSwitchItem } from './HomematicSwitchItem'
|
||||||
import { Forwarder } from './Forwarder'
|
import { Forwarder } from './Forwarder'
|
||||||
@ -481,6 +482,17 @@ basementLargeLight.on('somethingChanged', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
let basementForwarder = new Forwarder('Base', 'All', 'Forwarder', 'state', 'BasementForwarder', [
|
||||||
|
basementLargeLight.getState(),
|
||||||
|
basementSmallLight.getState(),
|
||||||
|
workshopLight.getState()
|
||||||
|
])
|
||||||
|
basementForwarder.start()
|
||||||
|
|
||||||
|
|
||||||
|
let basementForwarderSwitchAdaptor = new SwitchAdaptor('Base', 'All', 'Forwarder')
|
||||||
|
basementForwarderSwitchAdaptor.start()
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------------------
|
||||||
let twoLedSignal1 = new TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger',
|
let twoLedSignal1 = new TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger',
|
||||||
allRelevantLights, "OFF", "ON",
|
allRelevantLights, "OFF", "ON",
|
||||||
@ -490,7 +502,7 @@ twoLedSignal1.start()
|
|||||||
// MySwitchTHing
|
// MySwitchTHing
|
||||||
let mySwitchThingWolfgang = new MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
let mySwitchThingWolfgang = new MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
||||||
new MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
new MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
||||||
new MySwitchSingleItem('IoT/InsLeere/1'),
|
new MySwitchSingleItem(basementForwarderSwitchAdaptor.getInTopic()),
|
||||||
new MySwitchSingleItem('IoT/InsLeere/2'),
|
new MySwitchSingleItem('IoT/InsLeere/2'),
|
||||||
])
|
])
|
||||||
mySwitchThingWolfgang.start()
|
mySwitchThingWolfgang.start()
|
||||||
|
Reference in New Issue
Block a user