From e6e558eae7b5588ce586d6e12d1e11f6f1a3d7fd Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Fri, 20 Apr 2018 23:39:20 +0200 Subject: [PATCH] Improve homeassistant discovery. #8 --- lib/controller.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index b0af3b4a1..e3215e0a5 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -53,8 +53,8 @@ class Controller { settings.write(); } - // We can't handle devices without modelId or cid. - if (!device.modelId || !message.data.cid) { + // We can't handle devices without modelId. + if (!device.modelId) { return; } @@ -77,10 +77,20 @@ class Controller { payload.state_topic = `${settings.get().mqtt.base_topic}/${friendlyName}`; payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`; payload.name = friendlyName; + + if (payload.command_topic) { + payload.command_topic = `${settings.get().mqtt.base_topic}/${friendlyName}/set`; + } + this.mqtt.publish(topic, JSON.stringify(payload), true, null, 'homeassistant'); this.hassDiscoveryCache[device.ieeeAddr] = true; } + // After this point we cant handle message withoud cid anymore. + if (!message.data.cid) { + return; + } + // Find a conveter for this message. const cid = message.data.cid; const converters = zigbee2mqtt.filter((c) => c.devices.includes(mappedModel.model) && c.cid === cid && c.type === message.type);