mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
Make some Action methods protected
Apparently play()/stop() etc. are not meant to be called directly by users of the class and if they're called directly that would not give the expected result for the classes that have an empty play(). Make all methods except play_complex, stop_comples and is_running protected. While there also make RemoteTransmitterActionBase::encode protected.
This commit is contained in:
parent
da390d32f8
commit
a62b6548d2
42 changed files with 250 additions and 203 deletions
|
@ -29,7 +29,9 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
|
||||||
template<typename T> void add_variable(std::string key, T value) {
|
template<typename T> void add_variable(std::string key, T value) {
|
||||||
this->variables_.push_back(TemplatableKeyValuePair<Ts...>(key, value));
|
this->variables_.push_back(TemplatableKeyValuePair<Ts...>(key, value));
|
||||||
}
|
}
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
HomeassistantServiceResponse resp;
|
HomeassistantServiceResponse resp;
|
||||||
resp.service = this->service_.value(x...);
|
resp.service = this->service_.value(x...);
|
||||||
resp.is_event = this->is_event_;
|
resp.is_event = this->is_event_;
|
||||||
|
@ -54,7 +56,6 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
|
||||||
this->parent_->send_homeassistant_service_call(resp);
|
this->parent_->send_homeassistant_service_call(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
APIServer *parent_;
|
APIServer *parent_;
|
||||||
bool is_event_;
|
bool is_event_;
|
||||||
std::vector<TemplatableKeyValuePair<Ts...>> data_;
|
std::vector<TemplatableKeyValuePair<Ts...>> data_;
|
||||||
|
|
|
@ -137,12 +137,13 @@ template<typename... Ts> class BinarySensorPublishAction : public Action<Ts...>
|
||||||
public:
|
public:
|
||||||
explicit BinarySensorPublishAction(BinarySensor *sensor) : sensor_(sensor) {}
|
explicit BinarySensorPublishAction(BinarySensor *sensor) : sensor_(sensor) {}
|
||||||
TEMPLATABLE_VALUE(bool, state)
|
TEMPLATABLE_VALUE(bool, state)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto val = this->state_.value(x...);
|
auto val = this->state_.value(x...);
|
||||||
this->sensor_->publish_state(val);
|
this->sensor_->publish_state(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
BinarySensor *sensor_;
|
BinarySensor *sensor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(ClimateFanMode, fan_mode)
|
TEMPLATABLE_VALUE(ClimateFanMode, fan_mode)
|
||||||
TEMPLATABLE_VALUE(ClimateSwingMode, swing_mode)
|
TEMPLATABLE_VALUE(ClimateSwingMode, swing_mode)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->climate_->make_call();
|
auto call = this->climate_->make_call();
|
||||||
call.set_mode(this->mode_.optional_value(x...));
|
call.set_mode(this->mode_.optional_value(x...));
|
||||||
call.set_target_temperature(this->target_temperature_.optional_value(x...));
|
call.set_target_temperature(this->target_temperature_.optional_value(x...));
|
||||||
|
@ -30,7 +31,6 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
Climate *climate_;
|
Climate *climate_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ template<typename... Ts> class OpenAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit OpenAction(Cover *cover) : cover_(cover) {}
|
explicit OpenAction(Cover *cover) : cover_(cover) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->cover_->open(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->cover_->open(); }
|
||||||
|
|
||||||
Cover *cover_;
|
Cover *cover_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ template<typename... Ts> class CloseAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit CloseAction(Cover *cover) : cover_(cover) {}
|
explicit CloseAction(Cover *cover) : cover_(cover) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->cover_->close(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->cover_->close(); }
|
||||||
|
|
||||||
Cover *cover_;
|
Cover *cover_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ template<typename... Ts> class StopAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit StopAction(Cover *cover) : cover_(cover) {}
|
explicit StopAction(Cover *cover) : cover_(cover) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->cover_->stop(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->cover_->stop(); }
|
||||||
|
|
||||||
Cover *cover_;
|
Cover *cover_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,7 +41,12 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit ControlAction(Cover *cover) : cover_(cover) {}
|
explicit ControlAction(Cover *cover) : cover_(cover) {}
|
||||||
|
|
||||||
void play(Ts... x) override {
|
TEMPLATABLE_VALUE(bool, stop)
|
||||||
|
TEMPLATABLE_VALUE(float, position)
|
||||||
|
TEMPLATABLE_VALUE(float, tilt)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->cover_->make_call();
|
auto call = this->cover_->make_call();
|
||||||
if (this->stop_.has_value())
|
if (this->stop_.has_value())
|
||||||
call.set_stop(this->stop_.value(x...));
|
call.set_stop(this->stop_.value(x...));
|
||||||
|
@ -52,18 +57,18 @@ template<typename... Ts> class ControlAction : public Action<Ts...> {
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(bool, stop)
|
|
||||||
TEMPLATABLE_VALUE(float, position)
|
|
||||||
TEMPLATABLE_VALUE(float, tilt)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Cover *cover_;
|
Cover *cover_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
|
template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
CoverPublishAction(Cover *cover) : cover_(cover) {}
|
CoverPublishAction(Cover *cover) : cover_(cover) {}
|
||||||
void play(Ts... x) override {
|
TEMPLATABLE_VALUE(float, position)
|
||||||
|
TEMPLATABLE_VALUE(float, tilt)
|
||||||
|
TEMPLATABLE_VALUE(CoverOperation, current_operation)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
if (this->position_.has_value())
|
if (this->position_.has_value())
|
||||||
this->cover_->position = this->position_.value(x...);
|
this->cover_->position = this->position_.value(x...);
|
||||||
if (this->tilt_.has_value())
|
if (this->tilt_.has_value())
|
||||||
|
@ -73,11 +78,6 @@ template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
|
||||||
this->cover_->publish_state();
|
this->cover_->publish_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(float, position)
|
|
||||||
TEMPLATABLE_VALUE(float, tilt)
|
|
||||||
TEMPLATABLE_VALUE(CoverOperation, current_operation)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Cover *cover_;
|
Cover *cover_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,9 @@ template<typename... Ts> class EnterDeepSleepAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
EnterDeepSleepAction(DeepSleepComponent *deep_sleep) : deep_sleep_(deep_sleep) {}
|
EnterDeepSleepAction(DeepSleepComponent *deep_sleep) : deep_sleep_(deep_sleep) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->deep_sleep_->begin_sleep(true); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->deep_sleep_->begin_sleep(true); }
|
||||||
|
|
||||||
DeepSleepComponent *deep_sleep_;
|
DeepSleepComponent *deep_sleep_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ template<typename... Ts> class PreventDeepSleepAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
PreventDeepSleepAction(DeepSleepComponent *deep_sleep) : deep_sleep_(deep_sleep) {}
|
PreventDeepSleepAction(DeepSleepComponent *deep_sleep) : deep_sleep_(deep_sleep) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->deep_sleep_->prevent_deep_sleep(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->deep_sleep_->prevent_deep_sleep(); }
|
||||||
|
|
||||||
DeepSleepComponent *deep_sleep_;
|
DeepSleepComponent *deep_sleep_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,8 @@ class DFPlayer : public uart::UARTDevice, public Component {
|
||||||
|
|
||||||
#define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \
|
#define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \
|
||||||
template<typename... Ts> class ACTION_CLASS : public Action<Ts...>, public Parented<DFPlayer> { \
|
template<typename... Ts> class ACTION_CLASS : public Action<Ts...>, public Parented<DFPlayer> { \
|
||||||
public: \
|
protected: \
|
||||||
void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \
|
void play_(Ts... x) override { this->parent_->ACTION_METHOD(); } \
|
||||||
};
|
};
|
||||||
|
|
||||||
DFPLAYER_SIMPLE_ACTION(NextAction, next)
|
DFPLAYER_SIMPLE_ACTION(NextAction, next)
|
||||||
|
@ -115,7 +115,9 @@ template<typename... Ts> class PlayFileAction : public Action<Ts...>, public Par
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint16_t, file)
|
TEMPLATABLE_VALUE(uint16_t, file)
|
||||||
TEMPLATABLE_VALUE(boolean, loop)
|
TEMPLATABLE_VALUE(boolean, loop)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto file = this->file_.value(x...);
|
auto file = this->file_.value(x...);
|
||||||
auto loop = this->loop_.value(x...);
|
auto loop = this->loop_.value(x...);
|
||||||
if (loop) {
|
if (loop) {
|
||||||
|
@ -131,7 +133,9 @@ template<typename... Ts> class PlayFolderAction : public Action<Ts...>, public P
|
||||||
TEMPLATABLE_VALUE(uint16_t, folder)
|
TEMPLATABLE_VALUE(uint16_t, folder)
|
||||||
TEMPLATABLE_VALUE(uint16_t, file)
|
TEMPLATABLE_VALUE(uint16_t, file)
|
||||||
TEMPLATABLE_VALUE(boolean, loop)
|
TEMPLATABLE_VALUE(boolean, loop)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto folder = this->folder_.value(x...);
|
auto folder = this->folder_.value(x...);
|
||||||
auto file = this->file_.value(x...);
|
auto file = this->file_.value(x...);
|
||||||
auto loop = this->loop_.value(x...);
|
auto loop = this->loop_.value(x...);
|
||||||
|
@ -146,7 +150,9 @@ template<typename... Ts> class PlayFolderAction : public Action<Ts...>, public P
|
||||||
template<typename... Ts> class SetDeviceAction : public Action<Ts...>, public Parented<DFPlayer> {
|
template<typename... Ts> class SetDeviceAction : public Action<Ts...>, public Parented<DFPlayer> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(Device, device)
|
TEMPLATABLE_VALUE(Device, device)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto device = this->device_.value(x...);
|
auto device = this->device_.value(x...);
|
||||||
this->parent_->set_device(device);
|
this->parent_->set_device(device);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +161,9 @@ template<typename... Ts> class SetDeviceAction : public Action<Ts...>, public Pa
|
||||||
template<typename... Ts> class SetVolumeAction : public Action<Ts...>, public Parented<DFPlayer> {
|
template<typename... Ts> class SetVolumeAction : public Action<Ts...>, public Parented<DFPlayer> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint8_t, volume)
|
TEMPLATABLE_VALUE(uint8_t, volume)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto volume = this->volume_.value(x...);
|
auto volume = this->volume_.value(x...);
|
||||||
this->parent_->set_volume(volume);
|
this->parent_->set_volume(volume);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +172,9 @@ template<typename... Ts> class SetVolumeAction : public Action<Ts...>, public Pa
|
||||||
template<typename... Ts> class SetEqAction : public Action<Ts...>, public Parented<DFPlayer> {
|
template<typename... Ts> class SetEqAction : public Action<Ts...>, public Parented<DFPlayer> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(EqPreset, eq)
|
TEMPLATABLE_VALUE(EqPreset, eq)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto eq = this->eq_.value(x...);
|
auto eq = this->eq_.value(x...);
|
||||||
this->parent_->set_eq(eq);
|
this->parent_->set_eq(eq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,9 @@ class Image {
|
||||||
template<typename... Ts> class DisplayPageShowAction : public Action<Ts...> {
|
template<typename... Ts> class DisplayPageShowAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(DisplayPage *, page)
|
TEMPLATABLE_VALUE(DisplayPage *, page)
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto *page = this->page_.value(x...);
|
auto *page = this->page_.value(x...);
|
||||||
if (page != nullptr) {
|
if (page != nullptr) {
|
||||||
page->show();
|
page->show();
|
||||||
|
@ -402,18 +404,20 @@ template<typename... Ts> class DisplayPageShowAction : public Action<Ts...> {
|
||||||
template<typename... Ts> class DisplayPageShowNextAction : public Action<Ts...> {
|
template<typename... Ts> class DisplayPageShowNextAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
DisplayPageShowNextAction(DisplayBuffer *buffer) : buffer_(buffer) {}
|
DisplayPageShowNextAction(DisplayBuffer *buffer) : buffer_(buffer) {}
|
||||||
void play(Ts... x) override { this->buffer_->show_next_page(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->buffer_->show_next_page(); }
|
||||||
|
|
||||||
DisplayBuffer *buffer_;
|
DisplayBuffer *buffer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class DisplayPageShowPrevAction : public Action<Ts...> {
|
template<typename... Ts> class DisplayPageShowPrevAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
DisplayPageShowPrevAction(DisplayBuffer *buffer) : buffer_(buffer) {}
|
DisplayPageShowPrevAction(DisplayBuffer *buffer) : buffer_(buffer) {}
|
||||||
void play(Ts... x) override { this->buffer_->show_prev_page(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->buffer_->show_prev_page(); }
|
||||||
|
|
||||||
DisplayBuffer *buffer_;
|
DisplayBuffer *buffer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
|
||||||
SetFrequencyAction(ESP8266PWM *parent) : parent_(parent) {}
|
SetFrequencyAction(ESP8266PWM *parent) : parent_(parent) {}
|
||||||
TEMPLATABLE_VALUE(float, frequency);
|
TEMPLATABLE_VALUE(float, frequency);
|
||||||
|
|
||||||
void play(Ts... x) {
|
protected:
|
||||||
|
void play_(Ts... x) {
|
||||||
float freq = this->frequency_.value(x...);
|
float freq = this->frequency_.value(x...);
|
||||||
this->parent_->update_frequency(freq);
|
this->parent_->update_frequency(freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
ESP8266PWM *parent_;
|
ESP8266PWM *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ template<typename... Ts> class TurnOnAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(bool, oscillating)
|
TEMPLATABLE_VALUE(bool, oscillating)
|
||||||
TEMPLATABLE_VALUE(FanSpeed, speed)
|
TEMPLATABLE_VALUE(FanSpeed, speed)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->state_->turn_on();
|
auto call = this->state_->turn_on();
|
||||||
if (this->oscillating_.has_value()) {
|
if (this->oscillating_.has_value()) {
|
||||||
call.set_oscillating(this->oscillating_.value(x...));
|
call.set_oscillating(this->oscillating_.value(x...));
|
||||||
|
@ -25,7 +26,6 @@ template<typename... Ts> class TurnOnAction : public Action<Ts...> {
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
FanState *state_;
|
FanState *state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ template<typename... Ts> class TurnOffAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit TurnOffAction(FanState *state) : state_(state) {}
|
explicit TurnOffAction(FanState *state) : state_(state) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->state_->turn_off().perform(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->state_->turn_off().perform(); }
|
||||||
|
|
||||||
FanState *state_;
|
FanState *state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit ToggleAction(FanState *state) : state_(state) {}
|
explicit ToggleAction(FanState *state) : state_(state) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->state_->toggle().perform(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->state_->toggle().perform(); }
|
||||||
|
|
||||||
FanState *state_;
|
FanState *state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,9 @@ template<class C, typename... Ts> class GlobalVarSetAction : public Action<Ts...
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(T, value);
|
TEMPLATABLE_VALUE(T, value);
|
||||||
|
|
||||||
void play(Ts... x) override { this->parent_->value() = this->value_.value(x...); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->parent_->value() = this->value_.value(x...); }
|
||||||
|
|
||||||
C *parent_;
|
C *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||||
|
|
||||||
void set_json(std::function<void(Ts..., JsonObject &)> json_func) { this->json_func_ = json_func; }
|
void set_json(std::function<void(Ts..., JsonObject &)> json_func) { this->json_func_ = json_func; }
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
this->parent_->set_url(this->url_.value(x...));
|
this->parent_->set_url(this->url_.value(x...));
|
||||||
this->parent_->set_method(this->method_.value(x...));
|
this->parent_->set_method(this->method_.value(x...));
|
||||||
if (this->body_.has_value()) {
|
if (this->body_.has_value()) {
|
||||||
|
@ -106,7 +107,6 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
||||||
this->parent_->close();
|
this->parent_->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
void encode_json_(Ts... x, JsonObject &root) {
|
void encode_json_(Ts... x, JsonObject &root) {
|
||||||
for (const auto &item : this->json_) {
|
for (const auto &item : this->json_) {
|
||||||
auto val = item.second;
|
auto val = item.second;
|
||||||
|
|
|
@ -76,9 +76,9 @@ template<typename... Ts> class ResetAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit ResetAction(IntegrationSensor *parent) : parent_(parent) {}
|
explicit ResetAction(IntegrationSensor *parent) : parent_(parent) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->parent_->reset(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->parent_->reset(); }
|
||||||
|
|
||||||
IntegrationSensor *parent_;
|
IntegrationSensor *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,12 +43,12 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
|
||||||
SetFrequencyAction(LEDCOutput *parent) : parent_(parent) {}
|
SetFrequencyAction(LEDCOutput *parent) : parent_(parent) {}
|
||||||
TEMPLATABLE_VALUE(float, frequency);
|
TEMPLATABLE_VALUE(float, frequency);
|
||||||
|
|
||||||
void play(Ts... x) {
|
protected:
|
||||||
|
void play_(Ts... x) {
|
||||||
float freq = this->frequency_.value(x...);
|
float freq = this->frequency_.value(x...);
|
||||||
this->parent_->apply_frequency(freq);
|
this->parent_->apply_frequency(freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
LEDCOutput *parent_;
|
LEDCOutput *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(uint32_t, transition_length)
|
TEMPLATABLE_VALUE(uint32_t, transition_length)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->state_->toggle();
|
auto call = this->state_->toggle();
|
||||||
call.set_transition_length(this->transition_length_.optional_value(x...));
|
call.set_transition_length(this->transition_length_.optional_value(x...));
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
LightState *state_;
|
LightState *state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ template<typename... Ts> class LightControlAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(float, color_temperature)
|
TEMPLATABLE_VALUE(float, color_temperature)
|
||||||
TEMPLATABLE_VALUE(std::string, effect)
|
TEMPLATABLE_VALUE(std::string, effect)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->parent_->make_call();
|
auto call = this->parent_->make_call();
|
||||||
call.set_state(this->state_.optional_value(x...));
|
call.set_state(this->state_.optional_value(x...));
|
||||||
call.set_brightness(this->brightness_.optional_value(x...));
|
call.set_brightness(this->brightness_.optional_value(x...));
|
||||||
|
@ -53,7 +54,6 @@ template<typename... Ts> class LightControlAction : public Action<Ts...> {
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
LightState *parent_;
|
LightState *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,7 +64,8 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(float, relative_brightness)
|
TEMPLATABLE_VALUE(float, relative_brightness)
|
||||||
TEMPLATABLE_VALUE(uint32_t, transition_length)
|
TEMPLATABLE_VALUE(uint32_t, transition_length)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->parent_->make_call();
|
auto call = this->parent_->make_call();
|
||||||
float rel = this->relative_brightness_.value(x...);
|
float rel = this->relative_brightness_.value(x...);
|
||||||
float cur;
|
float cur;
|
||||||
|
@ -77,7 +78,6 @@ template<typename... Ts> class DimRelativeAction : public Action<Ts...> {
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
LightState *parent_;
|
LightState *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ template<typename... Ts> class AddressableSet : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(uint8_t, blue)
|
TEMPLATABLE_VALUE(uint8_t, blue)
|
||||||
TEMPLATABLE_VALUE(uint8_t, white)
|
TEMPLATABLE_VALUE(uint8_t, white)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto *out = (AddressableLight *) this->parent_->get_output();
|
auto *out = (AddressableLight *) this->parent_->get_output();
|
||||||
int32_t range_from = this->range_from_.value_or(x..., 0);
|
int32_t range_from = this->range_from_.value_or(x..., 0);
|
||||||
int32_t range_to = this->range_to_.value_or(x..., out->size() - 1) + 1;
|
int32_t range_to = this->range_to_.value_or(x..., out->size() - 1) + 1;
|
||||||
|
@ -159,7 +160,6 @@ template<typename... Ts> class AddressableSet : public Action<Ts...> {
|
||||||
out->schedule_show();
|
out->schedule_show();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
LightState *parent_;
|
LightState *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,27 +37,30 @@ class MHZ19Component : public PollingComponent, public uart::UARTDevice {
|
||||||
template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
|
template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
||||||
void play(Ts... x) override { this->mhz19_->calibrate_zero(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->mhz19_->calibrate_zero(); }
|
||||||
|
|
||||||
MHZ19Component *mhz19_;
|
MHZ19Component *mhz19_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
|
template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
||||||
void play(Ts... x) override { this->mhz19_->abc_enable(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->mhz19_->abc_enable(); }
|
||||||
|
|
||||||
MHZ19Component *mhz19_;
|
MHZ19Component *mhz19_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
|
template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
|
||||||
void play(Ts... x) override { this->mhz19_->abc_disable(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->mhz19_->abc_disable(); }
|
||||||
|
|
||||||
MHZ19Component *mhz19_;
|
MHZ19Component *mhz19_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -299,12 +299,12 @@ template<typename... Ts> class MQTTPublishAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(uint8_t, qos)
|
TEMPLATABLE_VALUE(uint8_t, qos)
|
||||||
TEMPLATABLE_VALUE(bool, retain)
|
TEMPLATABLE_VALUE(bool, retain)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
this->parent_->publish(this->topic_.value(x...), this->payload_.value(x...), this->qos_.value(x...),
|
this->parent_->publish(this->topic_.value(x...), this->payload_.value(x...), this->qos_.value(x...),
|
||||||
this->retain_.value(x...));
|
this->retain_.value(x...));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
MQTTClientComponent *parent_;
|
MQTTClientComponent *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -316,15 +316,15 @@ template<typename... Ts> class MQTTPublishJsonAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(bool, retain)
|
TEMPLATABLE_VALUE(bool, retain)
|
||||||
|
|
||||||
void set_payload(std::function<void(Ts..., JsonObject &)> payload) { this->payload_ = payload; }
|
void set_payload(std::function<void(Ts..., JsonObject &)> payload) { this->payload_ = payload; }
|
||||||
void play(Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto f = std::bind(&MQTTPublishJsonAction<Ts...>::encode_, this, x..., std::placeholders::_1);
|
auto f = std::bind(&MQTTPublishJsonAction<Ts...>::encode_, this, x..., std::placeholders::_1);
|
||||||
auto topic = this->topic_.value(x...);
|
auto topic = this->topic_.value(x...);
|
||||||
auto qos = this->qos_.value(x...);
|
auto qos = this->qos_.value(x...);
|
||||||
auto retain = this->retain_.value(x...);
|
auto retain = this->retain_.value(x...);
|
||||||
this->parent_->publish_json(topic, f, qos, retain);
|
this->parent_->publish_json(topic, f, qos, retain);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
void encode_(Ts... x, JsonObject &root) { this->payload_(x..., root); }
|
void encode_(Ts... x, JsonObject &root) { this->payload_(x..., root); }
|
||||||
std::function<void(Ts..., JsonObject &)> payload_;
|
std::function<void(Ts..., JsonObject &)> payload_;
|
||||||
MQTTClientComponent *parent_;
|
MQTTClientComponent *parent_;
|
||||||
|
|
|
@ -12,9 +12,9 @@ template<typename... Ts> class TurnOffAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
TurnOffAction(BinaryOutput *output) : output_(output) {}
|
TurnOffAction(BinaryOutput *output) : output_(output) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->output_->turn_off(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->output_->turn_off(); }
|
||||||
|
|
||||||
BinaryOutput *output_;
|
BinaryOutput *output_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ template<typename... Ts> class TurnOnAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
TurnOnAction(BinaryOutput *output) : output_(output) {}
|
TurnOnAction(BinaryOutput *output) : output_(output) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->output_->turn_on(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->output_->turn_on(); }
|
||||||
|
|
||||||
BinaryOutput *output_;
|
BinaryOutput *output_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +33,10 @@ template<typename... Ts> class SetLevelAction : public Action<Ts...> {
|
||||||
SetLevelAction(FloatOutput *output) : output_(output) {}
|
SetLevelAction(FloatOutput *output) : output_(output) {}
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(float, level)
|
TEMPLATABLE_VALUE(float, level)
|
||||||
void play(Ts... x) override { this->output_->set_level(this->level_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->output_->set_level(this->level_.value(x...)); }
|
||||||
|
|
||||||
FloatOutput *output_;
|
FloatOutput *output_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,12 @@ template<typename... Ts> class PIDAutotuneAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
PIDAutotuneAction(PIDClimate *parent) : parent_(parent) {}
|
PIDAutotuneAction(PIDClimate *parent) : parent_(parent) {}
|
||||||
|
|
||||||
void play(Ts... x) {
|
void set_noiseband(float noiseband) { noiseband_ = noiseband; }
|
||||||
|
void set_positive_output(float positive_output) { positive_output_ = positive_output; }
|
||||||
|
void set_negative_output(float negative_output) { negative_output_ = negative_output; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) {
|
||||||
auto tuner = make_unique<PIDAutotuner>();
|
auto tuner = make_unique<PIDAutotuner>();
|
||||||
tuner->set_noiseband(this->noiseband_);
|
tuner->set_noiseband(this->noiseband_);
|
||||||
tuner->set_output_negative(this->negative_output_);
|
tuner->set_output_negative(this->negative_output_);
|
||||||
|
@ -79,11 +84,6 @@ template<typename... Ts> class PIDAutotuneAction : public Action<Ts...> {
|
||||||
this->parent_->start_autotune(std::move(tuner));
|
this->parent_->start_autotune(std::move(tuner));
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_noiseband(float noiseband) { noiseband_ = noiseband; }
|
|
||||||
void set_positive_output(float positive_output) { positive_output_ = positive_output; }
|
|
||||||
void set_negative_output(float negative_output) { negative_output_ = negative_output; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float noiseband_;
|
float noiseband_;
|
||||||
float positive_output_;
|
float positive_output_;
|
||||||
float negative_output_;
|
float negative_output_;
|
||||||
|
|
|
@ -23,7 +23,9 @@ DECLARE_REMOTE_PROTOCOL(JVC)
|
||||||
template<typename... Ts> class JVCAction : public RemoteTransmitterActionBase<Ts...> {
|
template<typename... Ts> class JVCAction : public RemoteTransmitterActionBase<Ts...> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint32_t, data)
|
TEMPLATABLE_VALUE(uint32_t, data)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
JVCData data{};
|
JVCData data{};
|
||||||
data.data = this->data_.value(x...);
|
data.data = this->data_.value(x...);
|
||||||
JVCProtocol().encode(dst, data);
|
JVCProtocol().encode(dst, data);
|
||||||
|
|
|
@ -26,7 +26,9 @@ template<typename... Ts> class LGAction : public RemoteTransmitterActionBase<Ts.
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint32_t, data)
|
TEMPLATABLE_VALUE(uint32_t, data)
|
||||||
TEMPLATABLE_VALUE(uint8_t, nbits)
|
TEMPLATABLE_VALUE(uint8_t, nbits)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
LGData data{};
|
LGData data{};
|
||||||
data.data = this->data_.value(x...);
|
data.data = this->data_.value(x...);
|
||||||
data.nbits = this->nbits_.value(x...);
|
data.nbits = this->nbits_.value(x...);
|
||||||
|
|
|
@ -25,7 +25,9 @@ template<typename... Ts> class NECAction : public RemoteTransmitterActionBase<Ts
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint16_t, address)
|
TEMPLATABLE_VALUE(uint16_t, address)
|
||||||
TEMPLATABLE_VALUE(uint16_t, command)
|
TEMPLATABLE_VALUE(uint16_t, command)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
NECData data{};
|
NECData data{};
|
||||||
data.address = this->address_.value(x...);
|
data.address = this->address_.value(x...);
|
||||||
data.command = this->command_.value(x...);
|
data.command = this->command_.value(x...);
|
||||||
|
|
|
@ -26,7 +26,9 @@ template<typename... Ts> class PanasonicAction : public RemoteTransmitterActionB
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint16_t, address)
|
TEMPLATABLE_VALUE(uint16_t, address)
|
||||||
TEMPLATABLE_VALUE(uint32_t, command)
|
TEMPLATABLE_VALUE(uint32_t, command)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
PanasonicData data{};
|
PanasonicData data{};
|
||||||
data.address = this->address_.value(x...);
|
data.address = this->address_.value(x...);
|
||||||
data.command = this->command_.value(x...);
|
data.command = this->command_.value(x...);
|
||||||
|
|
|
@ -25,7 +25,9 @@ template<typename... Ts> class PioneerAction : public RemoteTransmitterActionBas
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint16_t, rc_code_1)
|
TEMPLATABLE_VALUE(uint16_t, rc_code_1)
|
||||||
TEMPLATABLE_VALUE(uint16_t, rc_code_2)
|
TEMPLATABLE_VALUE(uint16_t, rc_code_2)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
PioneerData data{};
|
PioneerData data{};
|
||||||
data.rc_code_1 = this->rc_code_1_.value(x...);
|
data.rc_code_1 = this->rc_code_1_.value(x...);
|
||||||
data.rc_code_2 = this->rc_code_2_.value(x...);
|
data.rc_code_2 = this->rc_code_2_.value(x...);
|
||||||
|
|
|
@ -46,7 +46,8 @@ template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts
|
||||||
}
|
}
|
||||||
TEMPLATABLE_VALUE(uint32_t, carrier_frequency);
|
TEMPLATABLE_VALUE(uint32_t, carrier_frequency);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
if (this->code_static_ != nullptr) {
|
if (this->code_static_ != nullptr) {
|
||||||
for (size_t i = 0; i < this->code_static_len_; i++) {
|
for (size_t i = 0; i < this->code_static_len_; i++) {
|
||||||
auto val = this->code_static_[i];
|
auto val = this->code_static_[i];
|
||||||
|
@ -61,7 +62,6 @@ template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts
|
||||||
dst->set_carrier_frequency(this->carrier_frequency_.value(x...));
|
dst->set_carrier_frequency(this->carrier_frequency_.value(x...));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
std::function<std::vector<int32_t>(Ts...)> code_func_{};
|
std::function<std::vector<int32_t>(Ts...)> code_func_{};
|
||||||
const int32_t *code_static_{nullptr};
|
const int32_t *code_static_{nullptr};
|
||||||
int32_t code_static_len_{0};
|
int32_t code_static_len_{0};
|
||||||
|
|
|
@ -26,7 +26,9 @@ template<typename... Ts> class RC5Action : public RemoteTransmitterActionBase<Ts
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint8_t, address)
|
TEMPLATABLE_VALUE(uint8_t, address)
|
||||||
TEMPLATABLE_VALUE(uint8_t, command)
|
TEMPLATABLE_VALUE(uint8_t, command)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
RC5Data data{};
|
RC5Data data{};
|
||||||
data.address = this->address_.value(x...);
|
data.address = this->address_.value(x...);
|
||||||
data.command = this->command_.value(x...);
|
data.command = this->command_.value(x...);
|
||||||
|
|
|
@ -71,7 +71,8 @@ template<typename... Ts> class RCSwitchRawAction : public RemoteTransmitterActio
|
||||||
TEMPLATABLE_VALUE(RCSwitchBase, protocol);
|
TEMPLATABLE_VALUE(RCSwitchBase, protocol);
|
||||||
TEMPLATABLE_VALUE(std::string, code);
|
TEMPLATABLE_VALUE(std::string, code);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
auto code = this->code_.value(x...);
|
auto code = this->code_.value(x...);
|
||||||
uint64_t the_code = decode_binary_string(code);
|
uint64_t the_code = decode_binary_string(code);
|
||||||
uint8_t nbits = code.size();
|
uint8_t nbits = code.size();
|
||||||
|
@ -88,7 +89,8 @@ template<typename... Ts> class RCSwitchTypeAAction : public RemoteTransmitterAct
|
||||||
TEMPLATABLE_VALUE(std::string, device);
|
TEMPLATABLE_VALUE(std::string, device);
|
||||||
TEMPLATABLE_VALUE(bool, state);
|
TEMPLATABLE_VALUE(bool, state);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
auto group = this->group_.value(x...);
|
auto group = this->group_.value(x...);
|
||||||
auto device = this->device_.value(x...);
|
auto device = this->device_.value(x...);
|
||||||
auto state = this->state_.value(x...);
|
auto state = this->state_.value(x...);
|
||||||
|
@ -111,7 +113,8 @@ template<typename... Ts> class RCSwitchTypeBAction : public RemoteTransmitterAct
|
||||||
TEMPLATABLE_VALUE(uint8_t, channel);
|
TEMPLATABLE_VALUE(uint8_t, channel);
|
||||||
TEMPLATABLE_VALUE(bool, state);
|
TEMPLATABLE_VALUE(bool, state);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
auto address = this->address_.value(x...);
|
auto address = this->address_.value(x...);
|
||||||
auto channel = this->channel_.value(x...);
|
auto channel = this->channel_.value(x...);
|
||||||
auto state = this->state_.value(x...);
|
auto state = this->state_.value(x...);
|
||||||
|
@ -133,7 +136,8 @@ template<typename... Ts> class RCSwitchTypeCAction : public RemoteTransmitterAct
|
||||||
TEMPLATABLE_VALUE(uint8_t, device);
|
TEMPLATABLE_VALUE(uint8_t, device);
|
||||||
TEMPLATABLE_VALUE(bool, state);
|
TEMPLATABLE_VALUE(bool, state);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
auto family = this->family_.value(x...);
|
auto family = this->family_.value(x...);
|
||||||
auto group = this->group_.value(x...);
|
auto group = this->group_.value(x...);
|
||||||
auto device = this->device_.value(x...);
|
auto device = this->device_.value(x...);
|
||||||
|
@ -156,7 +160,8 @@ template<typename... Ts> class RCSwitchTypeDAction : public RemoteTransmitterAct
|
||||||
TEMPLATABLE_VALUE(uint8_t, device);
|
TEMPLATABLE_VALUE(uint8_t, device);
|
||||||
TEMPLATABLE_VALUE(bool, state);
|
TEMPLATABLE_VALUE(bool, state);
|
||||||
|
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
auto group = this->group_.value(x...);
|
auto group = this->group_.value(x...);
|
||||||
auto device = this->device_.value(x...);
|
auto device = this->device_.value(x...);
|
||||||
auto state = this->state_.value(x...);
|
auto state = this->state_.value(x...);
|
||||||
|
|
|
@ -323,20 +323,20 @@ template<typename... Ts> class RemoteTransmitterActionBase : public Action<Ts...
|
||||||
public:
|
public:
|
||||||
void set_parent(RemoteTransmitterBase *parent) { this->parent_ = parent; }
|
void set_parent(RemoteTransmitterBase *parent) { this->parent_ = parent; }
|
||||||
|
|
||||||
void play(Ts... x) override {
|
TEMPLATABLE_VALUE(uint32_t, send_times);
|
||||||
|
TEMPLATABLE_VALUE(uint32_t, send_wait);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void encode_(RemoteTransmitData *dst, Ts... x) = 0;
|
||||||
|
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto call = this->parent_->transmit();
|
auto call = this->parent_->transmit();
|
||||||
this->encode(call.get_data(), x...);
|
this->encode_(call.get_data(), x...);
|
||||||
call.set_send_times(this->send_times_.value_or(x..., 1));
|
call.set_send_times(this->send_times_.value_or(x..., 1));
|
||||||
call.set_send_wait(this->send_wait_.value_or(x..., 0));
|
call.set_send_wait(this->send_wait_.value_or(x..., 0));
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void encode(RemoteTransmitData *dst, Ts... x) = 0;
|
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(uint32_t, send_times);
|
|
||||||
TEMPLATABLE_VALUE(uint32_t, send_wait);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
RemoteTransmitterBase *parent_{};
|
RemoteTransmitterBase *parent_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,9 @@ DECLARE_REMOTE_PROTOCOL(Samsung)
|
||||||
template<typename... Ts> class SamsungAction : public RemoteTransmitterActionBase<Ts...> {
|
template<typename... Ts> class SamsungAction : public RemoteTransmitterActionBase<Ts...> {
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint32_t, data)
|
TEMPLATABLE_VALUE(uint32_t, data)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
SamsungData data{};
|
SamsungData data{};
|
||||||
data.data = this->data_.value(x...);
|
data.data = this->data_.value(x...);
|
||||||
SamsungProtocol().encode(dst, data);
|
SamsungProtocol().encode(dst, data);
|
||||||
|
|
|
@ -26,7 +26,9 @@ template<typename... Ts> class SonyAction : public RemoteTransmitterActionBase<T
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint32_t, data)
|
TEMPLATABLE_VALUE(uint32_t, data)
|
||||||
TEMPLATABLE_VALUE(uint8_t, nbits)
|
TEMPLATABLE_VALUE(uint8_t, nbits)
|
||||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
||||||
|
protected:
|
||||||
|
void encode_(RemoteTransmitData *dst, Ts... x) override {
|
||||||
SonyData data{};
|
SonyData data{};
|
||||||
data.data = this->data_.value(x...);
|
data.data = this->data_.value(x...);
|
||||||
data.nbits = this->nbits_.value(x...);
|
data.nbits = this->nbits_.value(x...);
|
||||||
|
|
|
@ -68,7 +68,8 @@ template<typename... Ts> class RFBridgeSendCodeAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(uint16_t, high)
|
TEMPLATABLE_VALUE(uint16_t, high)
|
||||||
TEMPLATABLE_VALUE(uint32_t, code)
|
TEMPLATABLE_VALUE(uint32_t, code)
|
||||||
|
|
||||||
void play(Ts... x) {
|
protected:
|
||||||
|
void play_(Ts... x) {
|
||||||
RFBridgeData data{};
|
RFBridgeData data{};
|
||||||
data.sync = this->sync_.value(x...);
|
data.sync = this->sync_.value(x...);
|
||||||
data.low = this->low_.value(x...);
|
data.low = this->low_.value(x...);
|
||||||
|
@ -77,7 +78,6 @@ template<typename... Ts> class RFBridgeSendCodeAction : public Action<Ts...> {
|
||||||
this->parent_->send_code(data);
|
this->parent_->send_code(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
RFBridgeComponent *parent_;
|
RFBridgeComponent *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ template<typename... Ts> class RFBridgeLearnAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
RFBridgeLearnAction(RFBridgeComponent *parent) : parent_(parent) {}
|
RFBridgeLearnAction(RFBridgeComponent *parent) : parent_(parent) {}
|
||||||
|
|
||||||
void play(Ts... x) { this->parent_->learn(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) { this->parent_->learn(); }
|
||||||
|
|
||||||
RFBridgeComponent *parent_;
|
RFBridgeComponent *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,9 @@ template<typename... Ts> class RotaryEncoderSetValueAction : public Action<Ts...
|
||||||
public:
|
public:
|
||||||
RotaryEncoderSetValueAction(RotaryEncoderSensor *encoder) : encoder_(encoder) {}
|
RotaryEncoderSetValueAction(RotaryEncoderSensor *encoder) : encoder_(encoder) {}
|
||||||
TEMPLATABLE_VALUE(int, value)
|
TEMPLATABLE_VALUE(int, value)
|
||||||
void play(Ts... x) override { this->encoder_->set_value(this->value_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->encoder_->set_value(this->value_.value(x...)); }
|
||||||
RotaryEncoderSensor *encoder_;
|
RotaryEncoderSensor *encoder_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ template<typename... Ts> class ScriptExecuteAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
ScriptExecuteAction(Script *script) : script_(script) {}
|
ScriptExecuteAction(Script *script) : script_(script) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->script_->trigger(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->script_->trigger(); }
|
||||||
|
|
||||||
Script *script_;
|
Script *script_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ template<typename... Ts> class ScriptStopAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
ScriptStopAction(Script *script) : script_(script) {}
|
ScriptStopAction(Script *script) : script_(script) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->script_->stop(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->script_->stop(); }
|
||||||
|
|
||||||
Script *script_;
|
Script *script_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,14 +53,11 @@ template<typename... Ts> class ScriptWaitAction : public Action<Ts...>, public C
|
||||||
public:
|
public:
|
||||||
ScriptWaitAction(Script *script) : script_(script) {}
|
ScriptWaitAction(Script *script) : script_(script) {}
|
||||||
|
|
||||||
void play(Ts... x) override { /* ignore - see play_complex */
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_complex(Ts... x) override {
|
void play_complex(Ts... x) override {
|
||||||
this->num_running_++;
|
this->num_running_++;
|
||||||
// Check if we can continue immediately.
|
// Check if we can continue immediately.
|
||||||
if (!this->script_->is_running()) {
|
if (!this->script_->is_running()) {
|
||||||
this->play_next(x...);
|
this->play_next_(x...);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->var_ = std::make_tuple(x...);
|
this->var_ = std::make_tuple(x...);
|
||||||
|
@ -74,12 +71,15 @@ template<typename... Ts> class ScriptWaitAction : public Action<Ts...>, public C
|
||||||
if (this->script_->is_running())
|
if (this->script_->is_running())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->play_next_tuple(this->var_);
|
this->play_next_tuple_(this->var_);
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { /* ignore - see play_complex */
|
||||||
|
}
|
||||||
|
|
||||||
Script *script_;
|
Script *script_;
|
||||||
std::tuple<Ts...> var_{};
|
std::tuple<Ts...> var_{};
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,9 +25,9 @@ template<typename... Ts> class SensorPublishAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
SensorPublishAction(Sensor *sensor) : sensor_(sensor) {}
|
SensorPublishAction(Sensor *sensor) : sensor_(sensor) {}
|
||||||
TEMPLATABLE_VALUE(float, state)
|
TEMPLATABLE_VALUE(float, state)
|
||||||
void play(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
||||||
Sensor *sensor_;
|
Sensor *sensor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -64,18 +64,18 @@ template<typename... Ts> class ServoWriteAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
ServoWriteAction(Servo *servo) : servo_(servo) {}
|
ServoWriteAction(Servo *servo) : servo_(servo) {}
|
||||||
TEMPLATABLE_VALUE(float, value)
|
TEMPLATABLE_VALUE(float, value)
|
||||||
void play(Ts... x) override { this->servo_->write(this->value_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->servo_->write(this->value_.value(x...)); }
|
||||||
Servo *servo_;
|
Servo *servo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class ServoDetachAction : public Action<Ts...> {
|
template<typename... Ts> class ServoDetachAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
ServoDetachAction(Servo *servo) : servo_(servo) {}
|
ServoDetachAction(Servo *servo) : servo_(servo) {}
|
||||||
void play(Ts... x) override { this->servo_->detach(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->servo_->detach(); }
|
||||||
Servo *servo_;
|
Servo *servo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -78,13 +78,13 @@ template<typename... Ts> class Sim800LSendSmsAction : public Action<Ts...> {
|
||||||
TEMPLATABLE_VALUE(std::string, recipient)
|
TEMPLATABLE_VALUE(std::string, recipient)
|
||||||
TEMPLATABLE_VALUE(std::string, message)
|
TEMPLATABLE_VALUE(std::string, message)
|
||||||
|
|
||||||
void play(Ts... x) {
|
protected:
|
||||||
|
void play_(Ts... x) {
|
||||||
auto recipient = this->recipient_.value(x...);
|
auto recipient = this->recipient_.value(x...);
|
||||||
auto message = this->message_.value(x...);
|
auto message = this->message_.value(x...);
|
||||||
this->parent_->send_sms(recipient, message);
|
this->parent_->send_sms(recipient, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
Sim800LComponent *parent_;
|
Sim800LComponent *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ template<typename... Ts> class SetTargetAction : public Action<Ts...> {
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(int32_t, target)
|
TEMPLATABLE_VALUE(int32_t, target)
|
||||||
|
|
||||||
void play(Ts... x) override { this->parent_->set_target(this->target_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->parent_->set_target(this->target_.value(x...)); }
|
||||||
|
|
||||||
Stepper *parent_;
|
Stepper *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,9 +55,9 @@ template<typename... Ts> class ReportPositionAction : public Action<Ts...> {
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(int32_t, position)
|
TEMPLATABLE_VALUE(int32_t, position)
|
||||||
|
|
||||||
void play(Ts... x) override { this->parent_->report_position(this->position_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->parent_->report_position(this->position_.value(x...)); }
|
||||||
|
|
||||||
Stepper *parent_;
|
Stepper *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,13 +67,13 @@ template<typename... Ts> class SetSpeedAction : public Action<Ts...> {
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(float, speed);
|
TEMPLATABLE_VALUE(float, speed);
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
float speed = this->speed_.value(x...);
|
float speed = this->speed_.value(x...);
|
||||||
this->parent_->set_max_speed(speed);
|
this->parent_->set_max_speed(speed);
|
||||||
this->parent_->on_update_speed();
|
this->parent_->on_update_speed();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
Stepper *parent_;
|
Stepper *parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ template<typename... Ts> class TurnOnAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit TurnOnAction(Switch *a_switch) : switch_(a_switch) {}
|
explicit TurnOnAction(Switch *a_switch) : switch_(a_switch) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->switch_->turn_on(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->switch_->turn_on(); }
|
||||||
|
|
||||||
Switch *switch_;
|
Switch *switch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ template<typename... Ts> class TurnOffAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit TurnOffAction(Switch *a_switch) : switch_(a_switch) {}
|
explicit TurnOffAction(Switch *a_switch) : switch_(a_switch) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->switch_->turn_off(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->switch_->turn_off(); }
|
||||||
|
|
||||||
Switch *switch_;
|
Switch *switch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ template<typename... Ts> class ToggleAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit ToggleAction(Switch *a_switch) : switch_(a_switch) {}
|
explicit ToggleAction(Switch *a_switch) : switch_(a_switch) {}
|
||||||
|
|
||||||
void play(Ts... x) override { this->switch_->toggle(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->switch_->toggle(); }
|
||||||
|
|
||||||
Switch *switch_;
|
Switch *switch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ template<typename... Ts> class SwitchPublishAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
SwitchPublishAction(Switch *a_switch) : switch_(a_switch) {}
|
SwitchPublishAction(Switch *a_switch) : switch_(a_switch) {}
|
||||||
TEMPLATABLE_VALUE(bool, state)
|
TEMPLATABLE_VALUE(bool, state)
|
||||||
void play(Ts... x) override { this->switch_->publish_state(this->state_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->switch_->publish_state(this->state_.value(x...)); }
|
||||||
Switch *switch_;
|
Switch *switch_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ template<typename... Ts> class TextSensorPublishAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {}
|
TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {}
|
||||||
TEMPLATABLE_VALUE(std::string, state)
|
TEMPLATABLE_VALUE(std::string, state)
|
||||||
void play(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
||||||
TextSensor *sensor_;
|
TextSensor *sensor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,8 @@ template<typename... Ts> class SetLevelPercentAction : public Action<Ts...>, pub
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint8_t, level_percent)
|
TEMPLATABLE_VALUE(uint8_t, level_percent)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto level_percent = this->level_percent_.value(x...);
|
auto level_percent = this->level_percent_.value(x...);
|
||||||
this->parent_->set_level_percent(level_percent);
|
this->parent_->set_level_percent(level_percent);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,8 @@ template<typename... Ts> class SetLevelAction : public Action<Ts...>, public Par
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint8_t, level)
|
TEMPLATABLE_VALUE(uint8_t, level)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto level = this->level_.value(x...);
|
auto level = this->level_.value(x...);
|
||||||
this->parent_->set_level(level);
|
this->parent_->set_level(level);
|
||||||
}
|
}
|
||||||
|
@ -63,20 +65,21 @@ template<typename... Ts> class SetBrightnessAction : public Action<Ts...>, publi
|
||||||
public:
|
public:
|
||||||
TEMPLATABLE_VALUE(uint8_t, brightness)
|
TEMPLATABLE_VALUE(uint8_t, brightness)
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
auto brightness = this->brightness_.value(x...);
|
auto brightness = this->brightness_.value(x...);
|
||||||
this->parent_->set_brightness(brightness);
|
this->parent_->set_brightness(brightness);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class TurnOnAction : public Action<Ts...>, public Parented<TM1651Display> {
|
template<typename... Ts> class TurnOnAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||||
public:
|
protected:
|
||||||
void play(Ts... x) override { this->parent_->turn_on(); }
|
void play_(Ts... x) override { this->parent_->turn_on(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class TurnOffAction : public Action<Ts...>, public Parented<TM1651Display> {
|
template<typename... Ts> class TurnOffAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||||
public:
|
protected:
|
||||||
void play(Ts... x) override { this->parent_->turn_off(); }
|
void play_(Ts... x) override { this->parent_->turn_off(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tm1651
|
} // namespace tm1651
|
||||||
|
|
|
@ -17,7 +17,8 @@ template<typename... Ts> class UARTWriteAction : public Action<Ts...>, public Pa
|
||||||
this->static_ = true;
|
this->static_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void play(Ts... x) override {
|
protected:
|
||||||
|
void play_(Ts... x) override {
|
||||||
if (this->static_) {
|
if (this->static_) {
|
||||||
this->parent_->write_array(this->data_static_);
|
this->parent_->write_array(this->data_static_);
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,8 +26,6 @@ template<typename... Ts> class UARTWriteAction : public Action<Ts...>, public Pa
|
||||||
this->parent_->write_array(val);
|
this->parent_->write_array(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
bool static_{false};
|
bool static_{false};
|
||||||
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
|
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
|
||||||
std::vector<uint8_t> data_static_{};
|
std::vector<uint8_t> data_static_{};
|
||||||
|
|
|
@ -75,13 +75,25 @@ template<typename... Ts> class ActionList;
|
||||||
|
|
||||||
template<typename... Ts> class Action {
|
template<typename... Ts> class Action {
|
||||||
public:
|
public:
|
||||||
virtual void play(Ts... x) = 0;
|
|
||||||
virtual void play_complex(Ts... x) {
|
virtual void play_complex(Ts... x) {
|
||||||
this->num_running_++;
|
this->num_running_++;
|
||||||
this->play(x...);
|
this->play_(x...);
|
||||||
this->play_next(x...);
|
this->play_next_(x...);
|
||||||
}
|
}
|
||||||
void play_next(Ts... x) {
|
virtual void stop_complex() {
|
||||||
|
if (num_running_) {
|
||||||
|
this->stop_();
|
||||||
|
this->num_running_ = 0;
|
||||||
|
}
|
||||||
|
this->stop_next_();
|
||||||
|
}
|
||||||
|
virtual bool is_running() { return this->num_running_ > 0 || this->is_running_next_(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend ActionList<Ts...>;
|
||||||
|
|
||||||
|
virtual void play_(Ts... x) = 0;
|
||||||
|
void play_next_(Ts... x) {
|
||||||
if (this->num_running_ > 0) {
|
if (this->num_running_ > 0) {
|
||||||
this->num_running_--;
|
this->num_running_--;
|
||||||
if (this->next_ != nullptr) {
|
if (this->next_ != nullptr) {
|
||||||
|
@ -89,37 +101,26 @@ template<typename... Ts> class Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void stop() {}
|
template<int... S> void play_next_tuple_(const std::tuple<Ts...> &tuple, seq<S...>) {
|
||||||
virtual void stop_complex() {
|
this->play_next_(std::get<S>(tuple)...);
|
||||||
if (num_running_) {
|
|
||||||
this->stop();
|
|
||||||
this->num_running_ = 0;
|
|
||||||
}
|
|
||||||
this->stop_next();
|
|
||||||
}
|
}
|
||||||
void stop_next() {
|
void play_next_tuple_(const std::tuple<Ts...> &tuple) {
|
||||||
|
this->play_next_tuple_(tuple, typename gens<sizeof...(Ts)>::type());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void stop_() {}
|
||||||
|
void stop_next_() {
|
||||||
if (this->next_ != nullptr) {
|
if (this->next_ != nullptr) {
|
||||||
this->next_->stop_complex();
|
this->next_->stop_complex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual bool is_running() { return this->num_running_ > 0 || this->is_running_next(); }
|
|
||||||
bool is_running_next() {
|
bool is_running_next_() {
|
||||||
if (this->next_ == nullptr)
|
if (this->next_ == nullptr)
|
||||||
return false;
|
return false;
|
||||||
return this->next_->is_running();
|
return this->next_->is_running();
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_next_tuple(const std::tuple<Ts...> &tuple) {
|
|
||||||
this->play_next_tuple_(tuple, typename gens<sizeof...(Ts)>::type());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend ActionList<Ts...>;
|
|
||||||
|
|
||||||
template<int... S> void play_next_tuple_(const std::tuple<Ts...> &tuple, seq<S...>) {
|
|
||||||
this->play_next(std::get<S>(tuple)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
Action<Ts...> *next_ = nullptr;
|
Action<Ts...> *next_ = nullptr;
|
||||||
|
|
||||||
int num_running_{0};
|
int num_running_{0};
|
||||||
|
|
|
@ -108,27 +108,29 @@ template<typename... Ts> class DelayAction : public Action<Ts...>, public Compon
|
||||||
|
|
||||||
TEMPLATABLE_VALUE(uint32_t, delay)
|
TEMPLATABLE_VALUE(uint32_t, delay)
|
||||||
|
|
||||||
void stop() override {
|
|
||||||
this->cancel_timeout("");
|
|
||||||
}
|
|
||||||
|
|
||||||
void play(Ts... x) override { /* ignore - see play_complex */
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_complex(Ts... x) override {
|
void play_complex(Ts... x) override {
|
||||||
auto f = std::bind(&Action<Ts...>::play_next, this, x...);
|
auto f = std::bind(&DelayAction<Ts...>::play_next_, this, x...);
|
||||||
this->num_running_++;
|
this->num_running_++;
|
||||||
this->set_timeout(this->delay_.value(x...), f);
|
this->set_timeout(this->delay_.value(x...), f);
|
||||||
}
|
}
|
||||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void play_(Ts... x) override { /* ignore - see play_complex */
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_() override {
|
||||||
|
this->cancel_timeout("");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class LambdaAction : public Action<Ts...> {
|
template<typename... Ts> class LambdaAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit LambdaAction(std::function<void(Ts...)> &&f) : f_(std::move(f)) {}
|
explicit LambdaAction(std::function<void(Ts...)> &&f) : f_(std::move(f)) {}
|
||||||
void play(Ts... x) override { this->f_(x...); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->f_(x...); }
|
||||||
|
|
||||||
std::function<void(Ts...)> f_;
|
std::function<void(Ts...)> f_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,15 +140,12 @@ template<typename... Ts> class IfAction : public Action<Ts...> {
|
||||||
|
|
||||||
void add_then(const std::vector<Action<Ts...> *> &actions) {
|
void add_then(const std::vector<Action<Ts...> *> &actions) {
|
||||||
this->then_.add_actions(actions);
|
this->then_.add_actions(actions);
|
||||||
this->then_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next(x...); }));
|
this->then_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next_(x...); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_else(const std::vector<Action<Ts...> *> &actions) {
|
void add_else(const std::vector<Action<Ts...> *> &actions) {
|
||||||
this->else_.add_actions(actions);
|
this->else_.add_actions(actions);
|
||||||
this->else_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next(x...); }));
|
this->else_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next_(x...); }));
|
||||||
}
|
|
||||||
|
|
||||||
void play(Ts... x) override { /* ignore - see play_complex */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_complex(Ts... x) override {
|
void play_complex(Ts... x) override {
|
||||||
|
@ -154,25 +153,28 @@ template<typename... Ts> class IfAction : public Action<Ts...> {
|
||||||
bool res = this->condition_->check(x...);
|
bool res = this->condition_->check(x...);
|
||||||
if (res) {
|
if (res) {
|
||||||
if (this->then_.empty()) {
|
if (this->then_.empty()) {
|
||||||
this->play_next(x...);
|
this->play_next_(x...);
|
||||||
} else if (this->num_running_ > 0) {
|
} else if (this->num_running_ > 0) {
|
||||||
this->then_.play(x...);
|
this->then_.play(x...);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this->else_.empty()) {
|
if (this->else_.empty()) {
|
||||||
this->play_next(x...);
|
this->play_next_(x...);
|
||||||
} else if (this->num_running_ > 0) {
|
} else if (this->num_running_ > 0) {
|
||||||
this->else_.play(x...);
|
this->else_.play(x...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() override {
|
protected:
|
||||||
|
void play_(Ts... x) override { /* ignore - see play_complex */
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_() override {
|
||||||
this->then_.stop();
|
this->then_.stop();
|
||||||
this->else_.stop();
|
this->else_.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
Condition<Ts...> *condition_;
|
Condition<Ts...> *condition_;
|
||||||
ActionList<Ts...> then_;
|
ActionList<Ts...> then_;
|
||||||
ActionList<Ts...> else_;
|
ActionList<Ts...> else_;
|
||||||
|
@ -192,14 +194,11 @@ template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// condition false, play next
|
// condition false, play next
|
||||||
this->play_next_tuple(this->var_);
|
this->play_next_tuple_(this->var_);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void play(Ts... x) override { /* ignore - see play_complex */
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_complex(Ts... x) override {
|
void play_complex(Ts... x) override {
|
||||||
this->num_running_++;
|
this->num_running_++;
|
||||||
// Store loop parameters
|
// Store loop parameters
|
||||||
|
@ -208,7 +207,7 @@ template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||||
if (!this->condition_->check_tuple(this->var_)) {
|
if (!this->condition_->check_tuple(this->var_)) {
|
||||||
// If new condition check failed, stop loop if running
|
// If new condition check failed, stop loop if running
|
||||||
this->then_.stop();
|
this->then_.stop();
|
||||||
this->play_next_tuple(this->var_);
|
this->play_next_tuple_(this->var_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,9 +216,12 @@ template<typename... Ts> class WhileAction : public Action<Ts...> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() override { this->then_.stop(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { /* ignore - see play_complex */
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_() override { this->then_.stop(); }
|
||||||
|
|
||||||
Condition<Ts...> *condition_;
|
Condition<Ts...> *condition_;
|
||||||
ActionList<Ts...> then_;
|
ActionList<Ts...> then_;
|
||||||
std::tuple<Ts...> var_{};
|
std::tuple<Ts...> var_{};
|
||||||
|
@ -229,15 +231,12 @@ template<typename... Ts> class WaitUntilAction : public Action<Ts...>, public Co
|
||||||
public:
|
public:
|
||||||
WaitUntilAction(Condition<Ts...> *condition) : condition_(condition) {}
|
WaitUntilAction(Condition<Ts...> *condition) : condition_(condition) {}
|
||||||
|
|
||||||
void play(Ts... x) override { /* ignore - see play_complex */
|
|
||||||
}
|
|
||||||
|
|
||||||
void play_complex(Ts... x) override {
|
void play_complex(Ts... x) override {
|
||||||
this->num_running_++;
|
this->num_running_++;
|
||||||
// Check if we can continue immediately.
|
// Check if we can continue immediately.
|
||||||
if (this->condition_->check(x...)) {
|
if (this->condition_->check(x...)) {
|
||||||
if (this->num_running_ > 0) {
|
if (this->num_running_ > 0) {
|
||||||
this->play_next(x...);
|
this->play_next_(x...);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -253,12 +252,15 @@ template<typename... Ts> class WaitUntilAction : public Action<Ts...>, public Co
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->play_next_tuple(this->var_);
|
this->play_next_tuple_(this->var_);
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { /* ignore - see play_complex */
|
||||||
|
}
|
||||||
|
|
||||||
Condition<Ts...> *condition_;
|
Condition<Ts...> *condition_;
|
||||||
std::tuple<Ts...> var_{};
|
std::tuple<Ts...> var_{};
|
||||||
};
|
};
|
||||||
|
@ -266,9 +268,10 @@ template<typename... Ts> class WaitUntilAction : public Action<Ts...>, public Co
|
||||||
template<typename... Ts> class UpdateComponentAction : public Action<Ts...> {
|
template<typename... Ts> class UpdateComponentAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
UpdateComponentAction(PollingComponent *component) : component_(component) {}
|
UpdateComponentAction(PollingComponent *component) : component_(component) {}
|
||||||
void play(Ts... x) override { this->component_->update(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void play_(Ts... x) override { this->component_->update(); }
|
||||||
|
|
||||||
PollingComponent *component_;
|
PollingComponent *component_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue