forwarder
This commit is contained in:
25
src/Forwarder.js
Normal file
25
src/Forwarder.js
Normal file
@ -0,0 +1,25 @@
|
||||
let AItem = require('./AItem')
|
||||
let logger = require('./log')
|
||||
let mqtt = require('./mqttHandler');
|
||||
|
||||
|
||||
class Forwarder extends AItem {
|
||||
constructor(floor, room, item, topicLastPart, targetTopics) {
|
||||
super(floor, room, item);
|
||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
|
||||
this.subscribeTopics = [ this.inTopic ];
|
||||
this.targetTopics = targetTopics;
|
||||
}
|
||||
|
||||
processMessage(topic, payload) {
|
||||
switch (topic) {
|
||||
case this.inTopic:
|
||||
this.targetTopics.forEach((targetTopic) => {
|
||||
mqtt.send(targetTopic, payload, true);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Forwarder;
|
@ -10,6 +10,8 @@ let M433SwitchItem = require('./M433SwitchItem');
|
||||
let HomematicFourButtonThing = require('./HomematicFourButtonThing');
|
||||
let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem');
|
||||
let DimmerAdaptor = require('./DimmerAdaptor');
|
||||
let Forwarder = require('./Forwarder');
|
||||
|
||||
|
||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
||||
aquariumLight.start();
|
||||
@ -31,6 +33,11 @@ testDimmerAdaptor.start();
|
||||
let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
|
||||
testLight.start();
|
||||
|
||||
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
|
||||
'dispatcher_ng/items/Gnd/Hallway/Testlight/state',
|
||||
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
||||
]);
|
||||
testForwarder.start();
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user