fix midea: undo approved PR#4053 (#5233)

This commit is contained in:
Sergey Dudanov 2023-08-14 01:06:04 +04:00 committed by GitHub
parent 1269bf9791
commit 0daf4545a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 26 deletions

View file

@ -1488,11 +1488,9 @@ MideaData, MideaBinarySensor, MideaTrigger, MideaAction, MideaDumper = declare_p
MideaAction = ns.class_("MideaAction", RemoteTransmitterActionBase)
MIDEA_SCHEMA = cv.Schema(
{
cv.Required(CONF_CODE): cv.templatable(
cv.All(
[cv.Any(cv.hex_uint8_t, cv.uint8_t)],
cv.Length(min=5, max=5),
)
cv.Required(CONF_CODE): cv.All(
[cv.Any(cv.hex_uint8_t, cv.uint8_t)],
cv.Length(min=5, max=5),
),
}
)
@ -1519,12 +1517,10 @@ def midea_dumper(var, config):
MIDEA_SCHEMA,
)
async def midea_action(var, config, args):
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_))
template_ = await cg.templatable(
config[CONF_CODE], args, cg.std_vector.template(cg.uint8)
)
cg.add(var.set_code(template_))
# AEHA

View file

@ -1,11 +1,11 @@
#pragma once
#include <array>
#include <vector>
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "remote_base.h"
#include <array>
#include <utility>
#include <vector>
namespace esphome {
namespace remote_base {
@ -84,23 +84,13 @@ using MideaDumper = RemoteReceiverDumper<MideaProtocol, MideaData>;
template<typename... Ts> class MideaAction : public RemoteTransmitterActionBase<Ts...> {
TEMPLATABLE_VALUE(std::vector<uint8_t>, 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 set_code(std::initializer_list<uint8_t> code) { this->code_ = code; }
void encode(RemoteTransmitData *dst, Ts... x) override {
MideaData data;
if (!this->code_static_.empty()) {
data = MideaData(this->code_static_);
} else {
data = MideaData(this->code_func_(x...));
}
MideaData data(this->code_.value(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

View file

@ -2333,6 +2333,8 @@ switch:
second: !lambda "return 0xB21F98;"
- remote_transmitter.transmit_midea:
code: [0xA2, 0x08, 0xFF, 0xFF, 0xFF]
- remote_transmitter.transmit_midea:
code: !lambda "return {0xA2, 0x08, 0xFF, 0xFF, 0xFF};"
- platform: gpio
name: "MCP23S08 Pin #0"
pin: