1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-26 20:48:19 +00:00
esphome/esphome/components/remote_base/pioneer_protocol.h
Andrew Zaborowski 2f07225984
Fix: Component script not stopped in certain situations (#1004)
* 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>
2020-06-28 19:44:15 -03:00

39 lines
1.0 KiB
C++

#pragma once
#include "remote_base.h"
namespace esphome {
namespace remote_base {
struct PioneerData {
uint16_t rc_code_1;
uint16_t rc_code_2;
bool operator==(const PioneerData &rhs) const { return rc_code_1 == rhs.rc_code_1 && rc_code_2 == rhs.rc_code_2; }
};
class PioneerProtocol : public RemoteProtocol<PioneerData> {
public:
void encode(RemoteTransmitData *dst, const PioneerData &data) override;
optional<PioneerData> decode(RemoteReceiveData src) override;
void dump(const PioneerData &data) override;
};
DECLARE_REMOTE_PROTOCOL(Pioneer)
template<typename... Ts> class PioneerAction : public RemoteTransmitterActionBase<Ts...> {
public:
TEMPLATABLE_VALUE(uint16_t, rc_code_1)
TEMPLATABLE_VALUE(uint16_t, rc_code_2)
void encode(RemoteTransmitData *dst, Ts... x) override {
PioneerData data{};
data.rc_code_1 = this->rc_code_1_.value(x...);
data.rc_code_2 = this->rc_code_2_.value(x...);
PioneerProtocol().encode(dst, data);
}
};
} // namespace remote_base
} // namespace esphome