publish mqtt emsesp on-change messages on connect

This commit is contained in:
MichaelDvP
2025-12-19 17:14:50 +01:00
parent b4affbff6d
commit 1b8b72c443
6 changed files with 42 additions and 21 deletions

View File

@@ -664,13 +664,18 @@ void AnalogSensor::remove_ha_topic(const int8_t type, const uint8_t gpio) const
void AnalogSensor::publish_values(const bool force) {
uint8_t num_sensors = sensors_.size();
if (num_sensors == 0) {
if (!Mqtt::connected() || num_sensors == 0) {
return;
}
if (force && Mqtt::publish_single()) {
for (const auto & sensor : sensors_) {
publish_sensor(sensor);
if (force) {
if (Mqtt::publish_single()) {
for (const auto & sensor : sensors_) {
publish_sensor(sensor);
}
return;
} else if (!EMSESP::mqtt_.get_publish_onchange(0)) {
return; // wait for first time periode
}
}