This commit is contained in:
Wolfgang Hottgenroth
2018-01-02 13:12:16 +01:00
parent f4823a73ac
commit ac24b58038
2 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@ let mqtt = require('./mqttHandler');
class GenericItem { class HomematicDimmerItem {
constructor(itemId, actionTopic) { constructor(itemId, actionTopic) {
this.itemId = itemId; this.itemId = itemId;
this.stateTopic = `dispatcher_ng/items/${this.itemId}/state`; this.stateTopic = `dispatcher_ng/items/${this.itemId}/state`;
@ -15,8 +15,9 @@ class GenericItem {
this.oldState = undefined; this.oldState = undefined;
this.bright = 0; this.bright = 0;
this.oldBright = undefined; this.oldBright = undefined;
}
start() {
mqtt.register([this.stateTopic, this.brightTopic], (topic, payload) => { mqtt.register([this.stateTopic, this.brightTopic], (topic, payload) => {
payload = payload.toString('UTF-8'); payload = payload.toString('UTF-8');
logger.info(`item ${this.itemId}: ${topic}, ${payload}`) logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
@ -40,5 +41,5 @@ class GenericItem {
} }
} }
module.exports = GenericItem; module.exports = HomematicDimmerItem;

View File

@ -6,7 +6,9 @@ logger.info("Hello world!");
require('./item1'); require('./item1');
let genericItemClass = require('./genericItem'); let homematicDimmerItemClass = require('./homematicDimmerItem');
let item2 = new genericItemClass(2, 'homegear/instance1/items/8/state');
let item2 = new homematicDimmerItemClass(2, 'homegear/instance1/items/8/state');
item2.start();
mqtt.start(); mqtt.start();