ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
toshiba.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
8
9namespace esphome::toshiba {
10
11static constexpr uint16_t TOSHIBA_HEADER_MARK = 4380;
12static constexpr uint16_t TOSHIBA_HEADER_SPACE = 4370;
13static constexpr uint16_t TOSHIBA_GAP_SPACE = 5480;
14static constexpr uint16_t TOSHIBA_BIT_MARK = 540;
15static constexpr uint8_t TOSHIBA_HEADER_LENGTH = 4;
16static constexpr uint8_t TOSHIBA_HEADER_BYTE_0 = 0xF2;
17static constexpr uint8_t TOSHIBA_HEADER_BYTE_1 = 0x0D;
18static constexpr uint8_t TOSHIBA_COMMAND_DEFAULT = 0x01;
19static constexpr uint8_t TOSHIBA_COMMAND_TIMER = 0x02;
20static constexpr uint8_t TOSHIBA_COMMAND_POWER = 0x08;
21static constexpr uint8_t TOSHIBA_FAN_SPEED_AUTO = 0x00;
22static constexpr uint8_t TOSHIBA_FAN_SPEED_QUIET = 0x20;
23static constexpr uint8_t TOSHIBA_FAN_SPEED_1 = 0x40;
24static constexpr uint8_t TOSHIBA_FAN_SPEED_2 = 0x60;
25static constexpr uint8_t TOSHIBA_FAN_SPEED_3 = 0x80;
26static constexpr uint8_t TOSHIBA_FAN_SPEED_4 = 0xA0;
27static constexpr uint8_t TOSHIBA_FAN_SPEED_5 = 0xC0;
28static constexpr uint8_t TOSHIBA_POWER_HIGH = 0x01;
29static constexpr uint8_t TOSHIBA_POWER_ECO = 0x03;
30static constexpr uint8_t TOSHIBA_MOTION_SWING = 0x04;
31static constexpr uint8_t TOSHIBA_MOTION_VANE_STEP = 0x00;
32
33// Simple enum to represent models.
34enum Model {
35 MODEL_GENERIC = 0, // Temperature range is from 17 to 30
36 MODEL_RAC_PT1411HWRU_C = 1, // Temperature range is from 16 to 30
37 MODEL_RAC_PT1411HWRU_F = 2, // Temperature range is from 16 to 30
38 MODEL_RAS_2819T = 3, // RAS-2819T protocol variant, temperature range 18 to 30
39 MODEL_SEIYA = 4, // Seiya family (RAS-B13E2KVG-E etc.), generic frame with a swing byte
40 MODEL_RAS_B10N3KV2 = 5, // RAS-B13 remote family, generic frame with IRremoteESP8266's TOSHIBA_AC timings
41 MODEL_RAS_25J2KVSG_ND = 6, // WH-TA15PE remote
42};
43
44// Supported temperature ranges
45const float TOSHIBA_GENERIC_TEMP_C_MIN = 17.0;
46const float TOSHIBA_GENERIC_TEMP_C_MAX = 30.0;
53
55 public:
60
61 void setup() override;
62 void set_model(Model model) { this->model_ = model; }
63
64 protected:
65 void transmit_state() override;
66 void transmit_generic_();
68 void transmit_rac_pt1411hwru_temp_(bool cs_state = true, bool cs_send_update = true);
70 // Process RAS-2819T IR command data
72 // Returns the header if valid, else returns zero
73 uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message);
74 // Returns true if message is a valid RAC-PT1411HWRU IR message, regardless if first or second packet
75 bool is_valid_rac_pt1411hwru_message_(const uint8_t *message);
76 // Returns true if message1 and message 2 are the same
77 bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2);
79
80 // Hooks for model subclasses
81 virtual float temperature_min() {
84 if (this->model_ == MODEL_RAS_2819T)
86 return TOSHIBA_GENERIC_TEMP_C_MIN; // Default to GENERIC for unknown models
87 }
88 // Called from the sensor callback after current_temperature is updated
90 // Sanitizes the saved state before swing and apply() use it
92
93 void encode_(remote_base::RemoteTransmitData *data, const uint8_t *message, uint8_t nbytes, uint8_t repeat);
94 bool decode_(remote_base::RemoteReceiveData *data, uint8_t *message, uint8_t nbytes);
95 // Writes the F2 0D header, the length byte and its inverse, and the trailing XOR of an F2 0D frame.
96 static void finalize_frame(uint8_t *message, uint8_t length);
97 static bool frame_header_valid(const uint8_t *message) {
98 return message[0] == TOSHIBA_HEADER_BYTE_0 && message[1] == TOSHIBA_HEADER_BYTE_1 &&
99 (message[2] ^ message[3]) == 0xFF;
100 }
101 static bool frame_checksum_valid(const uint8_t *message, uint8_t length) {
102 return xor_bytes(message + 4, length - 5) == message[length - 1];
103 }
104
105 // Shared by every model that uses the F2 0D frame
106 uint8_t encode_mode_() const;
107 uint8_t encode_fan_() const;
108 void decode_mode_(const uint8_t *message);
109 static climate::ClimateFanMode decode_fan(uint8_t code);
110
111 // Last swing mode sent or received, for models whose swing is a one-shot command
114
115 private:
117 optional<climate::ClimateFanMode> last_fan_mode_{};
118 float last_target_temperature_{24.0f};
119
120 float temperature_max_() {
121 if (this->model_ == MODEL_RAC_PT1411HWRU_C || this->model_ == MODEL_RAC_PT1411HWRU_F)
123 if (this->model_ == MODEL_RAS_2819T)
125 return TOSHIBA_GENERIC_TEMP_C_MAX; // Default to GENERIC for unknown models
126 }
127 climate::ClimateSwingModeMask toshiba_swing_modes_() {
128 if (this->model_ == MODEL_GENERIC || this->model_ == MODEL_RAS_B10N3KV2)
130 if (this->model_ == MODEL_SEIYA) {
131 // No captured code stops the swing, so OFF is not offered; the remote only selects a direction
134 }
136 }
137 uint8_t encode_mode_fan_() const { return this->encode_fan_() | this->encode_mode_(); }
138 void decode_mode_fan_temperature_(const uint8_t *message);
139 uint8_t seiya_swing_code_() const;
140 void seiya_decode_swing_(uint8_t code);
141};
142
143} // namespace esphome::toshiba
ClimateIR(float minimum_temperature, float maximum_temperature, float temperature_step=1.0f, bool supports_dry=false, bool supports_fan_only=false, climate::ClimateFanModeMask fan_modes=climate::ClimateFanModeMask(), climate::ClimateSwingModeMask swing_modes=climate::ClimateSwingModeMask(), climate::ClimatePresetMask presets=climate::ClimatePresetMask())
Definition climate_ir.h:25
static bool frame_header_valid(const uint8_t *message)
Definition toshiba.h:97
void encode_(remote_base::RemoteTransmitData *data, const uint8_t *message, uint8_t nbytes, uint8_t repeat)
Definition toshiba.cpp:1307
virtual void transmit_current_temperature()
Definition toshiba.h:89
static void finalize_frame(uint8_t *message, uint8_t length)
Definition toshiba.cpp:1299
bool compare_rac_pt1411hwru_packets_(const uint8_t *message1, const uint8_t *message2)
Definition toshiba.cpp:979
virtual float temperature_min()
Definition toshiba.h:81
virtual void sanitize_restore_state(climate::ClimateDeviceRestoreState &restore)
Definition toshiba.h:91
bool is_valid_rac_pt1411hwru_message_(const uint8_t *message)
Definition toshiba.cpp:987
static climate::ClimateFanMode decode_fan(uint8_t code)
Definition toshiba.cpp:1382
uint8_t is_valid_rac_pt1411hwru_header_(const uint8_t *message)
Definition toshiba.cpp:965
void set_model(Model model)
Definition toshiba.h:62
bool process_ras_2819t_command_(const remote_base::ToshibaAcData &toshiba_data)
Definition toshiba.cpp:1011
bool decode_(remote_base::RemoteReceiveData *data, uint8_t *message, uint8_t nbytes)
Definition toshiba.cpp:1332
void decode_mode_(const uint8_t *message)
Definition toshiba.cpp:1354
climate::ClimateSwingMode last_swing_mode_
Definition toshiba.h:112
void transmit_rac_pt1411hwru_temp_(bool cs_state=true, bool cs_send_update=true)
Definition toshiba.cpp:706
bool on_receive(remote_base::RemoteReceiveData data) override
Definition toshiba.cpp:1094
static bool frame_checksum_valid(const uint8_t *message, uint8_t length)
Definition toshiba.h:101
const LogString * message
Definition component.cpp:35
FiniteSetMask< ClimateSwingMode, DefaultBitPolicy< ClimateSwingMode, CLIMATE_SWING_HORIZONTAL+1 > > ClimateSwingModeMask
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_OFF
The climate device is off.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
@ MODEL_RAC_PT1411HWRU_C
Definition toshiba.h:36
@ MODEL_RAS_25J2KVSG_ND
Definition toshiba.h:41
@ MODEL_RAC_PT1411HWRU_F
Definition toshiba.h:37
const float TOSHIBA_RAS_2819T_TEMP_C_MAX
Definition toshiba.h:52
const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MIN
Definition toshiba.h:49
const float TOSHIBA_GENERIC_TEMP_C_MAX
Definition toshiba.h:46
const float TOSHIBA_GENERIC_TEMP_C_MIN
Definition toshiba.h:45
const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MAX
Definition toshiba.h:48
const float TOSHIBA_RAS_2819T_TEMP_C_MIN
Definition toshiba.h:51
const float TOSHIBA_RAC_PT1411HWRU_TEMP_C_MIN
Definition toshiba.h:47
const float TOSHIBA_RAC_PT1411HWRU_TEMP_F_MAX
Definition toshiba.h:50
constexpr uint8_t xor_bytes(const uint8_t *data, size_t len, uint8_t init=0)
XOR the bytes of data with size len, starting from init.
Definition helpers.h:904
Struct used to save the state of the climate device in restore memory.
Definition climate.h:149