14static const char *
const TAG =
"template.alarm_control_panel";
18#ifdef USE_BINARY_SENSOR
32 return LOG_STR(
"instant");
34 return LOG_STR(
"delayed_follower");
36 return LOG_STR(
"instant_always");
39 return LOG_STR(
"delayed");
46 "TemplateAlarmControlPanel:\n"
47 " Current State: %s\n"
48 " Number of Codes: %u\n"
49 " Requires Code To Arm: %s\n"
50 " Arming Away Time: %" PRIu32
"s\n"
51 " Arming Home Time: %" PRIu32
"s\n"
52 " Arming Night Time: %" PRIu32
"s\n"
53 " Pending Time: %" PRIu32
"s\n"
54 " Trigger Time: %" PRIu32
"s\n"
55 " Supported Features: %" PRIu32,
57 YESNO(!this->
codes_.empty() && this->requires_code_to_arm_), (this->arming_away_time_ / 1000),
58 (this->arming_home_time_ / 1000), (this->arming_night_time_ / 1000), (this->pending_time_ / 1000),
59 (this->trigger_time_ / 1000), this->get_supported_features());
60#ifdef USE_BINARY_SENSOR
61 for (
auto const &[sensor, info] : this->
sensor_map_) {
66 " Armed home bypass: %s\n"
67 " Armed night bypass: %s\n"
70 sensor->get_name().c_str(), LOG_STR_ARG(sensor_type_to_string(info.type)),
119 bool delayed_sensor_faulted =
false;
120 bool instant_sensor_faulted =
false;
122#ifdef USE_BINARY_SENSOR
124 for (
auto const &[sensor, info] : this->
sensor_map_) {
128 if ((!this->
sensor_data_[info.store_index].last_chime_state) && (sensor->state)) {
135 this->
sensor_data_[info.store_index].last_chime_state = sensor->state;
141 info.store_index) == 1) {
158 instant_sensor_faulted =
true;
163 delayed_sensor_faulted =
true;
165 instant_sensor_faulted =
true;
170 delayed_sensor_faulted =
true;
175 bool sensors_ready = !(instant_sensor_faulted || delayed_sensor_faulted);
186 if (instant_sensor_faulted) {
188 }
else if (delayed_sensor_faulted) {
202 if (!this->
codes_.empty()) {
204 ESP_LOGVV(TAG,
"Checking code: %s", code.
value().c_str());
205 return (std::count(this->
codes_.begin(), this->codes_.end(), code.
value()) == 1);
207 ESP_LOGD(TAG,
"No code provided");
227 ESP_LOGW(TAG,
"Cannot arm when not disarmed");
231 ESP_LOGW(TAG,
"Not arming code doesn't match");
244#ifdef USE_BINARY_SENSOR
245 for (
auto const &[sensor, info] : this->
sensor_map_) {
248 ESP_LOGW(TAG,
"'%s' is faulted and will be automatically bypassed", sensor->get_name().c_str());
256 if (
call.get_state()) {
265 ESP_LOGW(TAG,
"Not disarming code doesn't match");
270#ifdef USE_BINARY_SENSOR
278 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_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
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_
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_
void bypass_before_arming()
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
std::vector< uint8_t > bypassed_sensor_indicies_
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_BYPASS_AUTO
@ BINARY_SENSOR_MODE_CHIME
@ BINARY_SENSOR_MODE_BYPASS_ARMED_HOME
@ BINARY_SENSOR_MODE_BYPASS_ARMED_NIGHT
@ 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()