ESPHome 2026.3.3
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
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 auto code = call.get_code();
33 switch (state) {
35 if (this->get_requires_code_to_arm()) {
36 if (!code.has_value() || *code != "1234") {
37 this->status_momentary_error("invalid_code", 5000);
38 return;
39 }
40 }
42 break;
44 if (this->get_requires_code()) {
45 if (!code.has_value() || *code != "1234") {
46 this->status_momentary_error("invalid_code", 5000);
47 return;
48 }
49 }
51 return;
54 return;
57 return;
58 default:
59 break;
60 }
61 }
63};
64
65} // namespace demo
66} // namespace esphome
void status_momentary_error(const char *name, uint32_t length=5000)
Set error status flag and automatically clear it after a timeout.
void publish_state(AlarmControlPanelState state)
Set the state of the alarm_control_panel.
void control(const AlarmControlPanelCall &call) override
void set_type(DemoAlarmControlPanelType type)
uint16_t type
bool state
Definition fan.h:2
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
static void uint32_t