diff --git a/index.js b/index.js index d994dff40..8f8329ff7 100644 --- a/index.js +++ b/index.js @@ -146,10 +146,10 @@ function handleMessage(msg) { // Find a parser for this modelID and cid. const cid = msg.data.cid; - const _parsers = parsers.filter((p) => p.devices.includes(mappedModel.model) && p.cid === cid); + const _parsers = parsers.filter((p) => p.devices.includes(mappedModel.model) && p.cid === cid && p.type === msg.type); if (!_parsers.length) { - logger.error(`No parser available for '${mappedModel.model}' with cid '${cid}'`); + logger.error(`No parser available for '${mappedModel.model}' with cid '${cid}' and type '${msg.type}'`); logger.error('Please create an issue on https://github.com/Koenkk/xiaomi-zb2mqtt/issues with this message.'); return; } diff --git a/parsers.js b/parsers.js index ba02f2a9a..879e503d0 100644 --- a/parsers.js +++ b/parsers.js @@ -27,6 +27,7 @@ const parsers = [ { devices: ['WXKG01LM', 'RTCGQ01LM', 'WSDCGQ01LM', 'MCCGQ01LM'], cid: 'genBasic', + type: 'attReport', disablePublish: true, parse: (msg, publish) => { let voltage = null; @@ -45,6 +46,7 @@ const parsers = [ { devices: ['WXKG01LM'], cid: 'genOnOff', + type: 'attReport', parse: (msg, publish) => { const deviceID = msg.endpoints[0].device.ieeeAddr; const state = msg.data.data['onOff']; @@ -71,16 +73,19 @@ const parsers = [ { devices: ['WSDCGQ01LM'], cid: 'msTemperatureMeasurement', + type: 'attReport', parse: (msg) => {return {temperature: parseFloat(msg.data.data['measuredValue']) / 100.0}} }, { devices: ['WSDCGQ01LM'], cid: 'msRelativeHumidity', + type: 'attReport', parse: (msg) => {return {humidity: parseFloat(msg.data.data['measuredValue']) / 100.0}} }, { devices: ['RTCGQ01LM'], cid: 'msOccupancySensing', + type: 'attReport', parse: (msg, publish) => { // The occupancy sensor only sends a message when motion detected. // Therefore we need to publish the no_motion detected by ourselves. @@ -104,23 +109,35 @@ const parsers = [ { devices: ['MCCGQ01LM'], cid: 'genOnOff', + type: 'attReport', parse: (msg) => {return {state: msg.data.data['onOff'] ? 'open' : 'closed'}} }, - { - devices: ['LED1545G12'], - cid: 'genOnOff', - parse: (msg) => null - }, { devices: ['LED1545G12'], cid: 'genLevelCtrl', + type: 'devChange', parse: (msg) => {return {brightness: msg.data.data['currentLevel']}}, }, { devices: ['LED1545G12'], cid: 'lightingColorCtrl', + type: 'devChange', parse: (msg) => {return {color_temp: msg.data.data['colorTemperature']}}, - } + }, + + // Ignore the following messages: + { + devices: ['LED1545G12'], + cid: 'genOnOff', + type: 'devChange', + parse: (msg) => null + }, + { + devices: ['WXKG01LM'], + cid: 'genOnOff', + type: 'devChange', + parse: (msg) => null + }, ]; module.exports = parsers;