ESPHome  2024.11.0
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
esphome::safe_mode::SafeModeComponent Class Reference

SafeModeComponent provides a safe way to recover from repeated boot failures. More...

#include <safe_mode.h>

Inheritance diagram for esphome::safe_mode::SafeModeComponent:
esphome::Component

Public Member Functions

bool should_enter_safe_mode (uint8_t num_attempts, uint32_t enable_time, uint32_t boot_is_good_after)
 
void set_safe_mode_pending (const bool &pending)
 Set to true if the next startup will enter safe mode. More...
 
bool get_safe_mode_pending ()
 
void dump_config () override
 
float get_setup_priority () const override
 
void loop () override
 
void clean_rtc ()
 
void on_safe_shutdown () override
 
void add_on_safe_mode_callback (std::function< void()> &&callback)
 
- Public Member Functions inherited from esphome::Component
virtual void setup ()
 Where the component's initialization should happen. More...
 
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed () const
 
bool is_ready () const
 
virtual bool can_proceed ()
 
bool status_has_warning () const
 
bool status_has_error () const
 
void status_set_warning (const char *message="unspecified")
 
void status_set_error (const char *message="unspecified")
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 

Protected Member Functions

void write_rtc_ (uint32_t val)
 
uint32_t read_rtc_ ()
 
- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_setup ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 

Protected Attributes

bool boot_successful_ {false}
 set to true after boot is considered successful More...
 
uint32_t safe_mode_boot_is_good_after_ {60000}
 The amount of time after which the boot is considered successful. More...
 
uint32_t safe_mode_enable_time_ {60000}
 The time safe mode should remain active for. More...
 
uint32_t safe_mode_rtc_value_ {0}
 
uint32_t safe_mode_start_time_ {0}
 stores when safe mode was enabled More...
 
uint8_t safe_mode_num_attempts_ {0}
 
ESPPreferenceObject rtc_
 
CallbackManager< void()> safe_mode_callback_ {}
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 

Static Protected Attributes

static const uint32_t ENTER_SAFE_MODE_MAGIC
 a magic number to indicate that safe mode should be entered on next boot More...
 

Detailed Description

SafeModeComponent provides a safe way to recover from repeated boot failures.

Definition at line 12 of file safe_mode.h.

Member Function Documentation

◆ add_on_safe_mode_callback()

void esphome::safe_mode::SafeModeComponent::add_on_safe_mode_callback ( std::function< void()> &&  callback)
inline

Definition at line 28 of file safe_mode.h.

◆ clean_rtc()

void esphome::safe_mode::SafeModeComponent::clean_rtc ( )

Definition at line 123 of file safe_mode.cpp.

◆ dump_config()

void esphome::safe_mode::SafeModeComponent::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 17 of file safe_mode.cpp.

◆ get_safe_mode_pending()

bool esphome::safe_mode::SafeModeComponent::get_safe_mode_pending ( )

Definition at line 61 of file safe_mode.cpp.

◆ get_setup_priority()

float esphome::safe_mode::SafeModeComponent::get_setup_priority ( ) const
overridevirtual

Reimplemented from esphome::Component.

Definition at line 36 of file safe_mode.cpp.

◆ loop()

void esphome::safe_mode::SafeModeComponent::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 38 of file safe_mode.cpp.

◆ on_safe_shutdown()

void esphome::safe_mode::SafeModeComponent::on_safe_shutdown ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 125 of file safe_mode.cpp.

◆ read_rtc_()

uint32_t esphome::safe_mode::SafeModeComponent::read_rtc_ ( )
protected

Definition at line 116 of file safe_mode.cpp.

◆ set_safe_mode_pending()

void esphome::safe_mode::SafeModeComponent::set_safe_mode_pending ( const bool &  pending)

Set to true if the next startup will enter safe mode.

Definition at line 47 of file safe_mode.cpp.

◆ should_enter_safe_mode()

bool esphome::safe_mode::SafeModeComponent::should_enter_safe_mode ( uint8_t  num_attempts,
uint32_t  enable_time,
uint32_t  boot_is_good_after 
)

Definition at line 65 of file safe_mode.cpp.

◆ write_rtc_()

void esphome::safe_mode::SafeModeComponent::write_rtc_ ( uint32_t  val)
protected

Definition at line 111 of file safe_mode.cpp.

Field Documentation

◆ boot_successful_

bool esphome::safe_mode::SafeModeComponent::boot_successful_ {false}
protected

set to true after boot is considered successful

Definition at line 36 of file safe_mode.h.

◆ ENTER_SAFE_MODE_MAGIC

const uint32_t esphome::safe_mode::SafeModeComponent::ENTER_SAFE_MODE_MAGIC
staticprotected
Initial value:
=
0x5afe5afe

a magic number to indicate that safe mode should be entered on next boot

Definition at line 45 of file safe_mode.h.

◆ rtc_

ESPPreferenceObject esphome::safe_mode::SafeModeComponent::rtc_
protected

Definition at line 42 of file safe_mode.h.

◆ safe_mode_boot_is_good_after_

uint32_t esphome::safe_mode::SafeModeComponent::safe_mode_boot_is_good_after_ {60000}
protected

The amount of time after which the boot is considered successful.

Definition at line 37 of file safe_mode.h.

◆ safe_mode_callback_

CallbackManager<void()> esphome::safe_mode::SafeModeComponent::safe_mode_callback_ {}
protected

Definition at line 43 of file safe_mode.h.

◆ safe_mode_enable_time_

uint32_t esphome::safe_mode::SafeModeComponent::safe_mode_enable_time_ {60000}
protected

The time safe mode should remain active for.

Definition at line 38 of file safe_mode.h.

◆ safe_mode_num_attempts_

uint8_t esphome::safe_mode::SafeModeComponent::safe_mode_num_attempts_ {0}
protected

Definition at line 41 of file safe_mode.h.

◆ safe_mode_rtc_value_

uint32_t esphome::safe_mode::SafeModeComponent::safe_mode_rtc_value_ {0}
protected

Definition at line 39 of file safe_mode.h.

◆ safe_mode_start_time_

uint32_t esphome::safe_mode::SafeModeComponent::safe_mode_start_time_ {0}
protected

stores when safe mode was enabled

Definition at line 40 of file safe_mode.h.


The documentation for this class was generated from the following files: