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