dimmer handling
This commit is contained in:
43
src/DimmerAdaptor.js
Normal file
43
src/DimmerAdaptor.js
Normal file
@ -0,0 +1,43 @@
|
||||
let AItem = require('./AItem')
|
||||
let logger = require('./log')
|
||||
let mqtt = require('./mqttHandler');
|
||||
|
||||
|
||||
class DimmerAdaptor extends AItem {
|
||||
constructor(floor, room, item) {
|
||||
super(floor, room, item);
|
||||
this.actionStateTopic = `${this.topicFirstPart}/state`;
|
||||
this.actionBrightTopic = `${this.topicFirstPart}/bright`;
|
||||
this.inTopic = `${this.topicFirstPart}/dimmerIn`;
|
||||
this.subscribeTopics = [ this.inTopic ];
|
||||
this.state = 'OFF';
|
||||
this.bright = 100;
|
||||
this.brightDirection = -1;
|
||||
}
|
||||
|
||||
processMessage(topic, payload) {
|
||||
switch (topic) {
|
||||
case this.inTopic:
|
||||
switch (payload) {
|
||||
case 'SHORT':
|
||||
if (this.state == 'OFF') {
|
||||
this.state = 'ON';
|
||||
} else {
|
||||
this.state = 'OFF';
|
||||
}
|
||||
mqtt.send(this.actionStateTopic, this.state, true);
|
||||
mqtt.send(this.actionBrightTopic, this.bright, true);
|
||||
break;
|
||||
case 'LONG_HOLD':
|
||||
break;
|
||||
case 'LONG_END':
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = DimmerAdaptor;
|
||||
|
@ -10,14 +10,14 @@ class HomematicFourButtonSingleItem {
|
||||
processMessage(topic, payload) {
|
||||
switch(topic) {
|
||||
case 'PRESS_SHORT':
|
||||
mqtt.send(this.actionTopic, 'SHORT');
|
||||
mqtt.send(this.actionTopic, 'SHORT', true);
|
||||
break;
|
||||
case 'PRESS_LONG':
|
||||
case 'PRESS_CONT':
|
||||
mqtt.send(this.actionTopic, 'LONG_HOLD');
|
||||
mqtt.send(this.actionTopic, 'LONG_HOLD', true);
|
||||
break;
|
||||
case 'PRESS_LONG_RELEASE':
|
||||
mqtt.send(this.actionTopic, 'LONG_END');
|
||||
mqtt.send(this.actionTopic, 'LONG_END', true);
|
||||
break;
|
||||
default:
|
||||
logger.warn(`HM4BSI: no handling available for ${topic}`);
|
||||
|
@ -23,14 +23,14 @@ class HomematicDimmerItem extends AHomematicItem {
|
||||
];
|
||||
this.state = 'OFF';
|
||||
this.oldState = undefined;
|
||||
this.bright = 0;
|
||||
this.bright = 0.0;
|
||||
this.oldBright = undefined;
|
||||
}
|
||||
|
||||
dimmerAction() {
|
||||
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
||||
if (this.state == 'ON') {
|
||||
mqtt.send(this.actionTopic, `${this.bright}`);
|
||||
mqtt.send(this.actionTopic, `${this.bright} / 100.0`);
|
||||
} else {
|
||||
mqtt.send(this.actionTopic, '0');
|
||||
}
|
||||
@ -47,7 +47,7 @@ class HomematicDimmerItem extends AHomematicItem {
|
||||
this.dimmerAction();
|
||||
break;
|
||||
case this.brightTopic:
|
||||
this.bright = parseInt(payload);
|
||||
this.bright = parseFloat(payload);
|
||||
mqtt.send(this.brightFeedbackTopic, `${this.bright}`);
|
||||
this.dimmerAction();
|
||||
break;
|
||||
|
15
src/main.js
15
src/main.js
@ -9,10 +9,7 @@ let HomematicDimmerItemClass = require('./HomematicDimmerItem');
|
||||
let M433SwitchItem = require('./M433SwitchItem');
|
||||
let HomematicFourButtonThing = require('./HomematicFourButtonThing');
|
||||
let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem');
|
||||
|
||||
|
||||
let item2 = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
|
||||
item2.start();
|
||||
let DimmerAdaptor = require('./DimmerAdaptor');
|
||||
|
||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
||||
aquariumLight.start();
|
||||
@ -21,13 +18,21 @@ let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1',
|
||||
deskLight.start();
|
||||
|
||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonSingleItem('button1', 'test/button/1'),
|
||||
new HomematicFourButtonSingleItem('button1', 'dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
new HomematicFourButtonSingleItem('button2', 'test/button/2'),
|
||||
new HomematicFourButtonSingleItem('button3', 'test/button/3'),
|
||||
new HomematicFourButtonSingleItem('button4', 'test/button/4')
|
||||
])
|
||||
testFourButton.start();
|
||||
|
||||
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
||||
testDimmerAdaptor.start();
|
||||
|
||||
let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
|
||||
testLight.start();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mqtt.start();
|
||||
|
@ -55,10 +55,14 @@ function processMessage(topic, payload) {
|
||||
function send(topic, payload, internalFirst = false) {
|
||||
let sent = false;
|
||||
if (internalFirst) {
|
||||
logger.info(`Try internal sending: ${topic}`);
|
||||
sent = processMessage(topic, payload);
|
||||
}
|
||||
if (! sent) {
|
||||
logger.info(`External sending required: ${topic}`);
|
||||
client.publish(topic, payload);
|
||||
} else {
|
||||
logger.info(`Internally delivered: ${topic}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user