mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[climate] Return StringRef from get_custom_fan_mode() and get_custom_preset() (#13103)
This commit is contained in:
@@ -12,6 +12,25 @@ climate:
|
||||
x.set_mode(CLIMATE_MODE_FAN_ONLY);
|
||||
on_state:
|
||||
- logger.log: State changed!
|
||||
- lambda: |-
|
||||
// Test get_custom_fan_mode() returns StringRef
|
||||
if (id(midea_unit).has_custom_fan_mode()) {
|
||||
auto fan_mode = id(midea_unit).get_custom_fan_mode();
|
||||
// Compare with string literal using ==
|
||||
if (fan_mode == "SILENT") {
|
||||
ESP_LOGD("test", "Fan mode is SILENT");
|
||||
}
|
||||
// Log using %.*s format for StringRef
|
||||
ESP_LOGD("test", "Custom fan mode: %.*s", (int) fan_mode.size(), fan_mode.c_str());
|
||||
}
|
||||
// Test get_custom_preset() returns StringRef
|
||||
if (id(midea_unit).has_custom_preset()) {
|
||||
auto preset = id(midea_unit).get_custom_preset();
|
||||
// Check if empty
|
||||
if (!preset.empty()) {
|
||||
ESP_LOGD("test", "Custom preset: %.*s", (int) preset.size(), preset.c_str());
|
||||
}
|
||||
}
|
||||
transmitter_id: xmitr
|
||||
period: 1s
|
||||
num_attempts: 5
|
||||
|
||||
@@ -5,6 +5,7 @@ sensor:
|
||||
|
||||
climate:
|
||||
- platform: thermostat
|
||||
id: test_thermostat
|
||||
name: Test Thermostat
|
||||
sensor: thermostat_sensor
|
||||
humidity_sensor: thermostat_sensor
|
||||
@@ -15,6 +16,19 @@ climate:
|
||||
- name: Away
|
||||
default_target_temperature_low: 16°C
|
||||
default_target_temperature_high: 20°C
|
||||
on_state:
|
||||
- lambda: |-
|
||||
// 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()) {
|
||||
auto preset = id(test_thermostat).get_custom_preset();
|
||||
// Compare with string literal using ==
|
||||
if (preset == "Default Preset") {
|
||||
ESP_LOGD("test", "Preset is Default Preset");
|
||||
}
|
||||
// Log using %.*s format for StringRef
|
||||
ESP_LOGD("test", "Custom preset: %.*s", (int) preset.size(), preset.c_str());
|
||||
}
|
||||
idle_action:
|
||||
- logger.log: idle_action
|
||||
cool_action:
|
||||
|
||||
Reference in New Issue
Block a user