Allow to set device specific occupancy_timeout. #27

This commit is contained in:
Koenkk
2018-05-15 18:06:16 +02:00
parent 17aba009af
commit debc96c232
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ class Controller {
// for e.g. click switches where we need to count number of clicks and detect long presses.
converters.forEach((converter) => {
const publish = (payload) => this.mqttPublishDeviceState(device.ieeeAddr, payload, converter.disableCache !== true);
const payload = converter.convert(message, publish);
const payload = converter.convert(message, publish, settings.getDevice(device.ieeeAddr));
if (payload) {
publish(payload);
+3 -2
View File
@@ -176,9 +176,10 @@ const parsers = [
devices: ['RTCGQ01LM', 'RTCGQ11LM'],
cid: 'msOccupancySensing',
type: 'attReport',
convert: (msg, publish) => {
convert: (msg, publish, options) => {
// The occupancy sensor only sends a message when motion detected.
// Therefore we need to publish the no_motion detected by ourselves.
const timeout = options.occupancy_timeout ? options.occupancy_timeout : occupancyTimeout;
const deviceID = msg.endpoints[0].device.ieeeAddr;
// Stop existing timer because motion is detected and set a new one.
@@ -190,7 +191,7 @@ const parsers = [
store[deviceID] = setTimeout(() => {
publish({occupancy: false})
store[deviceID] = null;
}, occupancyTimeout * 1000);
}, timeout * 1000);
return {occupancy: true};
}
},