1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-17 18:52:19 +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:
Andrew Zaborowski
2020-05-01 12:38:34 +02:00
committed by Andrew Zaborowski
parent da390d32f8
commit a62b6548d2
42 changed files with 250 additions and 203 deletions

View File

@@ -104,8 +104,8 @@ class DFPlayer : public uart::UARTDevice, public Component {
#define DFPLAYER_SIMPLE_ACTION(ACTION_CLASS, ACTION_METHOD) \
template<typename... Ts> class ACTION_CLASS : public Action<Ts...>, public Parented<DFPlayer> { \
public: \
void play(Ts... x) override { this->parent_->ACTION_METHOD(); } \
protected: \
void play_(Ts... x) override { this->parent_->ACTION_METHOD(); } \
};
DFPLAYER_SIMPLE_ACTION(NextAction, next)
@@ -115,7 +115,9 @@ template<typename... Ts> class PlayFileAction : public Action<Ts...>, public Par
public:
TEMPLATABLE_VALUE(uint16_t, file)
TEMPLATABLE_VALUE(boolean, loop)
void play(Ts... x) override {
protected:
void play_(Ts... x) override {
auto file = this->file_.value(x...);
auto loop = this->loop_.value(x...);
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, file)
TEMPLATABLE_VALUE(boolean, loop)
void play(Ts... x) override {
protected:
void play_(Ts... x) override {
auto folder = this->folder_.value(x...);
auto file = this->file_.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> {
public:
TEMPLATABLE_VALUE(Device, device)
void play(Ts... x) override {
protected:
void play_(Ts... x) override {
auto device = this->device_.value(x...);
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> {
public:
TEMPLATABLE_VALUE(uint8_t, volume)
void play(Ts... x) override {
protected:
void play_(Ts... x) override {
auto volume = this->volume_.value(x...);
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> {
public:
TEMPLATABLE_VALUE(EqPreset, eq)
void play(Ts... x) override {
protected:
void play_(Ts... x) override {
auto eq = this->eq_.value(x...);
this->parent_->set_eq(eq);
}