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 logger = require('./log');
|
||||||
let mqtt = require('./mqttHandler');
|
let mqtt = require('./mqttHandler');
|
||||||
|
let AItem = require('./AItem')
|
||||||
|
|
||||||
|
|
||||||
|
class HomematicDimmerItem extends AItem {
|
||||||
class HomematicDimmerItem {
|
constructor(floor, room, item, actionTopic) {
|
||||||
constructor(itemId, actionTopic) {
|
super(floor, room, item);
|
||||||
this.itemId = itemId;
|
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||||
this.stateTopic = `dispatcher_ng/items/${this.itemId}/state`;
|
this.brightTopic = `${this.topicFirstPart}/bright`;
|
||||||
this.brightTopic = `dispatcher_ng/items/${this.itemId}/bright`;
|
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
|
||||||
this.stateFeedbackTopic = `dispatcher_ng/items/${this.itemId}/state/feedback`;
|
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`;
|
||||||
this.brightFeedbackTopic = `dispatcher_ng/items/${this.itemId}/bright/feedback`;
|
|
||||||
this.actionTopic = actionTopic;
|
this.actionTopic = actionTopic;
|
||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
this.oldState = undefined;
|
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');
|
require('./item1');
|
||||||
|
|
||||||
let homematicDimmerItemClass = require('./homematicDimmerItem');
|
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();
|
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();
|
mqtt.start();
|
||||||
|
Reference in New Issue
Block a user