14static const char *
const TAG =
"template.alarm_control_panel";
18#ifdef USE_BINARY_SENSOR
31 ESP_LOGCONFIG(TAG,
"TemplateAlarmControlPanel:");
33 ESP_LOGCONFIG(TAG,
" Number of Codes: %u", this->
codes_.size());
36 ESP_LOGCONFIG(TAG,
" Arming Away Time: %" PRIu32
"s", (this->
arming_away_time_ / 1000));
38 ESP_LOGCONFIG(TAG,
" Arming Home Time: %" PRIu32
"s", (this->
arming_home_time_ / 1000));
40 ESP_LOGCONFIG(TAG,
" Arming Night Time: %" PRIu32
"s", (this->
arming_night_time_ / 1000));
41 ESP_LOGCONFIG(TAG,
" Pending Time: %" PRIu32
"s", (this->
pending_time_ / 1000));
42 ESP_LOGCONFIG(TAG,
" Trigger Time: %" PRIu32
"s", (this->
trigger_time_ / 1000));
44#ifdef USE_BINARY_SENSOR
46 ESP_LOGCONFIG(TAG,
" Binary Sensor:");
47 ESP_LOGCONFIG(TAG,
" Name: %s", sensor_info.first->get_name().c_str());
48 ESP_LOGCONFIG(TAG,
" Armed home bypass: %s",
50 ESP_LOGCONFIG(TAG,
" Armed night bypass: %s",
53 const char *sensor_type;
54 switch (sensor_info.second.type) {
56 sensor_type =
"instant";
59 sensor_type =
"delayed_follower";
62 sensor_type =
"instant_always";
66 sensor_type =
"delayed";
68 ESP_LOGCONFIG(TAG,
" Sensor type: %s", sensor_type);
74 ESP_LOGCONFIG(TAG,
"Setting up Template AlarmControlPanel '%s'...", this->
name_.
c_str());
120 bool delayed_sensor_not_ready =
false;
121 bool instant_sensor_not_ready =
false;
123#ifdef USE_BINARY_SENSOR
129 if ((!this->
sensor_data_[sensor_info.second.store_index].last_chime_state) && (sensor_info.first->state)) {
136 this->
sensor_data_[sensor_info.second.store_index].last_chime_state = sensor_info.first->state;
139 if (sensor_info.first->state) {
151 switch (sensor_info.second.type) {
153 instant_sensor_not_ready =
true;
156 instant_sensor_not_ready =
true;
162 delayed_sensor_not_ready =
true;
164 instant_sensor_not_ready =
true;
169 delayed_sensor_not_ready =
true;
174 this->
sensors_ready_ = ((!instant_sensor_not_ready) && (!delayed_sensor_not_ready));
185 if (instant_sensor_not_ready) {
187 }
else if (delayed_sensor_not_ready) {
201 if (!this->
codes_.empty()) {
203 ESP_LOGVV(TAG,
"Checking code: %s", code.
value().c_str());
204 return (std::count(this->
codes_.begin(), this->codes_.end(), code.
value()) == 1);
206 ESP_LOGD(TAG,
"No code provided");
228 ESP_LOGW(TAG,
"Cannot arm when not disarmed");
232 ESP_LOGW(TAG,
"Not arming code doesn't match");
244 if (
call.get_state()) {
253 ESP_LOGW(TAG,
"Not disarming code doesn't match");
263 ESP_LOGE(TAG,
"State not yet implemented: %s",
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_object_id_hash()
constexpr const char * c_str() const
const optional< std::string > & get_code() const
const optional< AlarmControlPanelState > & get_state() const
AlarmControlPanelState desired_state_
bool is_state_armed(AlarmControlPanelState state)
ESPPreferenceObject pref_
AlarmControlPanelState current_state_
CallbackManager< void()> chime_callback_
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
CallbackManager< void()> ready_callback_
Base class for all binary_sensor-type classes.
value_type const & value() const
uint32_t arming_away_time_
bool get_requires_code() const override
TemplateAlarmControlPanelRestoreMode restore_mode_
uint32_t arming_home_time_
std::vector< std::string > codes_
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.
uint32_t arming_night_time_
void dump_config() override
uint32_t get_supported_features() const override
uint8_t next_store_index_
bool requires_code_to_arm_
std::map< binary_sensor::BinarySensor *, SensorInfo > sensor_map_
std::vector< SensorDataStore > sensor_data_
void control(const alarm_control_panel::AlarmControlPanelCall &call) override
bool is_code_valid_(optional< std::string > code)
TemplateAlarmControlPanel()
const LogString * alarm_control_panel_state_to_string(AlarmControlPanelState state)
Returns a string representation of the state.
@ ALARM_SENSOR_TYPE_DELAYED
@ ALARM_SENSOR_TYPE_INSTANT
@ ALARM_SENSOR_TYPE_INSTANT_ALWAYS
@ ALARM_SENSOR_TYPE_DELAYED_FOLLOWER
@ BINARY_SENSOR_MODE_CHIME
@ BINARY_SENSOR_MODE_BYPASS_ARMED_HOME
@ BINARY_SENSOR_MODE_BYPASS_ARMED_NIGHT
@ ALARM_CONTROL_PANEL_ALWAYS_DISARMED
@ ALARM_CONTROL_PANEL_RESTORE_DEFAULT_DISARMED
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()