[select] Return std::string_view from current_option()

This commit is contained in:
J. Nick Koston
2026-01-08 23:05:30 -10:00
parent 6596186240
commit 26671cb1ee
2 changed files with 2 additions and 0 deletions
@@ -709,6 +709,7 @@ void PrometheusHandler::select_row_(AsyncResponseStream *stream, select::Select
stream->print(ESPHOME_F("\",name=\""));
stream->print(relabel_name_(obj).c_str());
stream->print(ESPHOME_F("\",value=\""));
// current_option() returns string_view pointing to null-terminated string literals from codegen
stream->print(obj->current_option().data());
stream->print(ESPHOME_F("\"} "));
stream->print(ESPHOME_F("1.0"));
@@ -1420,6 +1420,7 @@ std::string WebServer::select_json_(select::Select *obj, std::string_view value,
json::JsonBuilder builder;
JsonObject root = builder.root();
// value points to null-terminated string literals from codegen (via current_option())
set_json_icon_state_value(root, obj, "select", value.data(), value.data(), start_config);
if (start_config == DETAIL_ALL) {
JsonArray opt = root[ESPHOME_F("option")].to<JsonArray>();