[safe_mode] Use StaticCallbackManager for on_safe_mode

safe_mode is a single-instance component, so a compile-time-sized
StaticVector backing for the callback list is a clean fit. Drop the
std::vector reallocation machinery (_M_realloc_insert) and size the
storage to the exact number of on_safe_mode automations via
ESPHOME_SAFE_MODE_CALLBACK_COUNT.
This commit is contained in:
J. Nick Koston
2026-04-25 14:23:31 -05:00
parent b5ccd55f4e
commit d7a69979e7
3 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -76,8 +76,9 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
if config.get(CONF_ON_SAFE_MODE):
if on_safe_mode := config.get(CONF_ON_SAFE_MODE):
cg.add_define("USE_SAFE_MODE_CALLBACK")
cg.add_define("ESPHOME_SAFE_MODE_CALLBACK_COUNT", len(on_safe_mode))
await automation.build_callback_automations(
var, config, _CALLBACK_AUTOMATIONS
)
+1 -1
View File
@@ -57,7 +57,7 @@ class SafeModeComponent final : public Component {
// Larger objects at the end
ESPPreferenceObject rtc_;
#ifdef USE_SAFE_MODE_CALLBACK
CallbackManager<void()> safe_mode_callback_{};
StaticCallbackManager<ESPHOME_SAFE_MODE_CALLBACK_COUNT, void()> safe_mode_callback_{};
#endif
static const uint32_t ENTER_SAFE_MODE_MAGIC =
+1
View File
@@ -136,6 +136,7 @@
#define USE_PREFERENCES_SYNC_EVERY_LOOP
#define USE_QR_CODE
#define USE_SAFE_MODE_CALLBACK
#define ESPHOME_SAFE_MODE_CALLBACK_COUNT 1
#define USE_SELECT
#define USE_SENSOR
#define USE_SENSOR_FILTER