ESPHome  2024.12.2
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 && !this->parent_->is_state_armed(this->parent_->get_state()) &&
78  ESP_LOGW(TAG, "Cannot disarm when not armed");
79  this->state_.reset();
80  return;
81  }
83  ESP_LOGW(TAG, "Cannot arm home when not supported");
84  this->state_.reset();
85  return;
86  }
88  ESP_LOGW(TAG, "Cannot arm night when not supported");
89  this->state_.reset();
90  return;
91  }
92  }
93 }
94 
96  this->validate_();
97  if (this->state_) {
98  this->parent_->control(*this);
99  }
100 }
101 
102 } // namespace alarm_control_panel
103 } // 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
Implementation of SPI Controller mode.
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