Skip to content

Commit

Permalink
Support QBKG04LM. Koenkk#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Apr 27, 2018
1 parent bc09975 commit 415027c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand All @@ -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);
});
}

Expand Down
12 changes: 11 additions & 1 deletion lib/converters/zigbee2mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
15 changes: 10 additions & 5 deletions lib/zigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 415027c

Please sign in to comment.