From 4f6797c36548b779e40450ac16d49b069b807fc2 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Fri, 25 Sep 2020 17:32:40 +0200 Subject: [PATCH] Fix topic not updated for Home Assistant sensor on rename. #4452 --- lib/extension/homeassistant.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index 997fa7725..de48ad676 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -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);