fix HA sensor referencing

This commit is contained in:
proddy
2025-12-17 11:37:46 +01:00
parent 55621e12d9
commit 310afe3ab8
3 changed files with 10 additions and 7 deletions

View File

@@ -675,7 +675,8 @@ void AnalogSensor::publish_values(const bool force) {
}
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
JsonObject obj = doc.to<JsonObject>();
bool ha_dev_created = false;
for (auto & sensor : sensors_) {
if (Mqtt::is_nested()) {
@@ -807,9 +808,12 @@ void AnalogSensor::publish_values(const bool force) {
std::string topic_str(topic);
config["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s;
// dev section with model is only created on the 1st sensor
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Analog Sensors", nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_dev_created);
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
ha_dev_created = sensor.ha_registered;
}
}