Improve homeassistant discovery. #8

This commit is contained in:
Koen Kanters
2018-04-20 23:39:20 +02:00
parent b9552f8ab3
commit e6e558eae7
+12 -2
View File
@@ -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);