add back force, fix for non-HA

This commit is contained in:
proddy
2025-12-19 08:54:59 +01:00
parent 778fe43012
commit 179351cb6b
2 changed files with 9 additions and 5 deletions

View File

@@ -216,12 +216,16 @@ void WebSchedulerService::publish_single(const char * name, const bool state) {
}
// publish to Mqtt
void WebSchedulerService::publish() {
void WebSchedulerService::publish(const bool force) {
if (force) {
ha_configdone_ = false;
}
if (!Mqtt::enabled() || scheduleItems_->empty()) {
return;
}
if (Mqtt::publish_single()) {
if (Mqtt::publish_single() && force) {
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
publish_single(scheduleItem.name, scheduleItem.active);
}
@@ -235,7 +239,7 @@ void WebSchedulerService::publish() {
Mqtt::add_value_bool(output, (const char *)scheduleItem.name, scheduleItem.active);
// create HA config
if (!ha_configdone_) {
if (Mqtt::ha_enabled() && !ha_configdone_) {
JsonDocument config;
config["~"] = Mqtt::base();
@@ -269,7 +273,7 @@ void WebSchedulerService::publish() {
config["cmd_t"] = command_topic;
Mqtt::add_ha_bool(config.as<JsonObject>());
Mqtt::add_ha_dev_section(config.as<JsonObject>(), F_(scheduler), nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_created);
Mqtt::add_ha_dev_section(config.as<JsonObject>(), F_(scheduler), !ha_created);
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());

View File

@@ -78,7 +78,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
void begin();
void loop();
void publish_single(const char * name, const bool state);
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, const ScheduleItem & scheduleItem);