ESPHome  2024.10.2
template_alarm_control_panel.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cinttypes>
4 #include <map>
5 
8 #include "esphome/core/defines.h"
9 
11 
12 #ifdef USE_BINARY_SENSOR
14 #endif
15 
16 namespace esphome {
17 namespace template_ {
18 
19 #ifdef USE_BINARY_SENSOR
20 enum BinarySensorFlags : uint16_t {
25 };
26 
27 enum AlarmSensorType : uint16_t {
31 };
32 
33 #endif
34 
38 };
39 
42 };
43 
44 struct SensorInfo {
45  uint16_t flags;
47  uint8_t store_index;
48 };
49 
51  public:
53  void dump_config() override;
54  void setup() override;
55  void loop() override;
56  uint32_t get_supported_features() const override;
57  bool get_requires_code() const override;
58  bool get_requires_code_to_arm() const override { return this->requires_code_to_arm_; }
59  bool get_all_sensors_ready() { return this->sensors_ready_; };
60  void set_restore_mode(TemplateAlarmControlPanelRestoreMode restore_mode) { this->restore_mode_ = restore_mode; }
61 
62 #ifdef USE_BINARY_SENSOR
63 
68  void add_sensor(binary_sensor::BinarySensor *sensor, uint16_t flags = 0,
70 #endif
71 
76  void add_code(const std::string &code) { this->codes_.push_back(code); }
77 
82  void set_requires_code_to_arm(bool code_to_arm) { this->requires_code_to_arm_ = code_to_arm; }
83 
88  void set_arming_away_time(uint32_t time) { this->arming_away_time_ = time; }
89 
94  void set_arming_home_time(uint32_t time) { this->arming_home_time_ = time; }
95 
100  void set_arming_night_time(uint32_t time) { this->arming_night_time_ = time; }
101 
106  void set_pending_time(uint32_t time) { this->pending_time_ = time; }
107 
112  void set_trigger_time(uint32_t time) { this->trigger_time_ = time; }
113 
114  void set_supports_arm_home(bool supports_arm_home) { supports_arm_home_ = supports_arm_home; }
115 
116  void set_supports_arm_night(bool supports_arm_night) { supports_arm_night_ = supports_arm_night; }
117 
118  protected:
119  void control(const alarm_control_panel::AlarmControlPanelCall &call) override;
120 #ifdef USE_BINARY_SENSOR
121  // This maps a binary sensor to its type and attribute bits
122  std::map<binary_sensor::BinarySensor *, SensorInfo> sensor_map_;
123 
124 #endif
126 
127  // the arming away delay
129  // the arming home delay
130  uint32_t arming_home_time_{0};
131  // the arming night delay
132  uint32_t arming_night_time_{0};
133  // the trigger delay
134  uint32_t pending_time_;
135  // the time in trigger
136  uint32_t trigger_time_;
137  // a list of codes
138  std::vector<std::string> codes_;
139  // Per sensor data store
140  std::vector<SensorDataStore> sensor_data_;
141  // requires a code to arm
142  bool requires_code_to_arm_ = false;
143  bool supports_arm_home_ = false;
144  bool supports_arm_night_ = false;
145  bool sensors_ready_ = false;
146  bool sensors_ready_last_ = false;
147  uint8_t next_store_index_ = 0;
148  // check if the code is valid
149  bool is_code_valid_(optional<std::string> code);
150 
152 };
153 
154 } // namespace template_
155 } // namespace esphome
void setup()
void loop()
void add_code(const std::string &code)
add a code
void set_pending_time(uint32_t time)
set the delay before triggering
void set_arming_night_time(uint32_t time)
set the delay before arming night
void set_arming_home_time(uint32_t time)
set the delay before arming home
void set_trigger_time(uint32_t time)
set the delay before resetting after triggered
void set_arming_away_time(uint32_t time)
set the delay before arming away
uint8_t type
const uint32_t flags
Definition: stm32flash.h:85
void set_requires_code_to_arm(bool code_to_arm)
set requires a code to arm
std::map< binary_sensor::BinarySensor *, SensorInfo > sensor_map_
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void set_restore_mode(TemplateAlarmControlPanelRestoreMode restore_mode)
esphome::sensor::Sensor * sensor
Definition: statsd.h:37
bool state
Definition: fan.h:34
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26