ESPHome  2023.11.6
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 {
24 };
25 #endif
26 
30 };
31 
33  public:
35  void dump_config() override;
36  void setup() override;
37  void loop() override;
38  uint32_t get_supported_features() const override;
39  bool get_requires_code() const override;
40  bool get_requires_code_to_arm() const override { return this->requires_code_to_arm_; }
41  void set_restore_mode(TemplateAlarmControlPanelRestoreMode restore_mode) { this->restore_mode_ = restore_mode; }
42 
43 #ifdef USE_BINARY_SENSOR
44 
49  void add_sensor(binary_sensor::BinarySensor *sensor, uint16_t flags = 0);
50 #endif
51 
56  void add_code(const std::string &code) { this->codes_.push_back(code); }
57 
62  void set_requires_code_to_arm(bool code_to_arm) { this->requires_code_to_arm_ = code_to_arm; }
63 
68  void set_arming_away_time(uint32_t time) { this->arming_away_time_ = time; }
69 
74  void set_arming_home_time(uint32_t time) { this->arming_home_time_ = time; }
75 
80  void set_arming_night_time(uint32_t time) { this->arming_night_time_ = time; }
81 
86  void set_pending_time(uint32_t time) { this->pending_time_ = time; }
87 
92  void set_trigger_time(uint32_t time) { this->trigger_time_ = time; }
93 
94  void set_supports_arm_home(bool supports_arm_home) { supports_arm_home_ = supports_arm_home; }
95 
96  void set_supports_arm_night(bool supports_arm_night) { supports_arm_night_ = supports_arm_night; }
97 
98  protected:
100 #ifdef USE_BINARY_SENSOR
101  // the map of binary sensors that the alarm_panel monitors with their modes
102  std::map<binary_sensor::BinarySensor *, uint16_t> sensor_map_;
103 #endif
105 
106  // the arming away delay
108  // the arming home delay
109  uint32_t arming_home_time_{0};
110  // the arming night delay
111  uint32_t arming_night_time_{0};
112  // the trigger delay
113  uint32_t pending_time_;
114  // the time in trigger
115  uint32_t trigger_time_;
116  // a list of codes
117  std::vector<std::string> codes_;
118  // requires a code to arm
119  bool requires_code_to_arm_ = false;
120  bool supports_arm_home_ = false;
121  bool supports_arm_night_ = false;
122  // check if the code is valid
124 
126 };
127 
128 } // namespace template_
129 } // namespace esphome
void add_code(const std::string &code)
add a code
void control(const alarm_control_panel::AlarmControlPanelCall &call) override
void add_sensor(binary_sensor::BinarySensor *sensor, uint16_t flags=0)
Add a binary_sensor to the alarm_panel.
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
std::map< binary_sensor::BinarySensor *, uint16_t > sensor_map_
void arm_(optional< std::string > code, alarm_control_panel::AlarmControlPanelState state, uint32_t delay)
const uint32_t flags
Definition: stm32flash.h:85
void set_requires_code_to_arm(bool code_to_arm)
set requires a code to arm
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)
bool state
Definition: fan.h:34
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26