mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
minor cleanup and testing
This commit is contained in:
23
src/mqtt.cpp
23
src/mqtt.cpp
@@ -989,28 +989,21 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
snprintf(entity_with_tag, sizeof(entity_with_tag), "%s", entity);
|
||||
}
|
||||
|
||||
// build unique identifier which will be used in the topic, also used as object_id
|
||||
// and becomes the Entity ID in HA
|
||||
// build unique identifier also used as object_id and becomes the Entity ID in HA
|
||||
char uniq_id[70];
|
||||
if (Mqtt::multiple_instances()) {
|
||||
// prefix base name to each uniq_id and use the shortname
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||
} else {
|
||||
// old v3.4 style
|
||||
// if there is no en_name take the shortname
|
||||
if (en_name == nullptr || strlen(en_name) == 0) {
|
||||
strlcpy(uniq_id, entity, sizeof(uniq_id));
|
||||
// take en_name and replace all spaces and lowercase it
|
||||
char uniq_s[40];
|
||||
strlcpy(uniq_s, en_name, sizeof(uniq_s));
|
||||
Helpers::replace_char(uniq_s, ' ', '_');
|
||||
if (EMSdevice::tag_to_string(tag).empty()) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str());
|
||||
} else {
|
||||
// old v3.4 style
|
||||
// take en_name and replace all spaces and lowercase it
|
||||
char uniq_s[40];
|
||||
strlcpy(uniq_s, en_name, sizeof(uniq_s));
|
||||
Helpers::replace_char(uniq_s, ' ', '_');
|
||||
if (EMSdevice::tag_to_string(tag).empty()) {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str());
|
||||
} else {
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str());
|
||||
}
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user