From 8e7b1638d07fd73718dd31935bf7b33850ce9062 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 28 Feb 2026 14:04:28 -1000 Subject: [PATCH] address bot comments --- tests/component_tests/text/test_text.py | 15 +++++++++++++++ tests/components/template/common-base.yaml | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/tests/component_tests/text/test_text.py b/tests/component_tests/text/test_text.py index 23e1ddc177a..16f5f980a5f 100644 --- a/tests/component_tests/text/test_text.py +++ b/tests/component_tests/text/test_text.py @@ -68,3 +68,18 @@ def test_text_config_lamda_is_set(generate_main): # Then assert "it_4->set_template([]() -> std::optional {" in main_cpp assert 'return std::string{"Hello"};' in main_cpp + + +def test_esphome_optional_alias_works(generate_main): + """ + Test that esphome::optional alias compiles (backward compatibility) + """ + # Given + + # When + main_cpp = generate_main("tests/component_tests/text/test_text.yaml") + + # Then + # Codegen emits std::optional, but esphome::optional must also work + # via the using alias in esphome/core/optional.h + assert "std::optional" in main_cpp diff --git a/tests/components/template/common-base.yaml b/tests/components/template/common-base.yaml index fe98583d135..ed398b0abd9 100644 --- a/tests/components/template/common-base.yaml +++ b/tests/components/template/common-base.yaml @@ -31,6 +31,11 @@ esphome: id(template_sens).set_template([]() -> std::optional { return 123.0f; }); + # Test that esphome::optional alias still works for backward compatibility + - lambda: |- + id(template_sens).set_template([]() -> esphome::optional { + return 42.0f; + }); - datetime.date.set: id: test_date