From 8a45e790718f658c955af63393db732c7dd5a437 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 8 Jun 2026 10:03:32 +0200 Subject: [PATCH] updates --- src/core/locale_translations.h | 2 +- src/test/test.cpp | 5 ++++- src/test/test.h | 2 +- src/web/WebCommandService.cpp | 38 ++++++++++++++++++++++----------- src/web/WebSchedulerService.cpp | 18 ++++++++++++++++ 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/core/locale_translations.h b/src/core/locale_translations.h index db34b25f5..f5ece66ac 100644 --- a/src/core/locale_translations.h +++ b/src/core/locale_translations.h @@ -75,7 +75,7 @@ MAKE_WORD_TRANSLATION(format_cmd, "factory reset EMS-ESP", "EMS-ESP auf Werksein MAKE_WORD_TRANSLATION(watch_cmd, "watch incoming telegrams", "Beobachte eingehende Telegramme", "inkomende telegrammen bekijken", "visa inkommande telegram", "obserwuj przyczodzące telegramy", "se innkommende telegrammer", "surveiller les télégrammes entrants", "Gelen telegramları izle", "guardare i telegrammi in arrivo", "sledovať prichádzajúce telegramy", "sledovat příchozí telegramy") MAKE_WORD_TRANSLATION(publish_cmd, "publish all to MQTT", "Publiziere MQTT", "publiceer alles naar MQTT", "publicera allt till MQTT", "opublikuj wszystko na MQTT", "Publiser alt til MQTT", "publier tout vers MQTT", "Hepsini MQTTye gönder", "pubblica tutto su MQTT", "zverejniť všetko na MQTT", "publikovat vše do MQTT") MAKE_WORD_TRANSLATION(system_info_cmd, "show system info", "Zeige Systeminformationen", "toon systeemstatus", "visa systeminformation", "pokaż status systemu", "vis system status", "afficher les informations système", "Sistem Durumunu Göster", "visualizza stati di sistema", "zobraziť stav systému", "zobrazit informace o systému") -MAKE_WORD_TRANSLATION(schedule_cmd, "enable schedule item", "Aktiviere Zeitplanelemente", "activeer tijdschema item", "aktivera schemalagt objekt", "aktywuj wybrany harmonogram", "aktiver planlagt element", "activer élément programmé", "program öğesini etkinleştir", "abilitare l'elemento programmato", "povoliť položku plánovania", "povolit položku plánování") +MAKE_WORD_TRANSLATION(schedule_cmd, "enable/disable schedule item", "Aktiviere/Deaktiviere Zeitplanelemente", "activeer/deactiveer tijdschema item", "aktivera/deaktivera schemalagt objekt", "aktywuj/deaktywuj wybrany harmonogram", "aktiver/deaktiver planlagt element", "activer/deactiver élément programmé", "program öğesini etkinleştir/devre dışı bırak", "abilitare/disabilitare l'elemento programmato", "povoliť/deaktivovať položku plánovania", "povolit/deaktivovat položku plánování") MAKE_WORD_TRANSLATION(command_cmd, "execute command", "Befehl ausführen", "opdracht uitvoeren", "kör kommando", "wykonaj polecenie", "kjør kommando", "exécuter commande", "komut çalıştır", "esegui comando", "vykonať príkaz", "provést příkaz") MAKE_WORD_TRANSLATION(entity_cmd, "set custom value", "Sende eigene Entitäten", "verstuur custom waarde", "sätt ett eget värde", "wyślij własną wartość", "sett egendefinert verdi", "définir valeur personnalisée", "özel değer ayarla", "imposta valori personalizzati", "nastaviť vlastnú hodnotu", "nastavit vlastní hodnotu") MAKE_WORD_TRANSLATION(commands_response, "get response", "Hole Antwort", "Verzoek om antwoord", "hämta svar", "uzyskaj odpowiedź", "få svar", "obtenir réponse", "yanıt al", "ottieni risposta", "získať odpoveď", "získat odpověď") diff --git a/src/test/test.cpp b/src/test/test.cpp index ba2c64842..d0435583a 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -350,6 +350,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const EMSESP::webCustomEntityService.load_test_data(); // custom entities EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors + EMSESP::webCommandService.load_test_data(); // add command items EMSESP::webSchedulerService.load_test_data(); // add scheduler data shell.invoke_command("show values"); @@ -406,7 +407,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const if (command == "scheduler") { shell.printfln("Adding Scheduler items..."); - // add some dummy entities + EMSESP::webCommandService.load_test_data(); EMSESP::webSchedulerService.load_test_data(); #ifdef EMSESP_STANDALONE @@ -1116,6 +1117,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const EMSESP::webCustomEntityService.load_test_data(); // custom entities EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors + EMSESP::webCommandService.load_test_data(); // add command items EMSESP::webSchedulerService.load_test_data(); // run scheduler tests, and conditions JsonDocument doc; @@ -1379,6 +1381,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const EMSESP::webCustomEntityService.load_test_data(); // custom entities EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors + EMSESP::webCommandService.load_test_data(); // add command items EMSESP::webSchedulerService.load_test_data(); // run scheduler tests, and conditions request.method(HTTP_GET); diff --git a/src/test/test.h b/src/test/test.h index 9ca860f51..51be36cc9 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -64,7 +64,7 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "hpmode" // #define EMSESP_DEBUG_DEFAULT "shuntingyard" // #define EMSESP_DEBUG_DEFAULT "src" -#define EMSESP_DEBUG_DEFAULT "led" +// #define EMSESP_DEBUG_DEFAULT "led" #ifndef EMSESP_DEBUG_DEFAULT #define EMSESP_DEBUG_DEFAULT "general" diff --git a/src/web/WebCommandService.cpp b/src/web/WebCommandService.cpp index cf841c188..9e7445f30 100644 --- a/src/web/WebCommandService.cpp +++ b/src/web/WebCommandService.cpp @@ -37,10 +37,14 @@ void WebCommandService::begin() { char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; snprintf(topic, sizeof(topic), "%s/#", F_(commands)); Mqtt::subscribe(EMSdevice::DeviceType::COMMAND, topic, nullptr); + +#if defined(EMSESP_TEST) + load_test_data(); +#endif } void WebCommands::read(WebCommands & webCommands, JsonObject root) { - JsonArray items = root["commands"].to(); + JsonArray items = root["commands"].to(); uint8_t counter = 1; for (const CommandItem & ci : webCommands.commandItems) { JsonObject obj = items.add(); @@ -57,8 +61,8 @@ StateUpdateResult WebCommands::update(JsonObject root, WebCommands & webCommands auto items = root["commands"].as(); for (const JsonObject item : items) { - auto ci = CommandItem(); - ci.cmd = item["cmd"].as(); + auto ci = CommandItem(); + ci.cmd = item["cmd"].as(); ci.value = item["value"].as(); strlcpy(ci.name, item["name"].as(), sizeof(ci.name)); @@ -67,9 +71,7 @@ StateUpdateResult WebCommands::update(JsonObject root, WebCommands & webCommands Command::add( EMSdevice::DeviceType::COMMAND, webCommands.commandItems.back().name, - [](const char * value, const int8_t id) { - return EMSESP::webCommandService.executeCommand(value); - }, + [](const char * value, const int8_t id) { return EMSESP::webCommandService.executeCommand(value); }, FL_(command_cmd), CommandFlag::ADMIN_ONLY); } @@ -99,7 +101,7 @@ bool WebCommandService::executeCommand(const char * name) { EMSESP::logger().warning("Command '%s' not found", name ? name : ""); return false; } - return executeCommand(ci->name, ci->cmd, ci->value); + return executeCommand(ci->name, std::string(ci->cmd.c_str()), std::string(ci->value.c_str())); } // execute a command with explicit cmd and value strings @@ -111,7 +113,7 @@ bool WebCommandService::executeCommand(const char * name, const std::string & co JsonDocument doc; if (deserializeJson(doc, cmd) == DeserializationError::Ok) { std::string url = doc["url"] | ""; - auto q = url.find_first_of('?'); + auto q = url.find_first_of('?'); if (q != std::string::npos) { auto s = url.substr(q + 1); auto l = s.length(); @@ -269,21 +271,33 @@ uint8_t WebCommandService::count_entities() { #if defined(EMSESP_TEST) void WebCommandService::load_test_data() { + Command::erase_device_commands(EMSdevice::DeviceType::COMMAND); update([&](WebCommands & webCommands) { webCommands.commandItems.clear(); - auto ci = CommandItem(); - ci.cmd = "system/fetch"; + auto ci = CommandItem(); + ci.cmd = "system/fetch"; ci.value = "10"; strcpy(ci.name, "test_cmd1"); webCommands.commandItems.push_back(ci); - ci = CommandItem(); - ci.cmd = "system/message"; + ci = CommandItem(); + ci.cmd = "system/message"; ci.value = "hello"; strcpy(ci.name, "test_cmd2"); webCommands.commandItems.push_back(ci); + for (const auto & item : webCommands.commandItems) { + if (item.name[0] != '\0') { + Command::add( + EMSdevice::DeviceType::COMMAND, + item.name, + [](const char * value, const int8_t id) { return EMSESP::webCommandService.executeCommand(value); }, + FL_(command_cmd), + CommandFlag::ADMIN_ONLY); + } + } + return StateUpdateResult::CHANGED; }); } diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 2c01d9777..049eaa404 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -49,6 +49,10 @@ void WebSchedulerService::begin() { #endif } #endif + +#if defined(EMSESP_TEST) + load_test_data(); +#endif } // this creates the scheduler file, saving it to the FS @@ -454,6 +458,7 @@ void WebSchedulerService::scheduler_task(void * pvParameters) { #if defined(EMSESP_TEST) void WebSchedulerService::load_test_data() { + Command::erase_device_commands(EMSdevice::DeviceType::SCHEDULER); update([&](WebScheduler & webScheduler) { webScheduler.scheduleItems.clear(); @@ -479,6 +484,19 @@ void WebSchedulerService::load_test_data() { webScheduler.scheduleItems.push_back(si); + for (const auto & item : webScheduler.scheduleItems) { + if (item.name[0] != '\0') { + Command::add( + EMSdevice::DeviceType::SCHEDULER, + item.name, + [name = std::string(item.name)](const char * value, const int8_t id) { + return EMSESP::webSchedulerService.command_setvalue(value, id, name.c_str()); + }, + FL_(schedule_cmd), + CommandFlag::ADMIN_ONLY); + } + } + return StateUpdateResult::CHANGED; }); }