ESPHome 2026.5.1
Loading...
Searching...
No Matches
demo_alarm_control_panel.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::demo {
7
8using namespace alarm_control_panel;
9
11 TYPE_1,
12 TYPE_2,
13 TYPE_3,
14};
15
17 public:
18 void setup() override {}
19
21
22 bool get_requires_code() const override { return this->type_ != DemoAlarmControlPanelType::TYPE_1; }
23
24 bool get_requires_code_to_arm() const override { return this->type_ == DemoAlarmControlPanelType::TYPE_3; }
25
27
28 protected:
29 void control(const AlarmControlPanelCall &call) override {
30 auto state = call.get_state().value_or(ACP_STATE_DISARMED);
31 const auto &code = call.get_code();
32 switch (state) {
34 if (this->get_requires_code_to_arm()) {
35 if (!code.has_value() || *code != "1234") {
36 this->status_momentary_error("invalid_code", 5000);
37 return;
38 }
39 }
41 break;
43 if (this->get_requires_code()) {
44 if (!code.has_value() || *code != "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 esphome::demo
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
static void uint32_t