ESPHome  2024.11.0
automation.h
Go to the documentation of this file.
1 
2 #pragma once
4 #include "alarm_control_panel.h"
5 
6 namespace esphome {
7 namespace alarm_control_panel {
8 
9 class StateTrigger : public Trigger<> {
10  public:
11  explicit StateTrigger(AlarmControlPanel *alarm_control_panel) {
12  alarm_control_panel->add_on_state_callback([this]() { this->trigger(); });
13  }
14 };
15 
16 class TriggeredTrigger : public Trigger<> {
17  public:
18  explicit TriggeredTrigger(AlarmControlPanel *alarm_control_panel) {
19  alarm_control_panel->add_on_triggered_callback([this]() { this->trigger(); });
20  }
21 };
22 
23 class ArmingTrigger : public Trigger<> {
24  public:
25  explicit ArmingTrigger(AlarmControlPanel *alarm_control_panel) {
26  alarm_control_panel->add_on_arming_callback([this]() { this->trigger(); });
27  }
28 };
29 
30 class PendingTrigger : public Trigger<> {
31  public:
32  explicit PendingTrigger(AlarmControlPanel *alarm_control_panel) {
33  alarm_control_panel->add_on_pending_callback([this]() { this->trigger(); });
34  }
35 };
36 
37 class ArmedHomeTrigger : public Trigger<> {
38  public:
39  explicit ArmedHomeTrigger(AlarmControlPanel *alarm_control_panel) {
40  alarm_control_panel->add_on_armed_home_callback([this]() { this->trigger(); });
41  }
42 };
43 
44 class ArmedNightTrigger : public Trigger<> {
45  public:
46  explicit ArmedNightTrigger(AlarmControlPanel *alarm_control_panel) {
47  alarm_control_panel->add_on_armed_night_callback([this]() { this->trigger(); });
48  }
49 };
50 
51 class ArmedAwayTrigger : public Trigger<> {
52  public:
53  explicit ArmedAwayTrigger(AlarmControlPanel *alarm_control_panel) {
54  alarm_control_panel->add_on_armed_away_callback([this]() { this->trigger(); });
55  }
56 };
57 
58 class DisarmedTrigger : public Trigger<> {
59  public:
60  explicit DisarmedTrigger(AlarmControlPanel *alarm_control_panel) {
61  alarm_control_panel->add_on_disarmed_callback([this]() { this->trigger(); });
62  }
63 };
64 
65 class ClearedTrigger : public Trigger<> {
66  public:
67  explicit ClearedTrigger(AlarmControlPanel *alarm_control_panel) {
68  alarm_control_panel->add_on_cleared_callback([this]() { this->trigger(); });
69  }
70 };
71 
72 class ChimeTrigger : public Trigger<> {
73  public:
74  explicit ChimeTrigger(AlarmControlPanel *alarm_control_panel) {
75  alarm_control_panel->add_on_chime_callback([this]() { this->trigger(); });
76  }
77 };
78 
79 class ReadyTrigger : public Trigger<> {
80  public:
81  explicit ReadyTrigger(AlarmControlPanel *alarm_control_panel) {
82  alarm_control_panel->add_on_ready_callback([this]() { this->trigger(); });
83  }
84 };
85 
86 template<typename... Ts> class ArmAwayAction : public Action<Ts...> {
87  public:
88  explicit ArmAwayAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
89 
90  TEMPLATABLE_VALUE(std::string, code)
91 
92  void play(Ts... x) override {
93  auto call = this->alarm_control_panel_->make_call();
94  auto code = this->code_.optional_value(x...);
95  if (code.has_value()) {
96  call.set_code(code.value());
97  }
98  call.arm_away();
99  call.perform();
100  }
101 
102  protected:
104 };
105 
106 template<typename... Ts> class ArmHomeAction : public Action<Ts...> {
107  public:
108  explicit ArmHomeAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
109 
110  TEMPLATABLE_VALUE(std::string, code)
111 
112  void play(Ts... x) override {
113  auto call = this->alarm_control_panel_->make_call();
114  auto code = this->code_.optional_value(x...);
115  if (code.has_value()) {
116  call.set_code(code.value());
117  }
118  call.arm_home();
119  call.perform();
120  }
121 
122  protected:
124 };
125 
126 template<typename... Ts> class ArmNightAction : public Action<Ts...> {
127  public:
128  explicit ArmNightAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
129 
130  TEMPLATABLE_VALUE(std::string, code)
131 
132  void play(Ts... x) override {
133  auto call = this->alarm_control_panel_->make_call();
134  auto code = this->code_.optional_value(x...);
135  if (code.has_value()) {
136  call.set_code(code.value());
137  }
138  call.arm_night();
139  call.perform();
140  }
141 
142  protected:
144 };
145 
146 template<typename... Ts> class DisarmAction : public Action<Ts...> {
147  public:
148  explicit DisarmAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
149 
150  TEMPLATABLE_VALUE(std::string, code)
151 
152  void play(Ts... x) override { this->alarm_control_panel_->disarm(this->code_.optional_value(x...)); }
153 
154  protected:
156 };
157 
158 template<typename... Ts> class PendingAction : public Action<Ts...> {
159  public:
160  explicit PendingAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
161 
162  void play(Ts... x) override { this->alarm_control_panel_->make_call().pending().perform(); }
163 
164  protected:
166 };
167 
168 template<typename... Ts> class TriggeredAction : public Action<Ts...> {
169  public:
170  explicit TriggeredAction(AlarmControlPanel *alarm_control_panel) : alarm_control_panel_(alarm_control_panel) {}
171 
172  void play(Ts... x) override { this->alarm_control_panel_->make_call().triggered().perform(); }
173 
174  protected:
176 };
177 
178 template<typename... Ts> class AlarmControlPanelCondition : public Condition<Ts...> {
179  public:
180  AlarmControlPanelCondition(AlarmControlPanel *parent) : parent_(parent) {}
181  bool check(Ts... x) override {
182  return this->parent_->is_state_armed(this->parent_->get_state()) ||
183  this->parent_->get_state() == ACP_STATE_PENDING || this->parent_->get_state() == ACP_STATE_TRIGGERED;
184  }
185 
186  protected:
188 };
189 
190 } // namespace alarm_control_panel
191 } // namespace esphome
void add_on_armed_night_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_night.
ArmAwayAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:88
void add_on_cleared_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel clears from triggered.
ArmedHomeTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:39
void add_on_triggered_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel chanes to triggered. ...
uint16_t x
Definition: tt21100.cpp:17
void add_on_armed_home_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_home.
void add_on_disarmed_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to disarmed. ...
ArmedAwayTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:53
PendingTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:32
TEMPLATABLE_VALUE(std::string, code) void play(Ts... x) override
Definition: automation.h:110
TEMPLATABLE_VALUE(std::string, code) void play(Ts... x) override
Definition: automation.h:150
void add_on_chime_callback(std::function< void()> &&callback)
Add a callback for when a chime zone goes from closed to open.
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
TEMPLATABLE_VALUE(std::string, code) void play(Ts... x) override
Definition: automation.h:90
Base class for all automation conditions.
Definition: automation.h:74
ArmingTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:25
void add_on_state_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes.
ClearedTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:67
ArmHomeAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:108
ChimeTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:74
ReadyTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:81
PendingAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:160
DisarmedTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:60
TriggeredTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:18
StateTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:11
TEMPLATABLE_VALUE(std::string, code) void play(Ts... x) override
Definition: automation.h:130
void add_on_pending_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to pending.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
DisarmAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:148
ArmedNightTrigger(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:46
void add_on_armed_away_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel changes to armed_away.
TriggeredAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:170
void add_on_ready_callback(std::function< void()> &&callback)
Add a callback for when a ready state changes.
void add_on_arming_callback(std::function< void()> &&callback)
Add a callback for when the state of the alarm_control_panel chanes to arming.
ArmNightAction(AlarmControlPanel *alarm_control_panel)
Definition: automation.h:128