mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
Merge branch 'initial_option_template_select' into integration
This commit is contained in:
@@ -75,7 +75,10 @@ async def to_code(config):
|
|||||||
else:
|
else:
|
||||||
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||||
initial_option_index = config[CONF_OPTIONS].index(config[CONF_INITIAL_OPTION])
|
initial_option_index = config[CONF_OPTIONS].index(config[CONF_INITIAL_OPTION])
|
||||||
cg.add(var.set_initial_option_index(initial_option_index))
|
# Only set if non-zero to avoid bloating setup() function
|
||||||
|
# (initial_option_index_ is zero-initialized in the header)
|
||||||
|
if initial_option_index != 0:
|
||||||
|
cg.add(var.set_initial_option_index(initial_option_index))
|
||||||
|
|
||||||
if CONF_RESTORE_VALUE in config:
|
if CONF_RESTORE_VALUE in config:
|
||||||
cg.add(var.set_restore_value(config[CONF_RESTORE_VALUE]))
|
cg.add(var.set_restore_value(config[CONF_RESTORE_VALUE]))
|
||||||
|
|||||||
@@ -60,13 +60,11 @@ void TemplateSelect::dump_config() {
|
|||||||
LOG_UPDATE_INTERVAL(this);
|
LOG_UPDATE_INTERVAL(this);
|
||||||
if (this->f_.has_value())
|
if (this->f_.has_value())
|
||||||
return;
|
return;
|
||||||
auto initial_option = this->at(this->initial_option_index_);
|
|
||||||
ESP_LOGCONFIG(TAG,
|
ESP_LOGCONFIG(TAG,
|
||||||
" Optimistic: %s\n"
|
" Optimistic: %s\n"
|
||||||
" Initial Option: %s\n"
|
" Initial Option: %s\n"
|
||||||
" Restore Value: %s",
|
" Restore Value: %s",
|
||||||
YESNO(this->optimistic_),
|
YESNO(this->optimistic_), this->at(this->initial_option_index_).value().c_str(),
|
||||||
initial_option.has_value() ? initial_option.value().c_str() : LOG_STR_LITERAL("unknown"),
|
|
||||||
YESNO(this->restore_value_));
|
YESNO(this->restore_value_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ async def test_host_mode_empty_string_options(
|
|||||||
initial_state = states[initial_option_test.key]
|
initial_state = states[initial_option_test.key]
|
||||||
assert initial_state.state == "Third", (
|
assert initial_state.state == "Third", (
|
||||||
f"Expected initial state 'Third' but got '{initial_state.state}' - "
|
f"Expected initial state 'Third' but got '{initial_state.state}' - "
|
||||||
f"initial_option_index optimization may not be working correctly"
|
f"initial_option not correctly applied"
|
||||||
)
|
)
|
||||||
|
|
||||||
# The main test is that we got here without protobuf errors
|
# The main test is that we got here without protobuf errors
|
||||||
|
|||||||
Reference in New Issue
Block a user