add on_rc_switch trigger (#983)

This commit is contained in:
escoand 2020-03-12 01:36:34 +01:00 committed by GitHub
parent fcb2cc2471
commit a1dfd355f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -546,7 +546,9 @@ RC_SWITCH_TRANSMITTER = cv.Schema({
})
rc_switch_protocols = ns.rc_switch_protocols
RCSwitchData = ns.struct('RCSwitchData')
RCSwitchBase = ns.class_('RCSwitchBase')
RCSwitchTrigger = ns.class_('RCSwitchTrigger', RemoteReceiverTrigger)
RCSwitchDumper = ns.class_('RCSwitchDumper', RemoteTransmitterDumper)
RCSwitchRawAction = ns.class_('RCSwitchRawAction', RemoteTransmitterActionBase)
RCSwitchTypeAAction = ns.class_('RCSwitchTypeAAction', RemoteTransmitterActionBase)
@ -642,6 +644,11 @@ def rc_switch_type_d_action(var, config, args):
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, bool))))
@register_trigger('rc_switch', RCSwitchTrigger, RCSwitchData)
def rc_switch_trigger(var, config):
pass
@register_dumper('rc_switch', RCSwitchDumper)
def rc_switch_dumper(var, config):
pass

View File

@ -127,6 +127,19 @@ bool RCSwitchBase::decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *o
}
return true;
}
optional<RCSwitchData> RCSwitchBase::decode(RemoteReceiveData &src) const {
RCSwitchData out;
uint8_t out_nbits;
for (uint8_t i = 1; i <= 8; i++) {
src.reset();
RCSwitchBase *protocol = &rc_switch_protocols[i];
if (protocol->decode(src, &out.code, &out_nbits) && out_nbits >= 3) {
out.protocol = i;
return out;
}
}
return {};
}
void RCSwitchBase::simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_t *out_code) {
*out_code = 0;

View File

@ -6,6 +6,13 @@
namespace esphome {
namespace remote_base {
struct RCSwitchData {
uint64_t code;
uint8_t protocol;
bool operator==(const RCSwitchData &rhs) const { return code == rhs.code && protocol == rhs.protocol; }
};
class RCSwitchBase {
public:
RCSwitchBase() = default;
@ -28,6 +35,8 @@ class RCSwitchBase {
bool decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *out_nbits) const;
optional<RCSwitchData> decode(RemoteReceiveData &src) const;
static void simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_t *out_code);
static void type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code,
@ -204,5 +213,7 @@ class RCSwitchDumper : public RemoteReceiverDumperBase {
bool dump(RemoteReceiveData src) override;
};
using RCSwitchTrigger = RemoteReceiverTrigger<RCSwitchBase, RCSwitchData>;
} // namespace remote_base
} // namespace esphome