mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-06-14 11:56:32 +03:00
call scheduler immediate from dashboard
This commit is contained in:
@@ -478,8 +478,8 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
||||
}
|
||||
}
|
||||
|
||||
// show scheduler, with name, on/off, unless it's of type SCHEDULE_IMMEDIATE
|
||||
if (EMSESP::webSchedulerService.count_entities(true)) {
|
||||
// show scheduler items
|
||||
if (EMSESP::webSchedulerService.count_entities()) {
|
||||
JsonObject obj = nodes.add<JsonObject>();
|
||||
obj["id"] = EMSdevice::DeviceTypeUniqueID::SCHEDULER_UID; // it's unique id
|
||||
obj["t"] = EMSdevice::DeviceType::SCHEDULER; // device type number
|
||||
@@ -488,20 +488,21 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
|
||||
|
||||
EMSESP::webSchedulerService.read([&](const WebScheduler & webScheduler) {
|
||||
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
||||
if (scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_IMMEDIATE) {
|
||||
continue;
|
||||
}
|
||||
JsonObject node = nodes.add<JsonObject>();
|
||||
node["id"] = (EMSdevice::DeviceTypeUniqueID::SCHEDULER_UID * 100) + count++;
|
||||
|
||||
JsonObject dv = node["dv"].to<JsonObject>();
|
||||
dv["id"] = std::string("00") + scheduleItem.name;
|
||||
dv["c"] = scheduleItem.name;
|
||||
char s[12];
|
||||
dv["v"] = Helpers::render_boolean(s, scheduleItem.active, true);
|
||||
JsonArray l = dv["l"].to<JsonArray>();
|
||||
l.add(Helpers::render_boolean(s, false, true));
|
||||
l.add(Helpers::render_boolean(s, true, true));
|
||||
|
||||
// for immediate schedules, we don't show the active/inactive state or on/off options
|
||||
if (scheduleItem.flags != SCHEDULEFLAG_SCHEDULE_IMMEDIATE) {
|
||||
char s[12];
|
||||
dv["v"] = Helpers::render_boolean(s, scheduleItem.active, true);
|
||||
JsonArray l = dv["l"].to<JsonArray>();
|
||||
l.add(Helpers::render_boolean(s, false, true)); // False option
|
||||
l.add(Helpers::render_boolean(s, true, true)); // True option
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -332,17 +332,9 @@ void WebSchedulerService::publish(const bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
// count number of entries, default: only named items
|
||||
// if exclude_immediate is true, include those that are of type SCHEDULEFLAG_SCHEDULE_IMMEDIATE
|
||||
uint8_t WebSchedulerService::count_entities(bool exclude_immediate) {
|
||||
uint8_t count = 0;
|
||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||
// count all except SCHEDULE_IMMEDIATE if exclude_immediate is true, else count all
|
||||
if (!exclude_immediate || scheduleItem.flags != SCHEDULEFLAG_SCHEDULE_IMMEDIATE) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
// count number of scheduler entries
|
||||
uint8_t WebSchedulerService::count_entities() {
|
||||
return static_cast<uint8_t>(scheduleItems_ ? scheduleItems_->size() : 0);
|
||||
}
|
||||
|
||||
// execute scheduled command
|
||||
|
||||
@@ -85,7 +85,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
|
||||
void ha_reset() {
|
||||
ha_configdone_ = false;
|
||||
}
|
||||
uint8_t count_entities(bool exclude_immediate = false);
|
||||
uint8_t count_entities();
|
||||
bool onChange(const char * cmd);
|
||||
|
||||
bool executeSchedule(const char * name);
|
||||
|
||||
Reference in New Issue
Block a user