From 9665efbf38fb4fd5c0bb4b2e05b103c397bbafd8 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 5 Oct 2025 15:33:37 +0200 Subject: [PATCH] add checks, add a const, clear old scheduler items when testing standalone --- src/web/WebCustomEntityService.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index d10b18c5a..0a7676164 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -223,7 +223,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i // output of a single value // if add_uom is true it will add the UOM string to the value -void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem & entity, const bool useVal, const bool web, const bool add_uom) { +void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem const & entity, const bool useVal, const bool web, const bool add_uom) { char payload[20]; std::string name = useVal ? "value" : entity.name; switch (entity.value_type) { @@ -292,6 +292,10 @@ void WebCustomEntityService::show_values(JsonObject output) { // process json output for info/commands and value_info bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) { + if (cmd == nullptr || strlen(cmd) == 0) { + return false; + } + // if no custom entries, return empty json // even if we're looking for a specific entity // https://github.com/emsesp/EMS-ESP32/issues/1297 @@ -321,7 +325,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) // specific value info const char * attribute_s = Command::get_attribute(cmd); - for (auto & entity : *customEntityItems_) { + for (auto const & entity : *customEntityItems_) { if (Helpers::toLower(entity.name) == cmd) { get_value_json(output, entity); return Command::get_attribute(output, cmd, attribute_s); @@ -331,7 +335,7 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd) } // build the json for specific entity -void WebCustomEntityService::get_value_json(JsonObject output, CustomEntityItem & entity) { +void WebCustomEntityService::get_value_json(JsonObject output, CustomEntityItem const & entity) { output["name"] = entity.name; output["fullname"] = entity.name; output["storage"] = entity.ram ? "ram" : "ems"; @@ -689,7 +693,8 @@ bool WebCustomEntityService::get_value(std::shared_ptr telegram) #ifdef EMSESP_TEST void WebCustomEntityService::load_test_data() { update([&](WebCustomEntity & webCustomEntity) { - webCustomEntity.customEntityItems.clear(); + webCustomEntity.customEntityItems.clear(); // delete all existing entities + auto entityItem = CustomEntityItem(); // test 1