ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
alarm_control_panel.cpp
Go to the documentation of this file.
4
5#include <utility>
6
9#include "esphome/core/log.h"
10
12
13static const char *const TAG = "alarm_control_panel";
14
16
18 switch (state) {
24 return true;
25 default:
26 return false;
27 }
28};
29
31 this->last_update_ = millis();
32 if (state != this->current_state_) {
33 auto prev_state = this->current_state_;
34 ESP_LOGV(TAG, "'%s' >> %s (was %s)", this->get_name().c_str(),
36 LOG_STR_ARG(alarm_control_panel_state_to_string(prev_state)));
37 this->current_state_ = state;
38 // Single state callback - listeners receive the new state as an argument
39 this->state_callback_.call(state);
40#if defined(USE_ALARM_CONTROL_PANEL) && defined(USE_CONTROLLER_REGISTRY)
41 ControllerRegistry::notify_alarm_control_panel_update(this);
42#endif
43 // Cleared fires when leaving TRIGGERED state
44 if (prev_state == ACP_STATE_TRIGGERED) {
45 this->cleared_callback_.call();
46 }
47 if (state == this->desired_state_) {
48 // only store when in the desired state
49 this->pref_.save(&state);
50 }
51 }
52}
53
55 const char *code) {
56 auto call = this->make_call();
57 (call.*arm_method)();
58 if (code != nullptr)
59 call.set_code(code);
60 call.perform();
61}
62
64
66
68
72
76
78
79} // namespace esphome::alarm_control_panel
const StringRef & get_name() const
Definition entity_base.h:71
bool is_state_armed(AlarmControlPanelState state)
void arm_vacation(const char *code=nullptr)
arm the alarm in vacation mode
void arm_custom_bypass(const char *code=nullptr)
arm the alarm in custom bypass mode
void arm_home(const char *code=nullptr)
arm the alarm in home mode
LazyCallbackManager< void(AlarmControlPanelState)> state_callback_
void arm_with_code_(AlarmControlPanelCall &(AlarmControlPanelCall::*arm_method)(), const char *code)
void disarm(const char *code=nullptr)
disarm the alarm
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
void arm_night(const char *code=nullptr)
arm the alarm in night mode
void arm_away(const char *code=nullptr)
arm the alarm in away mode
AlarmControlPanelCall make_call()
Make a AlarmControlPanelCall.
bool state
Definition fan.h:2
const LogString * alarm_control_panel_state_to_string(AlarmControlPanelState state)
Returns a string representation of the state.
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:26