mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
[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:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user