ESPHome  2024.10.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace sprinkler {
9 
10 template<typename... Ts> class SetDividerAction : public Action<Ts...> {
11  public:
12  explicit SetDividerAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
13 
14  TEMPLATABLE_VALUE(uint32_t, divider)
15 
16  void play(Ts... x) override { this->sprinkler_->set_divider(this->divider_.optional_value(x...)); }
17 
18  protected:
20 };
21 
22 template<typename... Ts> class SetMultiplierAction : public Action<Ts...> {
23  public:
24  explicit SetMultiplierAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
25 
26  TEMPLATABLE_VALUE(float, multiplier)
27 
28  void play(Ts... x) override { this->sprinkler_->set_multiplier(this->multiplier_.optional_value(x...)); }
29 
30  protected:
32 };
33 
34 template<typename... Ts> class QueueValveAction : public Action<Ts...> {
35  public:
36  explicit QueueValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
37 
38  TEMPLATABLE_VALUE(size_t, valve_number)
39  TEMPLATABLE_VALUE(uint32_t, valve_run_duration)
40 
41  void play(Ts... x) override {
42  this->sprinkler_->queue_valve(this->valve_number_.optional_value(x...),
43  this->valve_run_duration_.optional_value(x...));
44  }
45 
46  protected:
48 };
49 
50 template<typename... Ts> class ClearQueuedValvesAction : public Action<Ts...> {
51  public:
52  explicit ClearQueuedValvesAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
53 
54  void play(Ts... x) override { this->sprinkler_->clear_queued_valves(); }
55 
56  protected:
58 };
59 
60 template<typename... Ts> class SetRepeatAction : public Action<Ts...> {
61  public:
62  explicit SetRepeatAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
63 
64  TEMPLATABLE_VALUE(uint32_t, repeat)
65 
66  void play(Ts... x) override { this->sprinkler_->set_repeat(this->repeat_.optional_value(x...)); }
67 
68  protected:
70 };
71 
72 template<typename... Ts> class SetRunDurationAction : public Action<Ts...> {
73  public:
74  explicit SetRunDurationAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
75 
76  TEMPLATABLE_VALUE(size_t, valve_number)
77  TEMPLATABLE_VALUE(uint32_t, valve_run_duration)
78 
79  void play(Ts... x) override {
80  this->sprinkler_->set_valve_run_duration(this->valve_number_.optional_value(x...),
81  this->valve_run_duration_.optional_value(x...));
82  }
83 
84  protected:
86 };
87 
88 template<typename... Ts> class StartFromQueueAction : public Action<Ts...> {
89  public:
90  explicit StartFromQueueAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
91 
92  void play(Ts... x) override { this->sprinkler_->start_from_queue(); }
93 
94  protected:
96 };
97 
98 template<typename... Ts> class StartFullCycleAction : public Action<Ts...> {
99  public:
100  explicit StartFullCycleAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
101 
102  void play(Ts... x) override { this->sprinkler_->start_full_cycle(); }
103 
104  protected:
106 };
107 
108 template<typename... Ts> class StartSingleValveAction : public Action<Ts...> {
109  public:
110  explicit StartSingleValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
111 
112  TEMPLATABLE_VALUE(size_t, valve_to_start)
113  TEMPLATABLE_VALUE(uint32_t, valve_run_duration)
114 
115  void play(Ts... x) override {
116  this->sprinkler_->start_single_valve(this->valve_to_start_.optional_value(x...),
117  this->valve_run_duration_.optional_value(x...));
118  }
119 
120  protected:
122 };
123 
124 template<typename... Ts> class ShutdownAction : public Action<Ts...> {
125  public:
126  explicit ShutdownAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
127 
128  void play(Ts... x) override { this->sprinkler_->shutdown(); }
129 
130  protected:
132 };
133 
134 template<typename... Ts> class NextValveAction : public Action<Ts...> {
135  public:
136  explicit NextValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
137 
138  void play(Ts... x) override { this->sprinkler_->next_valve(); }
139 
140  protected:
142 };
143 
144 template<typename... Ts> class PreviousValveAction : public Action<Ts...> {
145  public:
146  explicit PreviousValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
147 
148  void play(Ts... x) override { this->sprinkler_->previous_valve(); }
149 
150  protected:
152 };
153 
154 template<typename... Ts> class PauseAction : public Action<Ts...> {
155  public:
156  explicit PauseAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
157 
158  void play(Ts... x) override { this->sprinkler_->pause(); }
159 
160  protected:
162 };
163 
164 template<typename... Ts> class ResumeAction : public Action<Ts...> {
165  public:
166  explicit ResumeAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
167 
168  void play(Ts... x) override { this->sprinkler_->resume(); }
169 
170  protected:
172 };
173 
174 template<typename... Ts> class ResumeOrStartAction : public Action<Ts...> {
175  public:
176  explicit ResumeOrStartAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
177 
178  void play(Ts... x) override { this->sprinkler_->resume_or_start_full_cycle(); }
179 
180  protected:
182 };
183 
184 } // namespace sprinkler
185 } // namespace esphome
void set_repeat(optional< uint32_t > repeat)
set the number of times to repeat a full cycle
Definition: sprinkler.cpp:672
void play(Ts... x) override
Definition: automation.h:158
void play(Ts... x) override
Definition: automation.h:138
void previous_valve()
advances to the previous valve (numerically)
Definition: sprinkler.cpp:913
NextValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:136
void next_valve()
advances to the next valve (numerically)
Definition: sprinkler.cpp:890
void queue_valve(optional< size_t > valve_number, optional< uint32_t > run_duration)
adds a valve into the queue.
Definition: sprinkler.cpp:874
void set_divider(optional< uint32_t > divider)
sets the multiplier value to &#39;1 / divider&#39; and sets repeat value to divider
Definition: sprinkler.cpp:551
uint16_t x
Definition: tt21100.cpp:17
SetDividerAction(Sprinkler *a_sprinkler)
Definition: automation.h:12
void set_multiplier(optional< float > multiplier)
value multiplied by configured run times – used to extend or shorten the cycle
Definition: sprinkler.cpp:564
void play(Ts... x) override
Definition: automation.h:128
void shutdown(bool clear_queue=false)
turns off all valves, effectively shutting down the system.
Definition: sprinkler.cpp:936
void set_valve_run_duration(optional< size_t > valve_number, optional< uint32_t > run_duration)
set how long the valve should remain on/open. run_duration is time in seconds
Definition: sprinkler.cpp:635
ClearQueuedValvesAction(Sprinkler *a_sprinkler)
Definition: automation.h:52
SetRunDurationAction(Sprinkler *a_sprinkler)
Definition: automation.h:74
void resume_or_start_full_cycle()
if a cycle was suspended using pause(), resumes it. otherwise calls start_full_cycle() ...
Definition: sprinkler.cpp:981
PauseAction(Sprinkler *a_sprinkler)
Definition: automation.h:156
QueueValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:36
StartSingleValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:110
void resume()
resumes a cycle that was suspended using pause()
Definition: sprinkler.cpp:962
void pause()
same as shutdown(), but also stores active_valve() and time_remaining() allowing resume() to continue...
Definition: sprinkler.cpp:951
void start_full_cycle()
starts a full cycle of all enabled valves and enables auto_advance.
Definition: sprinkler.cpp:830
TEMPLATABLE_VALUE(uint32_t, repeat) void play(Ts... x) override
Definition: automation.h:64
SetRepeatAction(Sprinkler *a_sprinkler)
Definition: automation.h:62
TEMPLATABLE_VALUE(float, multiplier) void play(Ts... x) override
Definition: automation.h:26
void start_from_queue()
starts the controller from the first valve in the queue and disables auto_advance.
Definition: sprinkler.cpp:806
TEMPLATABLE_VALUE(uint32_t, divider) void play(Ts... x) override
Definition: automation.h:14
void clear_queued_valves()
clears/removes all valves from the queue
Definition: sprinkler.cpp:885
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void play(Ts... x) override
Definition: automation.h:168
ResumeOrStartAction(Sprinkler *a_sprinkler)
Definition: automation.h:176
PreviousValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:146
StartFromQueueAction(Sprinkler *a_sprinkler)
Definition: automation.h:90
SetMultiplierAction(Sprinkler *a_sprinkler)
Definition: automation.h:24
ShutdownAction(Sprinkler *a_sprinkler)
Definition: automation.h:126
void start_single_valve(optional< size_t > valve_number, optional< uint32_t > run_duration=nullopt)
activates a single valve and disables auto_advance.
Definition: sprinkler.cpp:853
ResumeAction(Sprinkler *a_sprinkler)
Definition: automation.h:166
virtual void play(Ts... x)=0
StartFullCycleAction(Sprinkler *a_sprinkler)
Definition: automation.h:100