From 9d3456cb3ab1d9a70593cbd648d518bdbba32b22 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 17 Sep 2023 09:22:25 +0200 Subject: [PATCH] show scheduler/custom always --- src/analogsensor.h | 4 ---- src/command.cpp | 36 ++++++++++++++++++--------------- src/web/WebEntityService.cpp | 15 +++++++------- src/web/WebSchedulerService.cpp | 15 +++++++------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/analogsensor.h b/src/analogsensor.h index cc931539b..132b20e50 100644 --- a/src/analogsensor.h +++ b/src/analogsensor.h @@ -23,10 +23,6 @@ #include "mqtt.h" #include "console.h" -#ifndef EMSESP_STANDALONE -#include "driver/adc.h" -#endif - #include namespace emsesp { diff --git a/src/command.cpp b/src/command.cpp index 0ef48306e..b3633db8b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -541,19 +541,23 @@ bool Command::device_has_commands(const uint8_t device_type) { } if (device_type == EMSdevice::DeviceType::SCHEDULER) { - return EMSESP::webSchedulerService.has_commands(); + return true; // we always have info + // return EMSESP::webSchedulerService.has_commands(); } if (device_type == EMSdevice::DeviceType::CUSTOM) { - return (EMSESP::webEntityService.count_entities() != 0); + return true; // we always have info + // return (EMSESP::webEntityService.count_entities() != 0); } if (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR) { - return (EMSESP::temperaturesensor_.have_sensors()); + return true; // we always have info + // return (EMSESP::temperaturesensor_.have_sensors()); } if (device_type == EMSdevice::DeviceType::ANALOGSENSOR) { - return (EMSESP::analogsensor_.have_sensors()); + return EMSESP::system_.analog_enabled(); + // return (EMSESP::analogsensor_.have_sensors()); } for (const auto & emsdevice : EMSESP::emsdevices) { @@ -574,13 +578,13 @@ bool Command::device_has_commands(const uint8_t device_type) { void Command::show_devices(uuid::console::Shell & shell) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SYSTEM)); - if (EMSESP::webSchedulerService.has_commands()) { + // if (EMSESP::webSchedulerService.has_commands()) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER)); - } - if (EMSESP::temperaturesensor_.have_sensors()) { + // } + // if (EMSESP::temperaturesensor_.have_sensors()) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); - } - if (EMSESP::analogsensor_.have_sensors()) { + // } + if (EMSESP::analogsensor_.analog_enabled()) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR)); } @@ -608,7 +612,7 @@ void Command::show_all(uuid::console::Shell & shell) { show(shell, EMSdevice::DeviceType::SYSTEM, true); // show Custom - if (EMSESP::webEntityService.has_commands()) { + // if (EMSESP::webEntityService.has_commands()) { shell.print(COLOR_BOLD_ON); shell.print(COLOR_YELLOW); shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::CUSTOM)); @@ -618,10 +622,10 @@ void Command::show_all(uuid::console::Shell & shell) { shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED); shell.print(COLOR_RESET); show(shell, EMSdevice::DeviceType::CUSTOM, true); - } + // } // show scheduler - if (EMSESP::webSchedulerService.has_commands()) { + // if (EMSESP::webSchedulerService.has_commands()) { shell.print(COLOR_BOLD_ON); shell.print(COLOR_YELLOW); shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER)); @@ -631,17 +635,17 @@ void Command::show_all(uuid::console::Shell & shell) { shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED); shell.print(COLOR_RESET); show(shell, EMSdevice::DeviceType::SCHEDULER, true); - } + // } // show sensors - if (EMSESP::temperaturesensor_.have_sensors()) { + // if (EMSESP::temperaturesensor_.have_sensors()) { shell.print(COLOR_BOLD_ON); shell.print(COLOR_YELLOW); shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); shell.print(COLOR_RESET); show(shell, EMSdevice::DeviceType::TEMPERATURESENSOR, true); - } - if (EMSESP::analogsensor_.have_sensors()) { + // } + if (EMSESP::analogsensor_.analog_enabled()) { shell.print(COLOR_BOLD_ON); shell.print(COLOR_YELLOW); shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR)); diff --git a/src/web/WebEntityService.cpp b/src/web/WebEntityService.cpp index 1919c5eb3..a183ed0ac 100644 --- a/src/web/WebEntityService.cpp +++ b/src/web/WebEntityService.cpp @@ -217,24 +217,25 @@ void WebEntityService::render_value(JsonObject & output, EntityItem entity, cons // process json output for info/commands and value_info bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) { EMSESP::webEntityService.read([&](WebEntity & webEntity) { entityItems = &webEntity.entityItems; }); - if (entityItems->size() == 0) { - return false; - } - if (Helpers::toLower(cmd) == "commands") { - output["info"] = "list all values"; - output["commands"] = "list all commands"; + if (Helpers::toLower(cmd) == F_(commands)) { + output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); + output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd)); for (const auto & entity : *entityItems) { output[entity.name] = "custom entitiy"; } return true; } - if (strlen(cmd) == 0 || Helpers::toLower(cmd) == "values" || Helpers::toLower(cmd) == "info") { + if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) { // list all names for (const EntityItem & entity : *entityItems) { render_value(output, entity); } return (output.size() != 0); } + if (entityItems->size() == 0) { + output["message"] = "no custom entities"; + return false; + } char command_s[30]; strlcpy(command_s, cmd, sizeof(command_s)); char * attribute_s = nullptr; diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index b7b166a26..4e84f9c31 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -132,12 +132,9 @@ bool WebSchedulerService::command_setvalue(const char * value, const std::string // process json output for info/commands and value_info bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd) { EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; }); - if (scheduleItems->size() == 0) { - return false; - } - if (Helpers::toLower(cmd) == "commands") { - output["info"] = "lists all values"; - output["commands"] = "lists all commands"; + if (Helpers::toLower(cmd) == F_(commands)) { + output[F_(info)] = Helpers::translated_word(FL_(info_cmd)); + output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd)); for (const ScheduleItem & scheduleItem : *scheduleItems) { if (!scheduleItem.name.empty()) { output[scheduleItem.name] = "activate schedule"; @@ -145,7 +142,7 @@ bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd) } return true; } - if (strlen(cmd) == 0 || Helpers::toLower(cmd) == "values" || Helpers::toLower(cmd) == "info") { + if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) { // list all names for (const ScheduleItem & scheduleItem : *scheduleItems) { if (!scheduleItem.name.empty()) { @@ -161,6 +158,10 @@ bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd) } return (output.size() > 0); } + if (scheduleItems->size() == 0) { + output["message"] = "no schedules"; + return false; + } char command_s[30]; strlcpy(command_s, cmd, sizeof(command_s)); char * attribute_s = nullptr;