mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 16:37:52 +01:00
add on_rc_switch trigger (#983)
This commit is contained in:
parent
fcb2cc2471
commit
a1dfd355f7
@ -546,7 +546,9 @@ RC_SWITCH_TRANSMITTER = cv.Schema({
|
|||||||
})
|
})
|
||||||
|
|
||||||
rc_switch_protocols = ns.rc_switch_protocols
|
rc_switch_protocols = ns.rc_switch_protocols
|
||||||
|
RCSwitchData = ns.struct('RCSwitchData')
|
||||||
RCSwitchBase = ns.class_('RCSwitchBase')
|
RCSwitchBase = ns.class_('RCSwitchBase')
|
||||||
|
RCSwitchTrigger = ns.class_('RCSwitchTrigger', RemoteReceiverTrigger)
|
||||||
RCSwitchDumper = ns.class_('RCSwitchDumper', RemoteTransmitterDumper)
|
RCSwitchDumper = ns.class_('RCSwitchDumper', RemoteTransmitterDumper)
|
||||||
RCSwitchRawAction = ns.class_('RCSwitchRawAction', RemoteTransmitterActionBase)
|
RCSwitchRawAction = ns.class_('RCSwitchRawAction', RemoteTransmitterActionBase)
|
||||||
RCSwitchTypeAAction = ns.class_('RCSwitchTypeAAction', 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))))
|
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)
|
@register_dumper('rc_switch', RCSwitchDumper)
|
||||||
def rc_switch_dumper(var, config):
|
def rc_switch_dumper(var, config):
|
||||||
pass
|
pass
|
||||||
|
@ -127,6 +127,19 @@ bool RCSwitchBase::decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *o
|
|||||||
}
|
}
|
||||||
return true;
|
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) {
|
void RCSwitchBase::simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_t *out_code) {
|
||||||
*out_code = 0;
|
*out_code = 0;
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace remote_base {
|
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 {
|
class RCSwitchBase {
|
||||||
public:
|
public:
|
||||||
RCSwitchBase() = default;
|
RCSwitchBase() = default;
|
||||||
@ -28,6 +35,8 @@ class RCSwitchBase {
|
|||||||
|
|
||||||
bool decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *out_nbits) const;
|
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 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,
|
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;
|
bool dump(RemoteReceiveData src) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using RCSwitchTrigger = RemoteReceiverTrigger<RCSwitchBase, RCSwitchData>;
|
||||||
|
|
||||||
} // namespace remote_base
|
} // namespace remote_base
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Loading…
Reference in New Issue
Block a user