ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
template_alarm_control_panel.h
Go to the documentation of this file.
1#pragma once
2
3#include <cinttypes>
4#include <cstring>
5#include <vector>
6
11
13
14#ifdef USE_BINARY_SENSOR
16#endif
17
18namespace esphome::template_ {
19
20#ifdef USE_BINARY_SENSOR
28
35
36#endif
37
42
43#ifdef USE_BINARY_SENSOR
47
48struct SensorInfo {
49 uint16_t flags;
51 uint8_t store_index;
52};
53
58#endif
59
61 public:
63 void dump_config() override;
64 void setup() override;
65 void loop() override;
66 uint32_t get_supported_features() const override;
67 bool get_requires_code() const override { return !this->codes_.empty(); }
68 bool get_requires_code_to_arm() const override { return this->requires_code_to_arm_; }
69 bool get_all_sensors_ready() { return this->sensors_ready_; };
70 void set_restore_mode(TemplateAlarmControlPanelRestoreMode restore_mode) { this->restore_mode_ = restore_mode; }
72
73#ifdef USE_BINARY_SENSOR
78 void init_sensors(size_t capacity) { this->sensors_.init(capacity); }
79
86 void add_sensor(binary_sensor::BinarySensor *sensor, uint16_t flags = 0,
88#endif
89
94 void set_codes(std::initializer_list<const char *> codes) { this->codes_ = codes; }
95
96 // Deleted overload to catch incorrect std::string usage at compile time
97 void set_codes(std::initializer_list<std::string> codes) = delete;
98
103 void set_requires_code_to_arm(bool code_to_arm) { this->requires_code_to_arm_ = code_to_arm; }
104
109 void set_arming_away_time(uint32_t time) { this->arming_away_time_ = time; }
110
115 void set_arming_home_time(uint32_t time) { this->arming_home_time_ = time; }
116
121 void set_arming_night_time(uint32_t time) { this->arming_night_time_ = time; }
122
127 void set_pending_time(uint32_t time) { this->pending_time_ = time; }
128
133 void set_trigger_time(uint32_t time) { this->trigger_time_ = time; }
134
135 void set_supports_arm_home(bool supports_arm_home) { supports_arm_home_ = supports_arm_home; }
136
137 void set_supports_arm_night(bool supports_arm_night) { supports_arm_night_ = supports_arm_night; }
138
139 protected:
141#ifdef USE_BINARY_SENSOR
142 // List of binary sensors with their alarm-specific info
144 // a list of automatically bypassed sensors
145 std::vector<uint8_t> bypassed_sensor_indicies_;
146 // Per sensor data store
147 std::vector<SensorDataStore> sensor_data_;
148 uint8_t next_store_index_ = 0;
149#endif
151
152 // the arming away delay
154 // the arming home delay
155 uint32_t arming_home_time_{0};
156 // the arming night delay
158 // the trigger delay
160 // the time in trigger
162 // a list of codes (const char* pointers to string literals in flash)
164 // requires a code to arm
166 bool supports_arm_home_ = false;
168 bool sensors_ready_ = false;
169 // check if the code is valid
171
173};
174
175} // namespace esphome::template_
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:299
bool empty() const
Definition helpers.h:457
Base class for all binary_sensor-type classes.
void set_codes(std::initializer_list< const char * > codes)
Set the codes (from initializer list).
void set_restore_mode(TemplateAlarmControlPanelRestoreMode restore_mode)
void set_trigger_time(uint32_t time)
set the delay before resetting after triggered
void arm_(optional< std::string > code, alarm_control_panel::AlarmControlPanelState state, uint32_t delay)
void add_sensor(binary_sensor::BinarySensor *sensor, uint16_t flags=0, AlarmSensorType type=ALARM_SENSOR_TYPE_DELAYED)
Add a binary_sensor to the alarm_panel.
void set_arming_night_time(uint32_t time)
set the delay before arming night
void set_pending_time(uint32_t time)
set the delay before triggering
void set_arming_home_time(uint32_t time)
set the delay before arming home
void control(const alarm_control_panel::AlarmControlPanelCall &call) override
void set_codes(std::initializer_list< std::string > codes)=delete
void init_sensors(size_t capacity)
Initialize the sensors vector with the specified capacity.
void set_arming_away_time(uint32_t time)
set the delay before arming away
void set_requires_code_to_arm(bool code_to_arm)
set requires a code to arm
uint16_t type
uint16_t flags
bool state
Definition fan.h:2
void HOT delay(uint32_t ms)
Definition core.cpp:27