From 415027c90ff43e00a77213c20c08a003f41cb80e Mon Sep 17 00:00:00 2001 From: Koenkk Date: Fri, 27 Apr 2018 23:58:46 +0200 Subject: [PATCH] Support QBKG04LM. #4 --- lib/controller.js | 7 ++++++- lib/converters/zigbee2mqtt.js | 12 +++++++++++- lib/devices.js | 8 ++++++++ lib/zigbee.js | 15 ++++++++++----- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index e26e8888af..c1e4442b8a 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -157,6 +157,7 @@ class Controller { handleMQTTMessageDevice(topic, message) { const friendlyName = topic.split('/')[1]; + const topicPostfix = ''; // Map friendlyName to deviceID. const deviceID = Object.keys(settings.get().devices).find((id) => settings.getDevice(id).friendly_name === friendlyName); @@ -174,6 +175,10 @@ class Controller { json = {state: message.toString()}; } + // Find ep for this device + const mappedModel = deviceMapping[this.zigbee.getDevice(deviceID).modelId]; + const ep = mappedModel.ep && mappedModel.ep[topicPostfix] ? mappedModel.ep[topicPostfix] : null; + Object.keys(json).forEach((key) => { // Find converter for this key. const converter = mqtt2zigbee[key]; @@ -190,7 +195,7 @@ class Controller { } }; - this.zigbee.publish(deviceID, message.cId, message.cmd, message.zclData, callback); + this.zigbee.publish(deviceID, message.cId, message.cmd, message.zclData, ep, callback); }); } diff --git a/lib/converters/zigbee2mqtt.js b/lib/converters/zigbee2mqtt.js index 2836e19fe3..b2ac0fcbae 100644 --- a/lib/converters/zigbee2mqtt.js +++ b/lib/converters/zigbee2mqtt.js @@ -218,10 +218,20 @@ const parsers = [ type: 'attReport', convert: (msg) => {return {power: precisionRound(msg.data.data['presentValue'], 2)}} }, + { + devices: ['QBKG04LM'], + cid: 'genOnOff', + type: 'attReport', + convert: (msg) => { + if (msg.data.data['61440']) { + return {state: msg.data.data['onOff'] === 1 ? "ON" : "OFF"} + } + } + }, // Ignore parsers (these message dont need parsing). { - devices: ['WXKG11LM', 'MCCGQ11LM', 'MCCGQ01LM', 'WXKG01LM', 'LED1545G12', '7146060PH', 'LED1537R6', 'ZNCZ02LM', 'QBCZ11LM'], + devices: ['WXKG11LM', 'MCCGQ11LM', 'MCCGQ01LM', 'WXKG01LM', 'LED1545G12', '7146060PH', 'LED1537R6', 'ZNCZ02LM', 'QBCZ11LM', 'QBKG04LM'], cid: 'genOnOff', type: 'devChange', convert: () => null diff --git a/lib/devices.js b/lib/devices.js index c4b852ef4d..907dca7e81 100644 --- a/lib/devices.js +++ b/lib/devices.js @@ -30,6 +30,14 @@ const devices = { supports: 'left, right and both click', homeassistant: [homeassistant.sensor_button] }, + 'lumi.ctrl_neutral1': { + model: 'QBKG04LM', + vendor: 'Xiaomi', + description: 'Aqara single key wired wall switch', + supports: 'on/off', + ep: {'': 2}, + homeassistant: [homeassistant.switch] + }, 'lumi.sens': { model: 'WSDCGQ01LM', vendor: 'Xiaomi', diff --git a/lib/zigbee.js b/lib/zigbee.js index 09026722f9..530bc7ce61 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -103,22 +103,27 @@ class Zigbee { return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ${friendlyDevice.vendor} ${friendlyDevice.description}`; } - publish(deviceID, cId, cmd, zclData, callback) { + getDevice(deviceID) { + return this.shepherd.list().find((d) => d.ieeeAddr === deviceID); + } + + publish(deviceID, cId, cmd, zclData, ep, callback) { // Find device in zigbee-shepherd - let device = this.shepherd.list().find((d) => d.ieeeAddr === deviceID); - if (!device || !device.epList || !device.epList[0]) { + let device = this.getDevice(deviceID); + if (!device || !device.epList || !device.epList.length) { logger.error(`Zigbee cannot determine endpoint for '${deviceID}'`); return; } - device = this.shepherd.find(deviceID, device.epList[0]); + ep = ep ? ep : device.epList[0]; + device = this.shepherd.find(deviceID, ep); if (!device) { logger.error(`Zigbee cannot publish message to device because '${deviceID}' is not known by zigbee-shepherd`); return; } - logger.info(`Zigbee publish to '${deviceID}', ${cId} - ${cmd} - ${JSON.stringify(zclData)}`); + logger.info(`Zigbee publish to '${deviceID}', ${cId} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`); device.functional(cId, cmd, zclData, callback); } }