mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 23:45:40 -07:00
Fix parameter name; set update_interval to never if no lambda to poll
This commit is contained in:
@@ -10,7 +10,10 @@ from esphome.const import (
|
||||
CONF_OPTIONS,
|
||||
CONF_RESTORE_VALUE,
|
||||
CONF_SET_ACTION,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
SCHEDULER_DONT_RUN,
|
||||
)
|
||||
from esphome.core import TimePeriodMilliseconds
|
||||
from esphome.cpp_generator import TemplateArguments
|
||||
|
||||
from .. import template_ns
|
||||
@@ -103,7 +106,13 @@ async def to_code(config):
|
||||
var_id,
|
||||
TemplateArguments(has_lambda, optimistic, restore_value, initial_option_index),
|
||||
)
|
||||
await cg.register_component(var, config)
|
||||
component_config = config.copy()
|
||||
if not has_lambda:
|
||||
# No point in polling if not using a lambda
|
||||
component_config[CONF_UPDATE_INTERVAL] = TimePeriodMilliseconds(
|
||||
milliseconds=SCHEDULER_DONT_RUN
|
||||
)
|
||||
await cg.register_component(var, component_config)
|
||||
await select.register_select(var, config, options=options)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
namespace esphome::template_ {
|
||||
|
||||
void dump_config_helper(BaseTemplateSelect *this_, bool optimistic, bool has_lambda, const size_t initial_option_index,
|
||||
bool restore_value) {
|
||||
LOG_SELECT("", "Template Select", this_);
|
||||
void dump_config_helper(BaseTemplateSelect *sel_comp, bool optimistic, bool has_lambda,
|
||||
const size_t initial_option_index, bool restore_value) {
|
||||
LOG_SELECT("", "Template Select", sel_comp);
|
||||
if (has_lambda) {
|
||||
LOG_UPDATE_INTERVAL((PollingComponent *) this_);
|
||||
LOG_UPDATE_INTERVAL(sel_comp);
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Optimistic: %s\n"
|
||||
" Initial Option: %s\n"
|
||||
" Restore Value: %s",
|
||||
YESNO(optimistic), this_->option_at(initial_option_index), YESNO(restore_value));
|
||||
YESNO(optimistic), sel_comp->option_at(initial_option_index), YESNO(restore_value));
|
||||
}
|
||||
}
|
||||
} // namespace esphome::template_
|
||||
|
||||
@@ -12,7 +12,7 @@ static const char *const TAG = "template.select";
|
||||
struct Empty {};
|
||||
class BaseTemplateSelect : public select::Select, public PollingComponent {};
|
||||
|
||||
void dump_config_helper(BaseTemplateSelect *this_, bool optimistic, bool has_lambda, size_t initial_option_index,
|
||||
void dump_config_helper(BaseTemplateSelect *sel_comp, bool optimistic, bool has_lambda, size_t initial_option_index,
|
||||
bool restore_value);
|
||||
|
||||
/// Base template select class - used when no set_action is configured
|
||||
|
||||
Reference in New Issue
Block a user