ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
pd_pioneer_ir.cpp
Go to the documentation of this file.
1#include "pd_pioneer_ir.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "pd_pioneer_ir");
7
9#ifdef USE_SWITCH
10 // Read before the climate publishes its restored state, which an on_state automation may transmit from, and publish
11 // after it, so the switch's own automations see a set up climate. Nothing is sent at boot.
12 if (this->display_switch_ != nullptr)
13 this->display_on_ = this->display_switch_->get_initial_write_state().value_or(true);
14#endif
15 climate_ir::ClimateIR::setup();
16#ifdef USE_SWITCH
17 PUBLISH_STATE(this->display_switch_, this->display_on_);
18#endif
19 this->publish_state();
20}
21
23 ControlData data;
24 data.set_mode(this->mode);
26 data.set_temp(this->target_temperature);
28 data.set_swing_mode(this->swing_mode);
29 // ECO shares the power byte, so it must not undo an off command
31 data.set_display(this->display_on_);
32 data.finalize();
33 // The remote sends the two bursts as separate transmissions
36}
37
39 this->display_on_ = on;
40 // An off command carries no display flag, and the display is dark while the unit is off
42 this->transmit_state();
43}
44
46 auto frame = remote_base::PDPioneerProtocol().decode(data);
47 if (!frame.has_value())
48 return false;
49 if (frame->is_odd_burst()) {
51 return false;
52 }
53 // decode() only returns odd or even bursts; a mode byte this remote never sends is another device's frame
54 const optional<climate::ClimateMode> decoded = ControlData::get_mode(*frame);
55 if (!decoded.has_value())
56 return false;
57 // An auto-mode frame from the remote must not publish HEAT_COOL when the traits leave it out
58 if (this->get_traits().supports_mode(*decoded)) {
59 this->mode = *decoded;
60 } else {
61 ESP_LOGD(TAG, "Received mode %s is not enabled, keeping the current mode",
62 LOG_STR_ARG(climate::climate_mode_to_string(*decoded)));
63 }
64 // Off and fan-only bursts carry no target temperature
65 if (*decoded != climate::CLIMATE_MODE_OFF && *decoded != climate::CLIMATE_MODE_FAN_ONLY)
67 this->fan_mode = ControlData::get_fan_mode(*frame);
69 // A missed odd burst must not carry this command's horizontal swing into the next one
70 this->rx_horizontal_swing_ = false;
72 if (*decoded != climate::CLIMATE_MODE_OFF) {
74#ifdef USE_SWITCH
75 PUBLISH_STATE(this->display_switch_, this->display_on_);
76#endif
77 }
78 this->publish_state();
79 return true;
80}
81
82} // namespace esphome::pd_pioneer_ir
ClimateMode mode
The active mode of the climate device.
Definition climate.h:317
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:311
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:482
float target_temperature
The target temperature of the climate device.
Definition climate.h:298
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:323
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:432
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:314
virtual void transmit_state()=0
Transmit via IR the state of this climate controller.
void set_display(bool on)
The display flag shares the power byte, so call this after set_eco()
static optional< ClimateMode > get_mode(const PDPioneerData &even)
Empty for a mode byte this remote does not use.
static float get_temp(const PDPioneerData &even)
Clamped to the set point range, so a frame from a sibling remote cannot publish an impossible value.
void set_swing_mode(climate::ClimateSwingMode mode)
static bool get_horizontal_swing(const PDPioneerData &odd)
Only the odd burst carries horizontal swing; the even burst carries vertical swing.
static ClimateFanMode get_fan_mode(const PDPioneerData &even)
void finalize()
Write the fan and swing positions, which share bytes, then the checksums.
const PDPioneerData & even() const
static bool get_eco(const PDPioneerData &even)
static bool get_display(const PDPioneerData &even)
static climate::ClimateSwingMode get_swing_mode(const PDPioneerData &even, bool horizontal)
const PDPioneerData & odd() const
void set_fan_mode(ClimateFanMode mode)
SUB_SWITCH(display) protected bool on_receive(remote_base::RemoteReceiveData data) override
void set_display_on(bool on)
Turns the unit's display on or off.
optional< PDPioneerData > decode(RemoteReceiveData src)
void transmit_(const typename Protocol::ProtocolData &data, uint32_t send_times=1, uint32_t send_wait=0)
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_OFF
The climate device is off.
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
ESPHOME_LOG_TAG(TAG, "pd_pioneer_ir")