mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 15:08:10 +01:00
Change device name in MQTT discovery messages to friendly names (#5205)
This commit is contained in:
parent
1495fada90
commit
3a07121784
1 changed files with 6 additions and 1 deletions
|
@ -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";
|
||||||
|
|
Loading…
Reference in a new issue