mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
Midea ir templatable code (#4053)
This commit is contained in:
parent
ef26677b67
commit
20da03f8c6
@ -1308,9 +1308,11 @@ MideaData, MideaBinarySensor, MideaTrigger, MideaAction, MideaDumper = declare_p
|
||||
MideaAction = ns.class_("MideaAction", RemoteTransmitterActionBase)
|
||||
MIDEA_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_CODE): cv.All(
|
||||
[cv.Any(cv.hex_uint8_t, cv.uint8_t)],
|
||||
cv.Length(min=5, max=5),
|
||||
cv.Required(CONF_CODE): cv.templatable(
|
||||
cv.All(
|
||||
[cv.Any(cv.hex_uint8_t, cv.uint8_t)],
|
||||
cv.Length(min=5, max=5),
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
@ -1337,7 +1339,12 @@ def midea_dumper(var, config):
|
||||
MIDEA_SCHEMA,
|
||||
)
|
||||
async def midea_action(var, config, args):
|
||||
cg.add(var.set_code(config[CONF_CODE]))
|
||||
code_ = config[CONF_CODE]
|
||||
if cg.is_template(code_):
|
||||
template_ = await cg.templatable(code_, args, cg.std_vector.template(cg.uint8))
|
||||
cg.add(var.set_code_template(template_))
|
||||
else:
|
||||
cg.add(var.set_code_static(code_))
|
||||
|
||||
|
||||
# AEHA
|
||||
|
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "remote_base.h"
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
namespace esphome {
|
||||
namespace remote_base {
|
||||
@ -84,12 +85,23 @@ using MideaDumper = RemoteReceiverDumper<MideaProtocol, MideaData>;
|
||||
|
||||
template<typename... Ts> class MideaAction : public RemoteTransmitterActionBase<Ts...> {
|
||||
TEMPLATABLE_VALUE(std::vector<uint8_t>, code)
|
||||
void set_code(const std::vector<uint8_t> &code) { code_ = code; }
|
||||
void set_code_static(std::vector<uint8_t> code) { code_static_ = std::move(code); }
|
||||
void set_code_template(std::function<std::vector<uint8_t>(Ts...)> func) { this->code_func_ = func; }
|
||||
|
||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
||||
MideaData data = this->code_.value(x...);
|
||||
MideaData data;
|
||||
if (!this->code_static_.empty()) {
|
||||
data = MideaData(this->code_static_);
|
||||
} else {
|
||||
data = MideaData(this->code_func_(x...));
|
||||
}
|
||||
data.finalize();
|
||||
MideaProtocol().encode(dst, data);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<std::vector<uint8_t>(Ts...)> code_func_{};
|
||||
std::vector<uint8_t> code_static_{};
|
||||
};
|
||||
|
||||
} // namespace remote_base
|
||||
|
Loading…
Reference in New Issue
Block a user