mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-28 01:29:07 +03:00
publish mqtt emsesp on-change messages on connect
This commit is contained in:
@@ -378,10 +378,20 @@ void WebCustomEntityService::publish_single(CustomEntityItem & entity) {
|
||||
}
|
||||
|
||||
// publish to Mqtt
|
||||
void WebCustomEntityService::publish() {
|
||||
if (!Mqtt::enabled() || customEntityItems_->empty()) {
|
||||
void WebCustomEntityService::publish(const bool force) {
|
||||
if (!Mqtt::connected() || customEntityItems_->empty()) {
|
||||
return;
|
||||
}
|
||||
if (force) {
|
||||
if (Mqtt::publish_single()) {
|
||||
for (CustomEntityItem & entityItem : *customEntityItems_) {
|
||||
publish_single(entityItem);
|
||||
}
|
||||
return;
|
||||
} else if (!EMSESP::mqtt_.get_publish_onchange(0)) {
|
||||
return; // wait for first time periode
|
||||
}
|
||||
}
|
||||
|
||||
JsonDocument doc;
|
||||
JsonObject output = doc.to<JsonObject>();
|
||||
|
||||
@@ -58,7 +58,7 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
||||
|
||||
void begin();
|
||||
void publish_single(CustomEntityItem & entity);
|
||||
void publish();
|
||||
void publish(const bool force = false);
|
||||
bool command_setvalue(const char * value, const int8_t id, const char * name);
|
||||
bool get_value_info(JsonObject output, const char * cmd);
|
||||
void get_value_json(JsonObject output, CustomEntityItem const & entity);
|
||||
|
||||
@@ -105,10 +105,6 @@ StateUpdateResult WebScheduler::update(JsonObject root, WebScheduler & webSchedu
|
||||
CommandFlag::ADMIN_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
EMSESP::webSchedulerService.ha_reset();
|
||||
EMSESP::webSchedulerService.publish();
|
||||
|
||||
return StateUpdateResult::CHANGED;
|
||||
}
|
||||
|
||||
@@ -217,17 +213,17 @@ void WebSchedulerService::publish_single(const char * name, const bool state) {
|
||||
|
||||
// publish to Mqtt
|
||||
void WebSchedulerService::publish(const bool force) {
|
||||
if (force) {
|
||||
ha_configdone_ = false;
|
||||
}
|
||||
|
||||
if (!Mqtt::enabled() || scheduleItems_->empty()) {
|
||||
if (!Mqtt::connected() || scheduleItems_->empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mqtt::publish_single() && force) {
|
||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||
publish_single(scheduleItem.name, scheduleItem.active);
|
||||
if (force) {
|
||||
if (Mqtt::publish_single()) {
|
||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||
publish_single(scheduleItem.name, scheduleItem.active);
|
||||
}
|
||||
return;
|
||||
} else if (!EMSESP::mqtt_.get_publish_onchange(0)) {
|
||||
return; // wait for first time periode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user