From 6c9f93fbf807e1bda8a9aac992fe82fa66340d37 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Oct 2025 10:40:05 -0700 Subject: [PATCH] touch ups --- esphome/components/template/select/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/esphome/components/template/select/__init__.py b/esphome/components/template/select/__init__.py index 93aa2c8b05..40ba557d9b 100644 --- a/esphome/components/template/select/__init__.py +++ b/esphome/components/template/select/__init__.py @@ -73,15 +73,18 @@ async def to_code(config): cg.add(var.set_template(template_)) else: - cg.add(var.set_optimistic(config[CONF_OPTIMISTIC])) + # Only set if non-default to avoid bloating setup() function + if config[CONF_OPTIMISTIC]: + cg.add(var.set_optimistic(True)) initial_option_index = config[CONF_OPTIONS].index(config[CONF_INITIAL_OPTION]) # 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: - cg.add(var.set_restore_value(config[CONF_RESTORE_VALUE])) + # Only set if True (default is False) + if CONF_RESTORE_VALUE in config and config[CONF_RESTORE_VALUE]: + cg.add(var.set_restore_value(True)) if CONF_SET_ACTION in config: await automation.build_automation(