mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-22 13:48:29 +02:00
2f07225984
* Move stop/is_running implementation to Action base class Try to fix issue #1105. Until now if an UpdateComponentAction, a LambdaAction, or any action that can contain those inside their "else" or "then" action lists, resulted in a call to script.stop on the script that contains them, the script would continue running, because they didn't implement a stop() method. Basically only the asynchronous ones did: DelayAction, WaitUntilAction and ScriptWaitAction. With this change num_running_ in Action replaces DelayAction::num_running_ and WaitUntilAction::triggered_ to provide the same is_running logic to other actions. * 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. * lint * format Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
40 lines
998 B
C++
40 lines
998 B
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "remote_base.h"
|
|
|
|
namespace esphome {
|
|
namespace remote_base {
|
|
|
|
struct RC5Data {
|
|
uint8_t address;
|
|
uint8_t command;
|
|
|
|
bool operator==(const RC5Data &rhs) const { return address == rhs.address && command == rhs.command; }
|
|
};
|
|
|
|
class RC5Protocol : public RemoteProtocol<RC5Data> {
|
|
public:
|
|
void encode(RemoteTransmitData *dst, const RC5Data &data) override;
|
|
optional<RC5Data> decode(RemoteReceiveData src) override;
|
|
void dump(const RC5Data &data) override;
|
|
};
|
|
|
|
DECLARE_REMOTE_PROTOCOL(RC5)
|
|
|
|
template<typename... Ts> class RC5Action : public RemoteTransmitterActionBase<Ts...> {
|
|
public:
|
|
TEMPLATABLE_VALUE(uint8_t, address)
|
|
TEMPLATABLE_VALUE(uint8_t, command)
|
|
|
|
void encode(RemoteTransmitData *dst, Ts... x) override {
|
|
RC5Data data{};
|
|
data.address = this->address_.value(x...);
|
|
data.command = this->command_.value(x...);
|
|
RC5Protocol().encode(dst, data);
|
|
}
|
|
};
|
|
|
|
} // namespace remote_base
|
|
} // namespace esphome
|