diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 6285bbc06..7b3f6a94f 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -40,8 +40,9 @@ For more details go to [www.emsesp.org](https://www.emsesp.org/). - autodetect and download firmware upgrades via the WebUI - command 'show log' that lists out the current weblog buffer, showing last messages. - default web log buffer to 25 lines for ESP32s with no PSRAM -- Try and determine correct board profile if none is set +- try and determine correct board profile if none is set during boot - auto Scroll in WebLog UI - reduced delay so incoming logs are faster +- uploading custom support info for Guest users [#2054] ## Fixed @@ -70,3 +71,4 @@ For more details go to [www.emsesp.org](https://www.emsesp.org/). - WebLog UI matches color schema of the terminal console correctly - Updated Web libraries, ArduinoJson - Help page doesn't show detailed tech info if the user is not 'admin' role [#2054](https://github.com/emsesp/EMS-ESP32/issues/2054) +- removed system command `allvalues` and moved to an action called `export` diff --git a/src/locale_translations.h b/src/locale_translations.h index b48f469a2..2fbbc0ec9 100644 --- a/src/locale_translations.h +++ b/src/locale_translations.h @@ -75,7 +75,6 @@ MAKE_WORD_TRANSLATION(schedule_cmd, "enable schedule item", "Aktiviere Zeitplane MAKE_WORD_TRANSLATION(entity_cmd, "set custom value on ems", "Sende eigene Entitäten zu EMS", "verstuur custom waarde naar EMS", "", "wyślij własną wartość na EMS", "", "", "emp üzerinde özel değer ayarla", "imposta valori personalizzati su EMS", "nastaviť vlastnú hodnotu na ems") // TODO translate MAKE_WORD_TRANSLATION(commands_response, "get response", "Hole Antwort", "Verzoek om antwoord", "", "uzyskaj odpowiedź", "", "", "gelen cevap", "", "získať odpoveď") // TODO translate MAKE_WORD_TRANSLATION(coldshot_cmd, "send a cold shot of water", "Zugabe einer Menge kalten Wassers", "", "", "uruchom tryśnięcie zimnej wody", "", "", "soğuk su gönder", "", "pošlite studenú dávku vody") // TODO translate -MAKE_WORD_TRANSLATION(allvalues_cmd, "output all values in system", "Alle Werte im System ausgeben", "", "", "wyświetl wszystkie wartości", "", "", "", "", "vypísať všetky hodnoty") // TODO remove MAKE_WORD_TRANSLATION(message_cmd, "send a message", "Eine Nachricht senden", "", "", "", "", "", "", "", "poslať správu") // TODO translate MAKE_WORD_TRANSLATION(values_cmd, "list all values", "Liste alle Werte auf", "", "", "", "", "", "", "", "vypísať všetky hodnoty") // TODO translate diff --git a/src/system.cpp b/src/system.cpp index d5478b512..dd506cc6c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -111,45 +111,6 @@ bool System::command_response(const char * value, const int8_t id, JsonObject ou return true; } -// output all the devices and the values -// not system info -// TODO remove? -bool System::command_allvalues(const char * value, const int8_t id, JsonObject output) { - JsonDocument doc; - JsonObject device_output; - // default to values - if (value == nullptr || strlen(value) == 0) { - value = F_(values); - } - - // System Entities - // device_output = output["System"].to(); - // get_value_info(device_output, value); - - // EMS-Device Entities - for (const auto & emsdevice : EMSESP::emsdevices) { - std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string(); - device_output = output[title].to(); - emsdevice->get_value_info(device_output, value, DeviceValueTAG::TAG_NONE); - } - - // Custom Entities - device_output = output["Custom Entities"].to(); - EMSESP::webCustomEntityService.get_value_info(device_output, value); - - // Scheduler - device_output = output["Scheduler"].to(); - EMSESP::webSchedulerService.get_value_info(device_output, value); - - // Sensors - device_output = output["Analog Sensors"].to(); - EMSESP::analogsensor_.get_value_info(device_output, value); - device_output = output["Temperature Sensors"].to(); - EMSESP::temperaturesensor_.get_value_info(device_output, value); - - return true; -} - // fetch device values bool System::command_fetch(const char * value, const int8_t id) { std::string value_s; @@ -339,6 +300,8 @@ void System::system_restart(const char * partitionname) { delay(1000); // wait 1 second ESP.restart(); #else + restart_requested(false); + restart_pending(false); if (partitionname != nullptr) { LOG_INFO("Restarting EMS-ESP from %s partition", partitionname); } else { @@ -875,7 +838,6 @@ void System::commands_init() { // these commands will return data in JSON format Command::add(EMSdevice::DeviceType::SYSTEM, F("response"), System::command_response, FL_(commands_response)); - Command::add(EMSdevice::DeviceType::SYSTEM, F("allvalues"), System::command_allvalues, FL_(allvalues_cmd)); // TODO remove // MQTT subscribe "ems-esp/system/#" Mqtt::subscribe(EMSdevice::DeviceType::SYSTEM, "system/#", nullptr); // use empty function callback diff --git a/src/system.h b/src/system.h index 22b89be5a..9aea1dd34 100644 --- a/src/system.h +++ b/src/system.h @@ -65,7 +65,6 @@ class System { static bool command_message(const char * value, const int8_t id); static bool command_info(const char * value, const int8_t id, JsonObject output); static bool command_response(const char * value, const int8_t id, JsonObject output); - static bool command_allvalues(const char * value, const int8_t id, JsonObject output); // TODO fix static bool get_value_info(JsonObject root, const char * cmd); static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val); diff --git a/src/test/test.cpp b/src/test/test.cpp index 60f7b9ebb..63f9241bf 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -989,11 +989,26 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const // EMSESP::webAPIService.webAPIService(&request); request.method(HTTP_POST); - char data_api[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}"; - deserializeJson(doc, data_api); - json = doc.as(); + + char data1[] = "{\"device\":\"system\", \"cmd\":\"restart\",\"id\":-1}"; + deserializeJson(doc, data1); request.url("/api"); - EMSESP::webAPIService.webAPIService(&request, json); + EMSESP::webAPIService.webAPIService(&request, doc.as()); + + char data2[] = "{\"action\":\"customSupport\", \"param\":\"hello\"}"; + deserializeJson(doc, data2); + request.url("/rest/action"); + EMSESP::webStatusService.action(&request, doc.as()); + + char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}"; + deserializeJson(doc, data3); + request.url("/rest/action"); + EMSESP::webStatusService.action(&request, doc.as()); + + char data4[] = "{\"action\":\"export\", \"param\":\"allvalues\"}"; + deserializeJson(doc, data4); + request.url("/rest/action"); + EMSESP::webStatusService.action(&request, doc.as()); // request.url("/api/thermostat"); // EMSESP::webAPIService.webAPIService(&request); diff --git a/src/version.h b/src/version.h index f18b9395f..b78c093ae 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.7.0-dev.40" +#define EMSESP_APP_VERSION "3.7.0-dev.41" diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 167a0f654..148f36f3a 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -584,7 +584,7 @@ void WebSchedulerService::test() { test_value = "(custom/seltemp)"; command("test5", test_cmd.c_str(), compute(test_value).c_str()); - // this will fail unless test("boiler") is loaded + // note: this will fail unless test("boiler") is loaded before hand test_value = "(boiler/outdoortemp)"; command("test6", test_cmd.c_str(), compute(test_value).c_str()); diff --git a/src/web/WebStatusService.cpp b/src/web/WebStatusService.cpp index 417a59e02..7260bc2eb 100644 --- a/src/web/WebStatusService.cpp +++ b/src/web/WebStatusService.cpp @@ -154,10 +154,6 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json) std::string action = json["action"]; std::string param = json["param"]; // is optional - // TODO remove - Serial.printf("Action: %s\n", action.c_str()); - Serial.printf("Param: %s\n", param.c_str()); - bool ok = true; if (action == "checkUpgrade") { ok = checkUpgrade(root, param); @@ -167,6 +163,17 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json) ok = customSupport(root); } +#if defined(EMSESP_UNITY) + // store the result so we can test with Unity later + storeResponse(output); +#endif +#if defined(EMSESP_STANDALONE) && !defined(EMSESP_UNITY) + Serial.printf("%sweb output: %s[%s]", COLOR_WHITE, COLOR_BRIGHT_CYAN, request->url().c_str()); + Serial.printf(" %s(%d)%s ", ok ? COLOR_BRIGHT_GREEN : COLOR_BRIGHT_RED, ok ? 200 : 400, COLOR_YELLOW); + serializeJson(root, Serial); + Serial.println(COLOR_RESET); +#endif + // send response if (!ok) { request->send(400); @@ -192,6 +199,34 @@ bool WebStatusService::checkUpgrade(JsonObject root, std::string & latest_versio return true; } +// output all the devices and the values +void WebStatusService::allvalues(JsonObject output) { + JsonDocument doc; + JsonObject device_output; + auto value = F_(values); + + // EMS-Device Entities + for (const auto & emsdevice : EMSESP::emsdevices) { + std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string(); + device_output = output[title].to(); + emsdevice->get_value_info(device_output, value, DeviceValueTAG::TAG_NONE); + } + + // Custom Entities + device_output = output["Custom Entities"].to(); + EMSESP::webCustomEntityService.get_value_info(device_output, value); + + // Scheduler + device_output = output["Scheduler"].to(); + EMSESP::webSchedulerService.get_value_info(device_output, value); + + // Sensors + device_output = output["Analog Sensors"].to(); + EMSESP::analogsensor_.get_value_info(device_output, value); + device_output = output["Temperature Sensors"].to(); + EMSESP::temperaturesensor_.get_value_info(device_output, value); +} + // returns data for a specific feature/settings as a json object bool WebStatusService::exportData(JsonObject root, std::string & type) { root["type"] = type; @@ -211,6 +246,8 @@ bool WebStatusService::exportData(JsonObject root, std::string & type) { System::extractSettings(EMSESP_CUSTOMIZATION_FILE, "Customizations", root); } else if (type == "entities") { System::extractSettings(EMSESP_CUSTOMENTITY_FILE, "Entities", root); + } else if (type == "allvalues") { + allvalues(root); } else { return false; } diff --git a/src/web/WebStatusService.h b/src/web/WebStatusService.h index 3e04b2ce0..bc887156c 100644 --- a/src/web/WebStatusService.h +++ b/src/web/WebStatusService.h @@ -2,7 +2,6 @@ #define WebStatusService_h #define EMSESP_SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus" - #define EMSESP_ACTION_SERVICE_PATH "/rest/action" #include // for version checking @@ -13,7 +12,10 @@ class WebStatusService { public: WebStatusService(AsyncWebServer * server, SecurityManager * securityManager); +// make all functions public so we can test in the debug and standalone mode +#ifndef EMSESP_STANDALONE protected: +#endif void systemStatus(AsyncWebServerRequest * request); void action(AsyncWebServerRequest * request, JsonVariant json); @@ -21,6 +23,7 @@ class WebStatusService { bool checkUpgrade(JsonObject root, std::string & latest_version); bool exportData(JsonObject root, std::string & type); bool customSupport(JsonObject root); + void allvalues(JsonObject output); }; } // namespace emsesp