ESPHome  2023.11.6
alarm_control_panel.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 
7 
10 #include "esphome/core/log.h"
11 
12 namespace esphome {
13 namespace alarm_control_panel {
14 
15 enum AlarmControlPanelFeature : uint8_t {
16  // Matches Home Assistant values
20  ACP_FEAT_TRIGGER = 1 << 3,
23 };
24 
25 class AlarmControlPanel : public EntityBase {
26  public:
31 
37 
42  void add_on_state_callback(std::function<void()> &&callback);
43 
48  void add_on_triggered_callback(std::function<void()> &&callback);
49 
54  void add_on_arming_callback(std::function<void()> &&callback);
55 
60  void add_on_pending_callback(std::function<void()> &&callback);
61 
66  void add_on_armed_home_callback(std::function<void()> &&callback);
67 
72  void add_on_armed_night_callback(std::function<void()> &&callback);
73 
78  void add_on_armed_away_callback(std::function<void()> &&callback);
79 
84  void add_on_disarmed_callback(std::function<void()> &&callback);
85 
90  void add_on_cleared_callback(std::function<void()> &&callback);
91 
95  virtual uint32_t get_supported_features() const = 0;
96 
100  virtual bool get_requires_code() const = 0;
101 
105  virtual bool get_requires_code_to_arm() const = 0;
106 
112 
118 
124 
130 
136 
141  void disarm(optional<std::string> code = nullopt);
142 
147 
148  // is the state one of the armed states
150 
151  protected:
153  // in order to store last panel state in flash
155  // current state
157  // the desired (or previous) state
159  // last time the state was updated
160  uint32_t last_update_;
161  // the call control function
162  virtual void control(const AlarmControlPanelCall &call) = 0;
163  // state callback
165  // trigger callback
167  // arming callback
169  // pending callback
171  // armed_home callback
173  // armed_night callback
175  // armed_away callback
177  // disarmed callback
179  // clear callback
181 };
182 
183 } // namespace alarm_control_panel
184 } // namespace esphome
AlarmControlPanelState get_state() const
Get the state.
void add_on_armed_night_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_night.
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_triggered_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel chanes to triggered. ...
void arm_vacation(optional< std::string > code=nullopt)
arm the alarm in vacation mode
void add_on_armed_home_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_home.
void add_on_disarmed_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to disarmed. ...
void arm_night(optional< std::string > code=nullopt)
arm the alarm in night mode
virtual bool get_requires_code() const =0
Returns if the alarm_control_panel has a code.
bool is_state_armed(AlarmControlPanelState state)
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
AlarmControlPanelCall make_call()
Make a AlarmControlPanelCall.
void disarm(optional< std::string > code=nullopt)
disarm the alarm
void arm_home(optional< std::string > code=nullopt)
arm the alarm in home mode
const nullopt_t nullopt((nullopt_t::init()))
void arm_custom_bypass(optional< std::string > code=nullopt)
arm the alarm in custom bypass mode
virtual void control(const AlarmControlPanelCall &call)=0
void add_on_state_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes.
void arm_away(optional< std::string > code=nullopt)
arm the alarm in away mode
void add_on_pending_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to pending.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void add_on_armed_away_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_away.
virtual uint32_t get_supported_features() const =0
A numeric representation of the supported features as per HomeAssistant.
void add_on_arming_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel chanes to arming.
bool state
Definition: fan.h:34
virtual bool get_requires_code_to_arm() const =0
Returns if the alarm_control_panel requires a code to arm.