ESPHome 2026.1.4
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_LOGD(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 - triggers check get_state() for specific states
39 this->state_callback_.call();
40#if defined(USE_ALARM_CONTROL_PANEL) && defined(USE_CONTROLLER_REGISTRY)
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
54void AlarmControlPanel::add_on_state_callback(std::function<void()> &&callback) {
55 this->state_callback_.add(std::move(callback));
56}
57
58void AlarmControlPanel::add_on_cleared_callback(std::function<void()> &&callback) {
59 this->cleared_callback_.add(std::move(callback));
60}
61
62void AlarmControlPanel::add_on_chime_callback(std::function<void()> &&callback) {
63 this->chime_callback_.add(std::move(callback));
64}
65
66void AlarmControlPanel::add_on_ready_callback(std::function<void()> &&callback) {
67 this->ready_callback_.add(std::move(callback));
68}
69
71 auto call = this->make_call();
72 call.arm_away();
73 if (code.has_value())
74 call.set_code(code.value());
75 call.perform();
76}
77
79 auto call = this->make_call();
80 call.arm_home();
81 if (code.has_value())
82 call.set_code(code.value());
83 call.perform();
84}
85
87 auto call = this->make_call();
88 call.arm_night();
89 if (code.has_value())
90 call.set_code(code.value());
91 call.perform();
92}
93
95 auto call = this->make_call();
96 call.arm_vacation();
97 if (code.has_value())
98 call.set_code(code.value());
99 call.perform();
100}
101
103 auto call = this->make_call();
104 call.arm_custom_bypass();
105 if (code.has_value())
106 call.set_code(code.value());
107 call.perform();
108}
109
111 auto call = this->make_call();
112 call.disarm();
113 if (code.has_value())
114 call.set_code(code.value());
115 call.perform();
116}
117
118} // namespace esphome::alarm_control_panel
static void notify_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj)
bool save(const T *src)
Definition preferences.h:21
const StringRef & get_name() const
void add_on_state_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes.
bool is_state_armed(AlarmControlPanelState state)
void arm_vacation(optional< std::string > code=nullopt)
arm the alarm in vacation mode
void arm_home(optional< std::string > code=nullopt)
arm the alarm in home mode
void arm_away(optional< std::string > code=nullopt)
arm the alarm in away mode
void arm_night(optional< std::string > code=nullopt)
arm the alarm in night mode
void arm_custom_bypass(optional< std::string > code=nullopt)
arm the alarm in custom bypass mode
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
void disarm(optional< std::string > code=nullopt)
disarm the alarm
void add_on_ready_callback(std::function< void()> &&callback)
Add a callback for when a ready state changes.
void add_on_cleared_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel clears from triggered.
void add_on_chime_callback(std::function< void()> &&callback)
Add a callback for when a chime zone goes from closed to open.
AlarmControlPanelCall make_call()
Make a AlarmControlPanelCall.
bool has_value() const
Definition optional.h:92
value_type const & value() const
Definition optional.h:94
bool state
Definition fan.h:0
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:25