mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-26 16:49:11 +03:00
publish mqtt emsesp on-change messages on connect
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -511,6 +511,11 @@ void Mqtt::on_connect() {
|
||||
|
||||
// send initial MQTT messages for some of our services
|
||||
EMSESP::system_.send_heartbeat(); // send heartbeat
|
||||
// for publish on change publish the initial complete list
|
||||
EMSESP::webCustomEntityService.publish(true);
|
||||
EMSESP::webSchedulerService.publish(true);
|
||||
EMSESP::analogsensor_.publish_values(true);
|
||||
EMSESP::temperaturesensor_.publish_values(true);
|
||||
}
|
||||
|
||||
// Home Assistant Discovery - the main master Device called EMS-ESP
|
||||
|
||||
@@ -473,10 +473,15 @@ void TemperatureSensor::publish_values(const bool force) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (force && Mqtt::publish_single()) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
JsonDocument doc;
|
||||
|
||||
Reference in New Issue
Block a user