Resolve esphome::optional vs std::optional ambiguity in code generation (#9119)

This commit is contained in:
J. Nick Koston 2025-06-17 20:04:45 +02:00 committed by GitHub
parent 78c8447d1e
commit bf161f1eaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -29,7 +29,9 @@ Component = esphome_ns.class_("Component")
ComponentPtr = Component.operator("ptr") ComponentPtr = Component.operator("ptr")
PollingComponent = esphome_ns.class_("PollingComponent", Component) PollingComponent = esphome_ns.class_("PollingComponent", Component)
Application = esphome_ns.class_("Application") Application = esphome_ns.class_("Application")
optional = esphome_ns.class_("optional") # Create optional with explicit namespace to avoid ambiguity with std::optional
# The generated code will use esphome::optional instead of just optional
optional = global_ns.namespace("esphome").class_("optional")
arduino_json_ns = global_ns.namespace("ArduinoJson") arduino_json_ns = global_ns.namespace("ArduinoJson")
JsonObject = arduino_json_ns.class_("JsonObject") JsonObject = arduino_json_ns.class_("JsonObject")
JsonObjectConst = arduino_json_ns.class_("JsonObjectConst") JsonObjectConst = arduino_json_ns.class_("JsonObjectConst")

View File

@ -66,5 +66,5 @@ def test_text_config_lamda_is_set(generate_main):
main_cpp = generate_main("tests/component_tests/text/test_text.yaml") main_cpp = generate_main("tests/component_tests/text/test_text.yaml")
# Then # Then
assert "it_4->set_template([=]() -> optional<std::string> {" in main_cpp assert "it_4->set_template([=]() -> esphome::optional<std::string> {" in main_cpp
assert 'return std::string{"Hello"};' in main_cpp assert 'return std::string{"Hello"};' in main_cpp