base class and m433switch
This commit is contained in:
12
src/AItem.js
Normal file
12
src/AItem.js
Normal file
@ -0,0 +1,12 @@
|
||||
class AItem {
|
||||
constructor(floor, room, item) {
|
||||
this.floor = floor;
|
||||
this.room = room;
|
||||
this.item = item;
|
||||
this.itemId = `${this.floor}.${this.room}.${this.item}`;
|
||||
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AItem;
|
||||
|
@ -1,15 +1,15 @@
|
||||
let logger = require('./log');
|
||||
let mqtt = require('./mqttHandler');
|
||||
let AItem = require('./AItem')
|
||||
|
||||
|
||||
|
||||
class HomematicDimmerItem {
|
||||
constructor(itemId, actionTopic) {
|
||||
this.itemId = itemId;
|
||||
this.stateTopic = `dispatcher_ng/items/${this.itemId}/state`;
|
||||
this.brightTopic = `dispatcher_ng/items/${this.itemId}/bright`;
|
||||
this.stateFeedbackTopic = `dispatcher_ng/items/${this.itemId}/state/feedback`;
|
||||
this.brightFeedbackTopic = `dispatcher_ng/items/${this.itemId}/bright/feedback`;
|
||||
class HomematicDimmerItem extends AItem {
|
||||
constructor(floor, room, item, actionTopic) {
|
||||
super(floor, room, item);
|
||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||
this.brightTopic = `${this.topicFirstPart}/bright`;
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
|
||||
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`;
|
||||
this.actionTopic = actionTopic;
|
||||
this.state = 'OFF';
|
||||
this.oldState = undefined;
|
||||
|
37
src/m433SwitchItem.js
Normal file
37
src/m433SwitchItem.js
Normal file
@ -0,0 +1,37 @@
|
||||
let logger = require('./log');
|
||||
let mqtt = require('./mqttHandler');
|
||||
let AItem = require('./AItem');
|
||||
|
||||
|
||||
class M433SwitchItem extends AItem {
|
||||
constructor(floor, room, item, onCode, offCode) {
|
||||
super(floor, room, item);
|
||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
|
||||
this.actionTopic = 'IoT/Mqtt433Gateway/Message';
|
||||
this.state = 'OFF';
|
||||
this.oldState = undefined;
|
||||
this.onCode = onCode;
|
||||
this.offCode = offCode;
|
||||
}
|
||||
|
||||
start() {
|
||||
mqtt.register([this.stateTopic], (topic, payload) => {
|
||||
payload = payload.toString('UTF-8');
|
||||
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
|
||||
this.state = payload;
|
||||
mqtt.send(this.stateFeedbackTopic, this.state);
|
||||
if (this.state != this.oldState) {
|
||||
if (this.state == 'ON') {
|
||||
mqtt.send(this.actionTopic, this.onCode);
|
||||
} else {
|
||||
mqtt.send(this.actionTopic, this.offCode);
|
||||
}
|
||||
this.oldState = this.state;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = M433SwitchItem;
|
||||
|
10
src/main.js
10
src/main.js
@ -7,8 +7,16 @@ logger.info("Hello world!");
|
||||
require('./item1');
|
||||
|
||||
let homematicDimmerItemClass = require('./homematicDimmerItem');
|
||||
let m433SwitchItem = require('./m433SwitchItem');
|
||||
|
||||
let item2 = new homematicDimmerItemClass(2, 'homegear/instance1/items/8/state');
|
||||
let item2 = new homematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 'homegear/instance1/items/8/state');
|
||||
item2.start();
|
||||
|
||||
let aquariumLight = new m433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
||||
aquariumLight.start();
|
||||
|
||||
let deskLight = new m433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1');
|
||||
deskLight.start();
|
||||
|
||||
|
||||
mqtt.start();
|
||||
|
Reference in New Issue
Block a user