ESPHome  2022.12.8
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 SetMultiplierAction : public Action<Ts...> {
11  public:
12  explicit SetMultiplierAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
13 
14  TEMPLATABLE_VALUE(float, multiplier)
15 
16  void play(Ts... x) override { this->sprinkler_->set_multiplier(this->multiplier_.optional_value(x...)); }
17 
18  protected:
20 };
21 
22 template<typename... Ts> class QueueValveAction : public Action<Ts...> {
23  public:
24  explicit QueueValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
25 
26  TEMPLATABLE_VALUE(size_t, valve_number)
27  TEMPLATABLE_VALUE(uint32_t, valve_run_duration)
28 
29  void play(Ts... x) override {
30  this->sprinkler_->queue_valve(this->valve_number_.optional_value(x...),
31  this->valve_run_duration_.optional_value(x...));
32  }
33 
34  protected:
36 };
37 
38 template<typename... Ts> class ClearQueuedValvesAction : public Action<Ts...> {
39  public:
40  explicit ClearQueuedValvesAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
41 
42  void play(Ts... x) override { this->sprinkler_->clear_queued_valves(); }
43 
44  protected:
46 };
47 
48 template<typename... Ts> class SetRepeatAction : public Action<Ts...> {
49  public:
50  explicit SetRepeatAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
51 
52  TEMPLATABLE_VALUE(uint32_t, repeat)
53 
54  void play(Ts... x) override { this->sprinkler_->set_repeat(this->repeat_.optional_value(x...)); }
55 
56  protected:
58 };
59 
60 template<typename... Ts> class SetRunDurationAction : public Action<Ts...> {
61  public:
62  explicit SetRunDurationAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
63 
64  TEMPLATABLE_VALUE(size_t, valve_number)
65  TEMPLATABLE_VALUE(uint32_t, valve_run_duration)
66 
67  void play(Ts... x) override {
68  this->sprinkler_->set_valve_run_duration(this->valve_number_.optional_value(x...),
69  this->valve_run_duration_.optional_value(x...));
70  }
71 
72  protected:
74 };
75 
76 template<typename... Ts> class StartFromQueueAction : public Action<Ts...> {
77  public:
78  explicit StartFromQueueAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
79 
80  void play(Ts... x) override { this->sprinkler_->start_from_queue(); }
81 
82  protected:
84 };
85 
86 template<typename... Ts> class StartFullCycleAction : public Action<Ts...> {
87  public:
88  explicit StartFullCycleAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
89 
90  void play(Ts... x) override { this->sprinkler_->start_full_cycle(); }
91 
92  protected:
94 };
95 
96 template<typename... Ts> class StartSingleValveAction : public Action<Ts...> {
97  public:
98  explicit StartSingleValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
99 
100  TEMPLATABLE_VALUE(size_t, valve_to_start)
101 
102  void play(Ts... x) override { this->sprinkler_->start_single_valve(this->valve_to_start_.optional_value(x...)); }
103 
104  protected:
106 };
107 
108 template<typename... Ts> class ShutdownAction : public Action<Ts...> {
109  public:
110  explicit ShutdownAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
111 
112  void play(Ts... x) override { this->sprinkler_->shutdown(); }
113 
114  protected:
116 };
117 
118 template<typename... Ts> class NextValveAction : public Action<Ts...> {
119  public:
120  explicit NextValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
121 
122  void play(Ts... x) override { this->sprinkler_->next_valve(); }
123 
124  protected:
126 };
127 
128 template<typename... Ts> class PreviousValveAction : public Action<Ts...> {
129  public:
130  explicit PreviousValveAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
131 
132  void play(Ts... x) override { this->sprinkler_->previous_valve(); }
133 
134  protected:
136 };
137 
138 template<typename... Ts> class PauseAction : public Action<Ts...> {
139  public:
140  explicit PauseAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
141 
142  void play(Ts... x) override { this->sprinkler_->pause(); }
143 
144  protected:
146 };
147 
148 template<typename... Ts> class ResumeAction : public Action<Ts...> {
149  public:
150  explicit ResumeAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
151 
152  void play(Ts... x) override { this->sprinkler_->resume(); }
153 
154  protected:
156 };
157 
158 template<typename... Ts> class ResumeOrStartAction : public Action<Ts...> {
159  public:
160  explicit ResumeOrStartAction(Sprinkler *a_sprinkler) : sprinkler_(a_sprinkler) {}
161 
162  void play(Ts... x) override { this->sprinkler_->resume_or_start_full_cycle(); }
163 
164  protected:
166 };
167 
168 } // namespace sprinkler
169 } // namespace esphome
void set_repeat(optional< uint32_t > repeat)
set the number of times to repeat a full cycle
Definition: sprinkler.cpp:575
TEMPLATABLE_VALUE(size_t, valve_to_start) void play(Ts... x) override
Definition: automation.h:100
void play(Ts... x) override
Definition: automation.h:142
void play(Ts... x) override
Definition: automation.h:122
void previous_valve()
advances to the previous valve (numerically)
Definition: sprinkler.cpp:727
NextValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:120
void next_valve()
advances to the next valve (numerically)
Definition: sprinkler.cpp:713
void queue_valve(optional< size_t > valve_number, optional< uint32_t > run_duration)
adds a valve into the queue.
Definition: sprinkler.cpp:697
void set_multiplier(optional< float > multiplier)
value multiplied by configured run times – used to extend or shorten the cycle
Definition: sprinkler.cpp:502
void play(Ts... x) override
Definition: automation.h:112
void shutdown(bool clear_queue=false)
turns off all valves, effectively shutting down the system.
Definition: sprinkler.cpp:741
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:561
ClearQueuedValvesAction(Sprinkler *a_sprinkler)
Definition: automation.h:40
SetRunDurationAction(Sprinkler *a_sprinkler)
Definition: automation.h:62
void resume_or_start_full_cycle()
if a cycle was suspended using pause(), resumes it. otherwise calls start_full_cycle() ...
Definition: sprinkler.cpp:778
void start_single_valve(optional< size_t > valve_number)
activates a single valve and disables auto_advance.
Definition: sprinkler.cpp:681
PauseAction(Sprinkler *a_sprinkler)
Definition: automation.h:140
QueueValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:24
StartSingleValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:98
void resume()
resumes a cycle that was suspended using pause()
Definition: sprinkler.cpp:767
void pause()
same as shutdown(), but also stores active_valve() and time_remaining() allowing resume() to continue...
Definition: sprinkler.cpp:756
void start_full_cycle()
starts a full cycle of all enabled valves and enables auto_advance.
Definition: sprinkler.cpp:665
TEMPLATABLE_VALUE(uint32_t, repeat) void play(Ts... x) override
Definition: automation.h:52
SetRepeatAction(Sprinkler *a_sprinkler)
Definition: automation.h:50
TEMPLATABLE_VALUE(float, multiplier) void play(Ts... x) override
Definition: automation.h:14
void start_from_queue()
starts the controller from the first valve in the queue and disables auto_advance.
Definition: sprinkler.cpp:646
void clear_queued_valves()
clears/removes all valves from the queue
Definition: sprinkler.cpp:708
Definition: a4988.cpp:4
void play(Ts... x) override
Definition: automation.h:152
ResumeOrStartAction(Sprinkler *a_sprinkler)
Definition: automation.h:160
PreviousValveAction(Sprinkler *a_sprinkler)
Definition: automation.h:130
StartFromQueueAction(Sprinkler *a_sprinkler)
Definition: automation.h:78
SetMultiplierAction(Sprinkler *a_sprinkler)
Definition: automation.h:12
ShutdownAction(Sprinkler *a_sprinkler)
Definition: automation.h:110
ResumeAction(Sprinkler *a_sprinkler)
Definition: automation.h:150
virtual void play(Ts... x)=0
StartFullCycleAction(Sprinkler *a_sprinkler)
Definition: automation.h:88