mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-28 23:00:55 +00:00
Improve homeassistant discovery. #8
This commit is contained in:
+12
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user