From b1eedcb1d87dd183951c7ffd0345ddcc244144aa Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 13 Mar 2025 22:46:04 +0100 Subject: [PATCH] add new return code NO_VALUE --- src/core/command.h | 3 ++- src/core/shuntingYard.hpp | 8 +++++++- src/web/WebAPIService.cpp | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/command.h b/src/core/command.h index 62517fb87..f85024b94 100644 --- a/src/core/command.h +++ b/src/core/command.h @@ -48,7 +48,8 @@ enum CommandRet : uint8_t { NOT_FOUND, // 2 ERROR, // 3 NOT_ALLOWED, // 4 - needs authentication - INVALID // 5 - invalid (tag) + INVALID, // 5 - invalid (tag) + NO_VALUE // 6 - no value }; using cmd_function_p = std::function; diff --git a/src/core/shuntingYard.hpp b/src/core/shuntingYard.hpp index c90c71cdd..3d17c4e1c 100644 --- a/src/core/shuntingYard.hpp +++ b/src/core/shuntingYard.hpp @@ -380,7 +380,13 @@ std::string commands(std::string & expr, bool quotes = true) { JsonObject output = doc_out.to(); JsonObject input = doc_in.to(); std::string cmd_s = "api/" + std::string(cmd); - emsesp::Command::process(cmd_s.c_str(), true, input, output); + + auto return_code = emsesp::Command::process(cmd_s.c_str(), true, input, output); + // check for no value (entity is valid but has no value set) + if (return_code == emsesp::CommandRet::NO_VALUE) { + return expr = ""; // just ignore for now + } + if (output["api_data"].is()) { std::string data = output["api_data"]; if (!isnum(data) && quotes) { diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index b30264ed6..89f23ad47 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -134,12 +134,13 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) { } // send the json that came back from the command call - // sequence is FAIL, OK, NOT_FOUND, ERROR, NOT_ALLOWED, INVALID + // sequence matches CommandRet in command.h (FAIL, OK, NOT_FOUND, ERROR, NOT_ALLOWED, INVALID, NO_VALUE) // 400 (bad request) // 200 (OK) // 404 (not found) // 401 (unauthorized) - int ret_codes[6] = {400, 200, 404, 400, 401, 400}; + // 400 (invalid) + int ret_codes[7] = {400, 200, 404, 400, 401, 400, 404}; response->setCode(ret_codes[return_code]); response->setLength(); response->setContentType("application/json; charset=utf-8");