Change device name in MQTT discovery messages to friendly names (#5205)

This commit is contained in:
Paweł Kozubal 2023-08-07 03:46:31 +02:00 committed by GitHub
parent 1495fada90
commit 3a07121784
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -132,9 +132,14 @@ bool MQTTComponent::send_discovery_() {
if (discovery_info.object_id_generator == MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR) if (discovery_info.object_id_generator == MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR)
root[MQTT_OBJECT_ID] = node_name + "_" + this->get_default_object_id_(); root[MQTT_OBJECT_ID] = node_name + "_" + this->get_default_object_id_();
std::string node_friendly_name = App.get_friendly_name();
if (node_friendly_name.empty()) {
node_friendly_name = node_name;
}
JsonObject device_info = root.createNestedObject(MQTT_DEVICE); JsonObject device_info = root.createNestedObject(MQTT_DEVICE);
device_info[MQTT_DEVICE_IDENTIFIERS] = get_mac_address(); device_info[MQTT_DEVICE_IDENTIFIERS] = get_mac_address();
device_info[MQTT_DEVICE_NAME] = node_name; device_info[MQTT_DEVICE_NAME] = node_friendly_name;
device_info[MQTT_DEVICE_SW_VERSION] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time(); device_info[MQTT_DEVICE_SW_VERSION] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time();
device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD; device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD;
device_info[MQTT_DEVICE_MANUFACTURER] = "espressif"; device_info[MQTT_DEVICE_MANUFACTURER] = "espressif";