This commit is contained in:
proddy
2026-06-08 10:03:32 +02:00
parent 5c4dfcb9ae
commit 8a45e79071
5 changed files with 50 additions and 15 deletions

View File

@@ -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(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(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(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(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(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ěď") 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ěď")

View File

@@ -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::webCustomEntityService.load_test_data(); // custom entities
EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS
EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors
EMSESP::webCommandService.load_test_data(); // add command items
EMSESP::webSchedulerService.load_test_data(); // add scheduler data EMSESP::webSchedulerService.load_test_data(); // add scheduler data
shell.invoke_command("show values"); 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") { if (command == "scheduler") {
shell.printfln("Adding Scheduler items..."); shell.printfln("Adding Scheduler items...");
// add some dummy entities EMSESP::webCommandService.load_test_data();
EMSESP::webSchedulerService.load_test_data(); EMSESP::webSchedulerService.load_test_data();
#ifdef EMSESP_STANDALONE #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::webCustomEntityService.load_test_data(); // custom entities
EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS
EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors 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 EMSESP::webSchedulerService.load_test_data(); // run scheduler tests, and conditions
JsonDocument doc; 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::webCustomEntityService.load_test_data(); // custom entities
EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS EMSESP::webCustomizationService.load_test_data(); // set customizations - this will overwrite any settings in the FS
EMSESP::temperaturesensor_.load_test_data(); // add temperature sensors 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 EMSESP::webSchedulerService.load_test_data(); // run scheduler tests, and conditions
request.method(HTTP_GET); request.method(HTTP_GET);

View File

@@ -64,7 +64,7 @@ namespace emsesp {
// #define EMSESP_DEBUG_DEFAULT "hpmode" // #define EMSESP_DEBUG_DEFAULT "hpmode"
// #define EMSESP_DEBUG_DEFAULT "shuntingyard" // #define EMSESP_DEBUG_DEFAULT "shuntingyard"
// #define EMSESP_DEBUG_DEFAULT "src" // #define EMSESP_DEBUG_DEFAULT "src"
#define EMSESP_DEBUG_DEFAULT "led" // #define EMSESP_DEBUG_DEFAULT "led"
#ifndef EMSESP_DEBUG_DEFAULT #ifndef EMSESP_DEBUG_DEFAULT
#define EMSESP_DEBUG_DEFAULT "general" #define EMSESP_DEBUG_DEFAULT "general"

View File

@@ -37,10 +37,14 @@ void WebCommandService::begin() {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf(topic, sizeof(topic), "%s/#", F_(commands)); snprintf(topic, sizeof(topic), "%s/#", F_(commands));
Mqtt::subscribe(EMSdevice::DeviceType::COMMAND, topic, nullptr); Mqtt::subscribe(EMSdevice::DeviceType::COMMAND, topic, nullptr);
#if defined(EMSESP_TEST)
load_test_data();
#endif
} }
void WebCommands::read(WebCommands & webCommands, JsonObject root) { void WebCommands::read(WebCommands & webCommands, JsonObject root) {
JsonArray items = root["commands"].to<JsonArray>(); JsonArray items = root["commands"].to<JsonArray>();
uint8_t counter = 1; uint8_t counter = 1;
for (const CommandItem & ci : webCommands.commandItems) { for (const CommandItem & ci : webCommands.commandItems) {
JsonObject obj = items.add<JsonObject>(); JsonObject obj = items.add<JsonObject>();
@@ -57,8 +61,8 @@ StateUpdateResult WebCommands::update(JsonObject root, WebCommands & webCommands
auto items = root["commands"].as<JsonArray>(); auto items = root["commands"].as<JsonArray>();
for (const JsonObject item : items) { for (const JsonObject item : items) {
auto ci = CommandItem(); auto ci = CommandItem();
ci.cmd = item["cmd"].as<std::string>(); ci.cmd = item["cmd"].as<std::string>();
ci.value = item["value"].as<std::string>(); ci.value = item["value"].as<std::string>();
strlcpy(ci.name, item["name"].as<const char *>(), sizeof(ci.name)); strlcpy(ci.name, item["name"].as<const char *>(), sizeof(ci.name));
@@ -67,9 +71,7 @@ StateUpdateResult WebCommands::update(JsonObject root, WebCommands & webCommands
Command::add( Command::add(
EMSdevice::DeviceType::COMMAND, EMSdevice::DeviceType::COMMAND,
webCommands.commandItems.back().name, webCommands.commandItems.back().name,
[](const char * value, const int8_t id) { [](const char * value, const int8_t id) { return EMSESP::webCommandService.executeCommand(value); },
return EMSESP::webCommandService.executeCommand(value);
},
FL_(command_cmd), FL_(command_cmd),
CommandFlag::ADMIN_ONLY); CommandFlag::ADMIN_ONLY);
} }
@@ -99,7 +101,7 @@ bool WebCommandService::executeCommand(const char * name) {
EMSESP::logger().warning("Command '%s' not found", name ? name : ""); EMSESP::logger().warning("Command '%s' not found", name ? name : "");
return false; 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 // 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; JsonDocument doc;
if (deserializeJson(doc, cmd) == DeserializationError::Ok) { if (deserializeJson(doc, cmd) == DeserializationError::Ok) {
std::string url = doc["url"] | ""; std::string url = doc["url"] | "";
auto q = url.find_first_of('?'); auto q = url.find_first_of('?');
if (q != std::string::npos) { if (q != std::string::npos) {
auto s = url.substr(q + 1); auto s = url.substr(q + 1);
auto l = s.length(); auto l = s.length();
@@ -269,21 +271,33 @@ uint8_t WebCommandService::count_entities() {
#if defined(EMSESP_TEST) #if defined(EMSESP_TEST)
void WebCommandService::load_test_data() { void WebCommandService::load_test_data() {
Command::erase_device_commands(EMSdevice::DeviceType::COMMAND);
update([&](WebCommands & webCommands) { update([&](WebCommands & webCommands) {
webCommands.commandItems.clear(); webCommands.commandItems.clear();
auto ci = CommandItem(); auto ci = CommandItem();
ci.cmd = "system/fetch"; ci.cmd = "system/fetch";
ci.value = "10"; ci.value = "10";
strcpy(ci.name, "test_cmd1"); strcpy(ci.name, "test_cmd1");
webCommands.commandItems.push_back(ci); webCommands.commandItems.push_back(ci);
ci = CommandItem(); ci = CommandItem();
ci.cmd = "system/message"; ci.cmd = "system/message";
ci.value = "hello"; ci.value = "hello";
strcpy(ci.name, "test_cmd2"); strcpy(ci.name, "test_cmd2");
webCommands.commandItems.push_back(ci); 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; return StateUpdateResult::CHANGED;
}); });
} }

View File

@@ -49,6 +49,10 @@ void WebSchedulerService::begin() {
#endif #endif
} }
#endif #endif
#if defined(EMSESP_TEST)
load_test_data();
#endif
} }
// this creates the scheduler file, saving it to the FS // this creates the scheduler file, saving it to the FS
@@ -454,6 +458,7 @@ void WebSchedulerService::scheduler_task(void * pvParameters) {
#if defined(EMSESP_TEST) #if defined(EMSESP_TEST)
void WebSchedulerService::load_test_data() { void WebSchedulerService::load_test_data() {
Command::erase_device_commands(EMSdevice::DeviceType::SCHEDULER);
update([&](WebScheduler & webScheduler) { update([&](WebScheduler & webScheduler) {
webScheduler.scheduleItems.clear(); webScheduler.scheduleItems.clear();
@@ -479,6 +484,19 @@ void WebSchedulerService::load_test_data() {
webScheduler.scheduleItems.push_back(si); 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; return StateUpdateResult::CHANGED;
}); });
} }