ESPHome  2024.4.0
alarm_control_panel_call.cpp
Go to the documentation of this file.
2 
3 #include "alarm_control_panel.h"
4 
5 #include "esphome/core/log.h"
6 
7 namespace esphome {
8 namespace alarm_control_panel {
9 
10 static const char *const TAG = "alarm_control_panel";
11 
13 
15  this->code_ = code;
16  return *this;
17 }
18 
21  return *this;
22 }
23 
26  return *this;
27 }
28 
31  return *this;
32 }
33 
36  return *this;
37 }
38 
41  return *this;
42 }
43 
45  this->state_ = ACP_STATE_DISARMED;
46  return *this;
47 }
48 
50  this->state_ = ACP_STATE_PENDING;
51  return *this;
52 }
53 
56  return *this;
57 }
58 
61 
63  if (this->state_.has_value()) {
64  auto state = *this->state_;
65  if (this->parent_->is_state_armed(state) && this->parent_->get_state() != ACP_STATE_DISARMED) {
66  ESP_LOGW(TAG, "Cannot arm when not disarmed");
67  this->state_.reset();
68  return;
69  }
71  ESP_LOGW(TAG, "Cannot trip alarm when disarmed");
72  this->state_.reset();
73  return;
74  }
75  if (state == ACP_STATE_DISARMED &&
76  !(this->parent_->is_state_armed(this->parent_->get_state()) ||
78  this->parent_->get_state() == ACP_STATE_TRIGGERED)) {
79  ESP_LOGW(TAG, "Cannot disarm when not armed");
80  this->state_.reset();
81  return;
82  }
84  ESP_LOGW(TAG, "Cannot arm home when not supported");
85  this->state_.reset();
86  return;
87  }
89  ESP_LOGW(TAG, "Cannot arm night when not supported");
90  this->state_.reset();
91  return;
92  }
93  }
94 }
95 
97  this->validate_();
98  if (this->state_) {
99  this->parent_->control(*this);
100  }
101 }
102 
103 } // namespace alarm_control_panel
104 } // namespace esphome
AlarmControlPanelState get_state() const
Get the state.
bool is_state_armed(AlarmControlPanelState state)
bool has_value() const
Definition: optional.h:87
virtual void control(const AlarmControlPanelCall &call)=0
AlarmControlPanelCall & set_code(const std::string &code)
const optional< AlarmControlPanelState > & get_state() const
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
virtual uint32_t get_supported_features() const =0
A numeric representation of the supported features as per HomeAssistant.
bool state
Definition: fan.h:34