ESPHome  2024.11.1
midea_data.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace midea_ir {
8 
12 
13 class ControlData : public MideaData {
14  public:
15  // Default constructor (power: ON, mode: AUTO, fan: AUTO, temp: 25C)
16  ControlData() : MideaData({MIDEA_TYPE_CONTROL, 0x82, 0x48, 0xFF, 0xFF}) {}
17  // Copy from Base
18  ControlData(const MideaData &data) : MideaData(data) {}
19 
20  void set_temp(float temp);
21  float get_temp() const;
22 
24  ClimateMode get_mode() const;
25 
26  void set_fan_mode(ClimateFanMode mode);
28 
29  void set_sleep_preset(bool value) { this->set_mask_(1, value, 64); }
30  bool get_sleep_preset() const { return this->get_value_(1, 64); }
31 
32  void set_fahrenheit(bool value) { this->set_mask_(2, value, 32); }
33  bool get_fahrenheit() const { return this->get_value_(2, 32); }
34 
35  void fix();
36 
37  protected:
38  enum Mode : uint8_t {
44  };
45  enum FanMode : uint8_t {
50  };
51  void set_fan_mode_(FanMode mode) { this->set_value_(1, mode, 3, 3); }
52  FanMode get_fan_mode_() const { return static_cast<FanMode>(this->get_value_(1, 3, 3)); }
53  void set_mode_(Mode mode) { this->set_value_(1, mode, 7); }
54  Mode get_mode_() const { return static_cast<Mode>(this->get_value_(1, 7)); }
55  void set_power_(bool value) { this->set_mask_(1, value, 128); }
56  bool get_power_() const { return this->get_value_(1, 128); }
57 };
58 
59 class FollowMeData : public MideaData {
60  public:
61  // Default constructor (temp: 30C, beeper: off)
62  FollowMeData() : MideaData({MIDEA_TYPE_FOLLOW_ME, 0x82, 0x48, 0x7F, 0x1F}) {}
63  // Copy from Base
64  FollowMeData(const MideaData &data) : MideaData(data) {}
65  // Direct from temperature and beeper values
66  FollowMeData(uint8_t temp, bool beeper = false) : FollowMeData() {
67  this->set_temp(temp);
68  this->set_beeper(beeper);
69  }
70 
71  /* TEMPERATURE */
72  uint8_t temp() const { return this->get_value_(4) - 1; }
73  void set_temp(uint8_t val) { this->set_value_(4, std::min(MAX_TEMP, val) + 1); }
74 
75  /* BEEPER */
76  bool beeper() const { return this->get_value_(3, 128); }
77  void set_beeper(bool value) { this->set_mask_(3, value, 128); }
78 
79  protected:
80  static const uint8_t MAX_TEMP = 37;
81 };
82 
83 class SpecialData : public MideaData {
84  public:
85  SpecialData(uint8_t code) : MideaData({MIDEA_TYPE_SPECIAL, code, 0xFF, 0xFF, 0xFF}) {}
86  static const uint8_t VSWING_STEP = 1;
87  static const uint8_t VSWING_TOGGLE = 2;
88  static const uint8_t TURBO_TOGGLE = 9;
89 };
90 
91 } // namespace midea_ir
92 } // namespace esphome
ControlData(const MideaData &data)
Definition: midea_data.h:18
FanMode get_fan_mode_() const
Definition: midea_data.h:52
void set_power_(bool value)
Definition: midea_data.h:55
mopeka_std_values val[4]
void set_sleep_preset(bool value)
Definition: midea_data.h:29
void set_value_(uint8_t idx, uint8_t value, uint8_t mask=255, uint8_t shift=0)
void set_fahrenheit(bool value)
Definition: midea_data.h:32
void set_beeper(bool value)
Definition: midea_data.h:77
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
uint8_t get_value_(uint8_t idx, uint8_t mask=255, uint8_t shift=0) const
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
void set_temp(float temp)
Definition: midea_ir.cpp:12
void set_mask_(uint8_t idx, bool state, uint8_t mask=255)
FollowMeData(const MideaData &data)
Definition: midea_data.h:64
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_fan_mode(ClimateFanMode mode)
Definition: midea_ir.cpp:82
void set_mode(ClimateMode mode)
Definition: midea_ir.cpp:41
FollowMeData(uint8_t temp, bool beeper=false)
Definition: midea_data.h:66
void set_temp(uint8_t val)
Definition: midea_data.h:73
ClimateMode get_mode() const
Definition: midea_ir.cpp:65
void set_fan_mode_(FanMode mode)
Definition: midea_data.h:51
ClimateFanMode get_fan_mode() const
Definition: midea_ir.cpp:99