[light] Return std::string_view from LightEffect::get_name() and LightState::get_effect_name()

This commit is contained in:
J. Nick Koston
2026-01-09 08:35:37 -10:00
parent 3d54ccac65
commit 775c6a077d
11 changed files with 52 additions and 22 deletions

View File

@@ -1,6 +1,21 @@
esphome:
on_boot:
then:
# Test LightEffect::get_name() returns string_view
- lambda: |-
// Test get_name() returns string_view
auto &effects = id(test_monochromatic_light).get_effects();
if (!effects.empty()) {
std::string_view name = effects[0]->get_name();
// Test comparison with string literal
if (name == "Strobe") {
ESP_LOGI("test", "Found Strobe effect");
}
// Safe logging with size-limited format
ESP_LOGI("test", "Effect name: %.*s", (int) name.size(), name.data());
// Test .data() for null-terminated functions (safe because names are from codegen)
ESP_LOGI("test", "Effect: %s", name.data());
}
- light.toggle: test_binary_light
- light.turn_off: test_rgb_light
- light.turn_on: