Fix topic not updated for Home Assistant sensor on rename. #4452

This commit is contained in:
Koen Kanters 2020-09-25 17:32:40 +02:00
parent cb5418e9fc
commit 4f6797c365

View File

@ -2204,16 +2204,16 @@ class HomeAssistant extends Extension {
}
onDeviceRenamed(device, homeAssisantRename) {
if (!homeAssisantRename) return;
logger.debug(`Refreshing Home Assistant discovery topic for '${device.ieeeAddr}'`);
// Clear before rename so Home Assistant uses new friendly_name
// https://github.com/Koenkk/zigbee2mqtt/issues/4096#issuecomment-674044916
const resolvedEntity = this.zigbee.resolveEntity(device);
for (const config of this.getConfigs(resolvedEntity)) {
const topic = this.getDiscoveryTopic(config, device);
this.mqtt.publish(topic, null, {retain: true, qos: 0}, this.discoveryTopic);
if (homeAssisantRename) {
const resolvedEntity = this.zigbee.resolveEntity(device);
for (const config of this.getConfigs(resolvedEntity)) {
const topic = this.getDiscoveryTopic(config, device);
this.mqtt.publish(topic, null, {retain: true, qos: 0}, this.discoveryTopic);
}
}
this.discover(resolvedEntity, true);