mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
40 lines
1.0 KiB
YAML
40 lines
1.0 KiB
YAML
esphome:
|
|
name: select-stringref-test
|
|
friendly_name: Select StringRef Test
|
|
|
|
host:
|
|
|
|
logger:
|
|
level: DEBUG
|
|
|
|
api:
|
|
|
|
select:
|
|
- platform: template
|
|
name: "Test Select"
|
|
id: test_select
|
|
optimistic: true
|
|
options:
|
|
- "Option A"
|
|
- "Option B"
|
|
- "Option C"
|
|
initial_option: "Option A"
|
|
on_value:
|
|
then:
|
|
# Test 1: Log the value directly (StringRef -> const char* via c_str())
|
|
- logger.log:
|
|
format: "Select value: %s"
|
|
args: ['x.c_str()']
|
|
# Test 2: String concatenation (StringRef + const char* -> std::string)
|
|
- lambda: |-
|
|
std::string with_suffix = x + " selected";
|
|
ESP_LOGI("test", "Concatenated: %s", with_suffix.c_str());
|
|
# Test 3: Comparison (StringRef == const char*)
|
|
- lambda: |-
|
|
if (x == "Option B") {
|
|
ESP_LOGI("test", "Option B was selected");
|
|
}
|
|
# Test 4: Use index parameter (variable name is 'i')
|
|
- lambda: |-
|
|
ESP_LOGI("test", "Select index: %d", (int)i);
|