mirror of
https://github.com/esphome/esphome.git
synced 2026-08-17 10:52:56 +08:00
[remote_base] support haier short IR message (#17826)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
co-authored by
Samuel Sieb
parent
a930baab7c
commit
899ed02ef2
@@ -2012,7 +2012,14 @@ HaierData, HaierBinarySensor, HaierTrigger, HaierAction, HaierDumper = declare_p
|
||||
HaierAction = ns.class_("HaierAction", RemoteTransmitterActionBase)
|
||||
HAIER_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_CODE): cv.All([cv.hex_uint8_t], cv.Length(min=13, max=13)),
|
||||
cv.Required(CONF_CODE): cv.All(
|
||||
[cv.hex_uint8_t],
|
||||
cv.Any(
|
||||
cv.Length(min=8, max=8),
|
||||
cv.Length(min=13, max=13),
|
||||
msg="must be a list of length 8 or 13",
|
||||
),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -11,9 +11,12 @@ constexpr uint32_t HEADER_HIGH_US = 4400;
|
||||
constexpr uint32_t BIT_MARK_US = 540;
|
||||
constexpr uint32_t BIT_ONE_SPACE_US = 1650;
|
||||
constexpr uint32_t BIT_ZERO_SPACE_US = 580;
|
||||
constexpr unsigned int HAIER_IR_PACKET_BIT_SIZE = 112;
|
||||
// 8 bytes + checksum
|
||||
constexpr unsigned int HAIER_IR_PACKET_BIT_SIZE_SHORT = 72;
|
||||
// 13 bytes + checksum
|
||||
constexpr unsigned int HAIER_IR_PACKET_BIT_SIZE_LONG = 112;
|
||||
// Max data bytes in packet (excluding checksum)
|
||||
constexpr size_t HAIER_MAX_DATA_BYTES = (HAIER_IR_PACKET_BIT_SIZE / 8);
|
||||
constexpr size_t HAIER_MAX_DATA_BYTES = HAIER_IR_PACKET_BIT_SIZE_LONG / 8 - 1;
|
||||
|
||||
void HaierProtocol::encode_byte_(RemoteTransmitData *dst, uint8_t item) {
|
||||
for (uint8_t mask = 1 << 7; mask != 0; mask >>= 1) {
|
||||
@@ -28,7 +31,7 @@ void HaierProtocol::encode_byte_(RemoteTransmitData *dst, uint8_t item) {
|
||||
|
||||
void HaierProtocol::encode(RemoteTransmitData *dst, const HaierData &data) {
|
||||
dst->set_carrier_frequency(38000);
|
||||
dst->reserve(5 + ((data.data.size() + 1) * 2));
|
||||
dst->reserve(5 + ((data.data.size() + 1) * 16));
|
||||
dst->mark(HEADER_LOW_US);
|
||||
dst->space(HEADER_LOW_US);
|
||||
dst->mark(HEADER_LOW_US);
|
||||
@@ -50,11 +53,16 @@ optional<HaierData> HaierProtocol::decode(RemoteReceiveData src) {
|
||||
return {};
|
||||
}
|
||||
size_t size = src.size() - src.get_index() - 1;
|
||||
if (size < HAIER_IR_PACKET_BIT_SIZE * 2)
|
||||
if (size >= HAIER_IR_PACKET_BIT_SIZE_LONG * 2) {
|
||||
size = HAIER_IR_PACKET_BIT_SIZE_LONG * 2;
|
||||
} else if (size >= HAIER_IR_PACKET_BIT_SIZE_SHORT * 2) {
|
||||
size = HAIER_IR_PACKET_BIT_SIZE_SHORT * 2;
|
||||
} else {
|
||||
return {};
|
||||
size = HAIER_IR_PACKET_BIT_SIZE * 2;
|
||||
}
|
||||
uint8_t checksum = 0;
|
||||
HaierData out;
|
||||
out.data.reserve(size / 16 - 1);
|
||||
while (size > 0) {
|
||||
uint8_t data = 0;
|
||||
for (uint8_t mask = 0x80; mask != 0; mask >>= 1) {
|
||||
|
||||
@@ -198,7 +198,7 @@ button:
|
||||
0xFF,
|
||||
]
|
||||
- platform: template
|
||||
name: Haier
|
||||
name: Haier Long
|
||||
on_press:
|
||||
remote_transmitter.transmit_haier:
|
||||
code:
|
||||
@@ -217,6 +217,21 @@ button:
|
||||
0x00,
|
||||
0x05,
|
||||
]
|
||||
- platform: template
|
||||
name: Haier Short
|
||||
on_press:
|
||||
remote_transmitter.transmit_haier:
|
||||
code:
|
||||
[
|
||||
0xA6,
|
||||
0xDA,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x40,
|
||||
0x00,
|
||||
0x80,
|
||||
]
|
||||
- platform: template
|
||||
name: Mirage
|
||||
on_press:
|
||||
|
||||
Reference in New Issue
Block a user