Handle case where using enetity level name: None with MQTT (#5897)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
mtl010957 2023-12-06 19:31:27 -05:00 committed by GitHub
parent 049a7a0113
commit 51428dcbc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,7 +76,11 @@ bool MQTTComponent::send_discovery_() {
this->send_discovery(root, config); this->send_discovery(root, config);
// Fields from EntityBase // Fields from EntityBase
root[MQTT_NAME] = this->friendly_name(); if (this->get_entity()->has_own_name()) {
root[MQTT_NAME] = this->friendly_name();
} else {
root[MQTT_NAME] = "";
}
if (this->is_disabled_by_default()) if (this->is_disabled_by_default())
root[MQTT_ENABLED_BY_DEFAULT] = false; root[MQTT_ENABLED_BY_DEFAULT] = false;
if (!this->get_icon().empty()) if (!this->get_icon().empty())