16static constexpr uint32_t RESEND_INTERVAL_MS = 500;
17static constexpr uint8_t MAX_ATTEMPTS = 4;
19static constexpr uint32_t STATUS_REFRESH_MS = 5 * 60 * 1000;
21static constexpr uint32_t STATUS_RETRY_MS = 30 * 1000;
22static constexpr float MIN_TEMPERATURE_C = 16.0f;
23static constexpr float MAX_TEMPERATURE_C = 31.0f;
25static constexpr uint8_t FAN_SPEED_COUNT = 7;
26static constexpr const char *
const FAN_SPEED_NAMES[FAN_SPEED_COUNT] PROGMEM = {
27 "Speed 1",
"Speed 2",
"Speed 3",
"Speed 4",
"Speed 5",
"Speed 6",
"Speed 7"};
31static constexpr uint8_t PRESENCE_REPLY_FRAME[] PROGMEM = {0xA5, 0x01, 0x00, 0x23, 0x00, 0x00, 0x00, 0x12, 0x47,
32 0x09, 0x80, 0x0C, 0x02, 0x64, 0xFF, 0xFF, 0xFF, 0xD0};
35static constexpr uint8_t CLIMATE_MODES[] PROGMEM = {
44 if (this->display_switch_ !=
nullptr)
45 this->display_switch_->restore();
46 if (this->beeper_switch_ !=
nullptr)
47 this->beeper_switch_->restore();
69 auto handle = [
this](
const uint8_t *frame,
size_t len) {
71 ESP_LOGD(TAG,
"Dropped a frame with a wrong checksum");
79 if (!this->
queue_.empty() && now - this->last_send_ >= RESEND_INTERVAL_MS && !this->reader_.receiving())
88 const uint8_t
flags = frame[2];
89 const uint8_t
type = frame[3];
90 const uint8_t
seq = frame[4];
91 const uint8_t
ack = frame[5];
92 const uint8_t *payload = frame + HEADER_SIZE;
93 const size_t payload_len =
len - HEADER_SIZE;
94 ESP_LOGVV_HEX(TAG, frame,
len, MAX_FRAME_SIZE,
"RX %s");
96 if (
type == TYPE_REPLY) {
97 if (!this->
queue_.empty() && this->queue_.front().seq ==
ack) {
107 if (type != TYPE_DATA || payload_len < 2)
110 const uint8_t msg_class = payload[0];
111 if (
flags & FLAG_WANT_ACK)
112 this->
write_frame_(FLAG_WANT_ACK, TYPE_REPLY, 0,
seq, CLASS_REPLY, msg_class,
nullptr, 0);
114 if (msg_class != CLASS_STATUS)
116 if (payload_len == 2) {
117 if (!(
flags & FLAG_WANT_ACK))
129 bool changed =
false;
130 while (attrs.
next()) {
132 switch (attrs.
id()) {
138 if (v < std::size(CLIMATE_MODES)) {
141 ESP_LOGD(TAG,
"Unknown mode %" PRIu32, v);
144 case ATTR_SETPOINT_F: {
150 case ATTR_INDOOR_TEMP_C100: {
151 const float current =
static_cast<float>(v) / 100.0f;
159 }
else if (v <= FAN_SPEED_COUNT) {
162 ESP_LOGD(TAG,
"Unknown fan speed %" PRIu32, v);
165 case ATTR_SWING_VERTICAL: {
176 PUBLISH_STATE(this->display_switch_, v != 0);
179 PUBLISH_STATE(this->beeper_switch_, v != 0);
187 ESP_LOGD(TAG,
"Status attribute %04X has an unknown size; ignored the rest of the frame", attrs.
id());
199 uint8_t body[MAX_BODY_SIZE];
203 if (
call.get_mode().has_value()) {
210 for (
size_t i = 0; i < std::size(CLIMATE_MODES); i++) {
221 p =
put_attr(p, ATTR_MODE, ac_mode);
225 if (
call.get_target_temperature().has_value()) {
227 const float celsius = clamp(*
call.get_target_temperature(), MIN_TEMPERATURE_C, MAX_TEMPERATURE_C);
235 }
else if (
call.has_custom_fan_mode()) {
237 const char *name =
call.get_custom_fan_mode().c_str();
238 for (uint8_t i = 0; i < FAN_SPEED_COUNT; i++) {
239 if (name == FAN_SPEED_NAMES[i]) {
245 if (fan_speed >= 0) {
246 p =
put_attr(p, ATTR_FAN_EXTRA_1, 0);
247 p =
put_attr(p, ATTR_FAN_EXTRA_2, 0);
248 p =
put_attr(p, ATTR_FAN_SPEED, fan_speed);
249 p =
put_attr(p, ATTR_FAN_AUTO, fan_speed == 0);
252 if (
call.get_swing_mode().has_value()) {
254 p =
put_attr(p, ATTR_SWING_VERTICAL, swing ? SWING_ON : SWING_OFF);
257 if (
call.get_preset().has_value())
273 static constexpr uint8_t REQUEST_ALL[] = {0xFF, 0xFF};
274 this->
queue_command_(CLASS_NETWORK, REQUEST_ALL,
sizeof(REQUEST_ALL));
279 if (this->
queue_.size() == TX_QUEUE_SIZE) {
280 ESP_LOGW(TAG,
"Command queue full; dropping the oldest command");
284 std::memcpy(pending.body.data(), body,
len);
285 this->
queue_.push(pending);
304 power = pending.power;
312 const uint8_t
seq = pending.
seq;
315 ESP_LOGD(TAG,
"No acknowledgement for command seq %02X; giving up",
seq);
321 pending.
body.data(), pending.
len);
326 const uint8_t *body,
size_t len) {
327 uint8_t frame[HEADER_SIZE + 2 + MAX_BODY_SIZE];
329 ESP_LOGVV_HEX(TAG, frame, total,
sizeof(frame),
"TX %s");
336 LOG_CLIMATE(
"",
"Pioneer WT",
this);
338 LOG_SWITCH(
" ",
"Display", this->display_switch_);
339 LOG_SWITCH(
" ",
"Beeper", this->beeper_switch_);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void status_set_warning()
void status_clear_warning()
void drop_kept()
Forget a partial frame an idle flush kept, before a request starts a new exchange; safe inside a fram...
This class is used to encode all control actions on a climate device.
ClimateMode mode
The active mode of the climate device.
float target_temperature
The target temperature of the climate device.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
float current_temperature
The current temperature of the climate device, as reported from the integration.
void set_supported_custom_fan_modes_static(const char *const *modes, size_t count)
Points at a static table that outlives the climate (codegen); call before any runtime copy.
void publish_state()
Publish the state of the climate device, to be called from integrations.
bool set_custom_fan_mode_(const char *mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
void set_visual_max_temperature(float visual_max_temperature)
void add_feature_flags(uint32_t feature_flags)
void set_visual_target_temperature_step(float temperature_step)
void set_supported_presets(ClimatePresetMask presets)
void set_supported_swing_modes(ClimateSwingModeMask modes)
void set_visual_min_temperature(float visual_min_temperature)
void set_visual_current_temperature_step(float temperature_step)
void set_supported_modes(ClimateModeMask modes)
void set_supported_fan_modes(ClimateFanModeMask modes)
Walks the attribute list in a status body. Stops at the first ID whose size is unknown.
bool stopped_on_unknown() const
True when the walk stopped early on an ID of unknown size.
bool next()
Moves to the next attribute. Returns false at the end of the body or at an unknown ID.
void dump_config() override
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_
void send_setting_(uint16_t attr, bool on)
Queues a command that sets one on/off attribute.
static constexpr int8_t POWER_UNCHANGED
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 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.
void write_array_progmem(const uint8_t *data, size_t len)
void write_array(const uint8_t *data, size_t len)
bool read_frames(R &reader, F &&handle, uint32_t now, uint32_t &last_rx, uint32_t gap_ms=250)
Feed the waiting bytes to a LengthFrameReader; on a pass with none, gap_ms after last_rx,...
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
ESPHOME_LOG_TAG(TAG, "pioneer_wt")
uint8_t * put_attr(uint8_t *p, uint16_t id, uint8_t value)
Writes a one-byte attribute (2-byte ID, then the value) at p. Returns the new end.
bool checksum_valid(const uint8_t *frame, size_t len)
size_t build_frame(uint8_t *out, 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)
Builds a frame into out, which must hold HEADER_SIZE + 2 + len bytes. Returns the frame length.
constexpr uint8_t * put_be16(uint8_t *dst, uint16_t value)
Write the low 16, 24 or 32 bits of value to dst, most significant byte first (be) or least significan...
constexpr float celsius_to_fahrenheit(float value)
Convert degrees Celsius to degrees Fahrenheit.
constexpr float fahrenheit_to_celsius(float value)
Convert degrees Fahrenheit to degrees Celsius.
Application App
Global storage of Application pointer - only one Application can exist.
constexpr uint8_t * put_be32(uint8_t *dst, uint32_t value)
uint8_t progmem_read_byte(const uint8_t *addr)
std::array< uint8_t, MAX_BODY_SIZE > body
spi_device_handle_t handle