ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
pioneer_wt.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5
11#ifdef USE_SWITCH
13#endif
14#include "pioneer_wt_protocol.h"
15
16namespace esphome::pioneer_wt {
17
18// The largest body control() builds is 30 bytes.
19static constexpr size_t MAX_BODY_SIZE = 32;
20static constexpr size_t TX_QUEUE_SIZE = 4;
21
22class PioneerWT final : public climate::Climate, public uart::UARTDevice, public Component {
23 public:
24 void setup() override;
25 void loop() override;
26 void dump_config() override;
27
29 void set_display_on(bool on) { this->send_setting_(ATTR_DISPLAY, on); }
31 void set_beeper_on(bool on) { this->send_setting_(ATTR_BEEPER, on); }
32
33#ifdef USE_SWITCH
34 SUB_SWITCH(display)
35 SUB_SWITCH(beeper)
36#endif
37
38 protected:
40 void control(const climate::ClimateCall &call) override;
41
42 void handle_frame_(const uint8_t *frame, size_t len);
43 void handle_status_(const uint8_t *body, size_t len);
44 void write_frame_(uint8_t flags, uint8_t type, uint8_t seq, uint8_t ack, uint8_t class_1, uint8_t class_2,
45 const uint8_t *body, size_t len);
47 void queue_command_(uint8_t msg_class, const uint8_t *body, size_t len, int8_t power = POWER_UNCHANGED);
48 void send_pending_();
50 void pop_command_();
52 bool wanted_power_(bool skip_head) const;
54 void send_setting_(uint16_t attr, bool on);
55 void request_status_();
56
57 static constexpr int8_t POWER_UNCHANGED = -1;
58
60 uint8_t msg_class;
61 uint8_t seq;
62 uint8_t len;
63 // Power the command sets: 0, 1 or POWER_UNCHANGED
64 int8_t power;
65 std::array<uint8_t, MAX_BODY_SIZE> body;
66 };
67
69 // Time of the last status report (counted once a full one has arrived), or of the last request for one
74 // Send attempts of the command at the head of the queue
75 uint8_t attempts_{0};
76 uint8_t next_seq_{1};
77 // Power the AC last reported
78 bool power_{false};
79 // Power set by an acknowledged command, until the next power report: 0, 1 or POWER_UNCHANGED
81 // Value of ATTR_MODE: 0 auto, 1 cool, 2 dry, 3 fan, 4 heat
82 uint8_t ac_mode_{0};
83};
84
85} // namespace esphome::pioneer_wt
Fixed-size circular buffer with FIFO semantics and iteration support.
Definition helpers.h:468
This class is used to encode all control actions on a climate device.
Definition climate.h:31
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:192
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
void write_frame_(uint8_t flags, uint8_t type, uint8_t seq, uint8_t ack, uint8_t class_1, uint8_t class_2, const uint8_t *body, size_t len)
StaticRingBuffer< PendingCommand, TX_QUEUE_SIZE > queue_
Definition pioneer_wt.h:73
void send_setting_(uint16_t attr, bool on)
Queues a command that sets one on/off attribute.
static constexpr int8_t POWER_UNCHANGED
Definition pioneer_wt.h:57
void set_beeper_on(bool on)
Turns the beep that confirms each command on or off.
Definition pioneer_wt.h:31
SUB_SWITCH(display) SUB_SWITCH(beeper) protected void control(const climate::ClimateCall &call) override
void handle_status_(const uint8_t *body, size_t len)
void handle_frame_(const uint8_t *frame, size_t len)
bool wanted_power_(bool skip_head) const
Power once the queued commands are applied; skip_head leaves out a head about to be dropped.
void set_display_on(bool on)
Turns the indoor unit's front display on or off.
Definition pioneer_wt.h:29
void pop_command_()
Removes the command at the head of the queue.
void queue_command_(uint8_t msg_class, const uint8_t *body, size_t len, int8_t power=POWER_UNCHANGED)
Queues a data frame that the AC must acknowledge; it is resent until it is.
uint16_t flags
uint8_t type
const void size_t len
Definition hal.h:68
static void uint32_t
std::array< uint8_t, MAX_BODY_SIZE > body
Definition pioneer_wt.h:65
uint16_t seq
uint8_t ack