mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 07:16:11 +08:00
[climate] Return std::string_view from get_custom_fan_mode() and get_custom_preset()
This commit is contained in:
@@ -16,21 +16,15 @@ climate:
|
|||||||
- name: Away
|
- name: Away
|
||||||
default_target_temperature_low: 16°C
|
default_target_temperature_low: 16°C
|
||||||
default_target_temperature_high: 20°C
|
default_target_temperature_high: 20°C
|
||||||
custom_preset:
|
|
||||||
- name: Eco Mode
|
|
||||||
default_target_temperature_low: 16°C
|
|
||||||
default_target_temperature_high: 22°C
|
|
||||||
- name: Sleep Mode
|
|
||||||
default_target_temperature_low: 17°C
|
|
||||||
default_target_temperature_high: 21°C
|
|
||||||
on_state:
|
on_state:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
// Test get_custom_preset() returns std::string_view
|
// Test get_custom_preset() returns std::string_view
|
||||||
|
// "Default Preset" is a custom preset (not a standard ClimatePreset name)
|
||||||
if (id(test_thermostat).has_custom_preset()) {
|
if (id(test_thermostat).has_custom_preset()) {
|
||||||
auto preset = id(test_thermostat).get_custom_preset();
|
auto preset = id(test_thermostat).get_custom_preset();
|
||||||
// Compare with string literal using ==
|
// Compare with string literal using ==
|
||||||
if (preset == "Eco Mode") {
|
if (preset == "Default Preset") {
|
||||||
ESP_LOGD("test", "Preset is Eco Mode");
|
ESP_LOGD("test", "Preset is Default Preset");
|
||||||
}
|
}
|
||||||
// Log using %.*s format for string_view
|
// Log using %.*s format for string_view
|
||||||
ESP_LOGD("test", "Custom preset: %.*s", (int) preset.size(), preset.data());
|
ESP_LOGD("test", "Custom preset: %.*s", (int) preset.size(), preset.data());
|
||||||
|
|||||||
Reference in New Issue
Block a user