ESPHome 2025.6.2
Loading...
Searching...
No Matches
demo_alarm_control_panel.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace demo {
8
9using namespace alarm_control_panel;
10
12 TYPE_1,
13 TYPE_2,
14 TYPE_3,
15};
16
18 public:
19 void setup() override {}
20
21 uint32_t get_supported_features() const override { return ACP_FEAT_ARM_AWAY | ACP_FEAT_TRIGGER; }
22
23 bool get_requires_code() const override { return this->type_ != DemoAlarmControlPanelType::TYPE_1; }
24
25 bool get_requires_code_to_arm() const override { return this->type_ == DemoAlarmControlPanelType::TYPE_3; }
26
28
29 protected:
30 void control(const AlarmControlPanelCall &call) override {
31 auto state = call.get_state().value_or(ACP_STATE_DISARMED);
32 switch (state) {
34 if (this->get_requires_code_to_arm() && call.get_code().has_value()) {
35 if (call.get_code().value() != "1234") {
36 this->status_momentary_error("Invalid code", 5000);
37 return;
38 }
39 }
41 break;
43 if (this->get_requires_code() && call.get_code().has_value()) {
44 if (call.get_code().value() != "1234") {
45 this->status_momentary_error("Invalid code", 5000);
46 return;
47 }
48 }
50 return;
53 return;
56 return;
57 default:
58 break;
59 }
60 }
62};
63
64} // namespace demo
65} // namespace esphome
void status_momentary_error(const std::string &name, uint32_t length=5000)
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
void control(const AlarmControlPanelCall &call) override
void set_type(DemoAlarmControlPanelType type)
bool has_value() const
Definition optional.h:87
uint8_t type
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7