diff --git a/esphome/components/template/select/__init__.py b/esphome/components/template/select/__init__.py index 566fb2996a..8de0b65c2d 100644 --- a/esphome/components/template/select/__init__.py +++ b/esphome/components/template/select/__init__.py @@ -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: diff --git a/esphome/components/template/select/template_select.cpp b/esphome/components/template/select/template_select.cpp index 5a7b6400c6..f6871cf186 100644 --- a/esphome/components/template/select/template_select.cpp +++ b/esphome/components/template/select/template_select.cpp @@ -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_ diff --git a/esphome/components/template/select/template_select.h b/esphome/components/template/select/template_select.h index 8f1cacc5a0..739d13e298 100644 --- a/esphome/components/template/select/template_select.h +++ b/esphome/components/template/select/template_select.h @@ -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