mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-22 21:58:29 +02:00
f34c9b33fc
* Added support for Midea IoT climate devices via UART interface (USB-dongle) * Fixed lint checks * Fixed lint checks * CODEOWNERS update * Clang-format * Clang-format * Add network device notification message support (show WiFi sign on devices) * Make wifi_signal_sensor optional component * Some optimization * Optimizations and code formatting * Fixed lint checks * Fixed lint checks * Fixed sign error * Code changes * Network notify repeat every 10 min * Added log messages * Fixed lint checks * Refactoring: MideaClimate => MideaAC * Using enums instead literals in Midea states * Enum changed to be more correct * Shrink notify frame to 32 bytes * Fixed lint checks * Change notify frame appliance type to common broadcast * Control optimization * Fixed control error * Control command now don't reset others uncontrollable properties of device * Fixed lint checks * Some optimization * on_receive callback give const Frame * Fix control * Fixes * Some minor changes * Fixed lint error * No dependency from wifi_signal sensor for stretched WiFi icon. New option: stretched_icon instead wifi_signal_id. * Fix option name * Added export of outdoor temperature as sensor value * Fixed lint errors * Fixed pylint error * Minor fix * Fix temperature overflow in some cases * Added answer on QueryNetwork command from appliance. Now don't wait for ack on 0x0D command. * Fix lint error * Added humidity setpoint optional sensor * Added boolean options 'swing_horizontal' and 'swing_both' * Added debug frame output * Added debug frame output * Fix lints error * Some debug output optimization * Fix lint check * Some code optimization: adding templates * Fix lint error * Added sensors device classes * Python code reformatted with black formatter * RX frame debug message RX frame debug message now prints before checking * Remove CRC check for receiving frames * Added experimental power usage option * Added power usage option * Fixed lint errors * Major changes. See esp-docs. * Added tests in test4.yaml * Added tests in test1.yaml * Added wifi dependency * Fix test1.yaml * Some fix :) * One more refactoring * One more refactoring * One more refactoring
138 lines
3.9 KiB
C++
138 lines
3.9 KiB
C++
#pragma once
|
|
#include "esphome/components/climate/climate.h"
|
|
#include "esphome/components/midea_dongle/midea_frame.h"
|
|
|
|
namespace esphome {
|
|
namespace midea_ac {
|
|
|
|
/// Enum for all modes a Midea device can be in.
|
|
enum MideaMode : uint8_t {
|
|
/// The Midea device is set to automatically change the heating/cooling cycle
|
|
MIDEA_MODE_AUTO = 1,
|
|
/// The Midea device is manually set to cool mode (not in auto mode!)
|
|
MIDEA_MODE_COOL = 2,
|
|
/// The Midea device is manually set to dry mode
|
|
MIDEA_MODE_DRY = 3,
|
|
/// The Midea device is manually set to heat mode (not in auto mode!)
|
|
MIDEA_MODE_HEAT = 4,
|
|
/// The Midea device is manually set to fan only mode
|
|
MIDEA_MODE_FAN_ONLY = 5,
|
|
};
|
|
|
|
/// Enum for all modes a Midea fan can be in
|
|
enum MideaFanMode : uint8_t {
|
|
/// The fan mode is set to Auto
|
|
MIDEA_FAN_AUTO = 102,
|
|
/// The fan mode is set to Low
|
|
MIDEA_FAN_LOW = 40,
|
|
/// The fan mode is set to Medium
|
|
MIDEA_FAN_MEDIUM = 60,
|
|
/// The fan mode is set to High
|
|
MIDEA_FAN_HIGH = 80,
|
|
};
|
|
|
|
/// Enum for all modes a Midea swing can be in
|
|
enum MideaSwingMode : uint8_t {
|
|
/// The sing mode is set to Off
|
|
MIDEA_SWING_OFF = 0b0000,
|
|
/// The fan mode is set to Both
|
|
MIDEA_SWING_BOTH = 0b1111,
|
|
/// The fan mode is set to Vertical
|
|
MIDEA_SWING_VERTICAL = 0b1100,
|
|
/// The fan mode is set to Horizontal
|
|
MIDEA_SWING_HORIZONTAL = 0b0011,
|
|
};
|
|
|
|
class PropertiesFrame : public midea_dongle::BaseFrame {
|
|
public:
|
|
PropertiesFrame() = delete;
|
|
PropertiesFrame(uint8_t *data) : BaseFrame(data) {}
|
|
PropertiesFrame(const Frame &frame) : BaseFrame(frame) {}
|
|
|
|
bool has_properties() const {
|
|
return this->has_response_type(0xC0) && (this->has_type(0x03) || this->has_type(0x02));
|
|
}
|
|
|
|
bool has_power_info() const { return this->has_response_type(0xC1); }
|
|
|
|
/* TARGET TEMPERATURE */
|
|
|
|
float get_target_temp() const;
|
|
void set_target_temp(float temp);
|
|
|
|
/* MODE */
|
|
climate::ClimateMode get_mode() const;
|
|
void set_mode(climate::ClimateMode mode);
|
|
|
|
/* FAN SPEED */
|
|
climate::ClimateFanMode get_fan_mode() const;
|
|
void set_fan_mode(climate::ClimateFanMode mode);
|
|
|
|
/* SWING MODE */
|
|
climate::ClimateSwingMode get_swing_mode() const;
|
|
void set_swing_mode(climate::ClimateSwingMode mode);
|
|
|
|
/* INDOOR TEMPERATURE */
|
|
float get_indoor_temp() const;
|
|
|
|
/* OUTDOOR TEMPERATURE */
|
|
float get_outdoor_temp() const;
|
|
|
|
/* HUMIDITY SETPOINT */
|
|
float get_humidity_setpoint() const;
|
|
|
|
/* ECO MODE */
|
|
bool get_eco_mode() const { return this->pbuf_[19]; }
|
|
void set_eco_mode(bool state) { this->set_bytemask_(19, 0xFF, state); }
|
|
|
|
/* SLEEP MODE */
|
|
bool get_sleep_mode() const { return this->pbuf_[20] & 0x01; }
|
|
void set_sleep_mode(bool state) { this->set_bytemask_(20, 0x01, state); }
|
|
|
|
/* TURBO MODE */
|
|
bool get_turbo_mode() const { return this->pbuf_[20] & 0x02; }
|
|
void set_turbo_mode(bool state) { this->set_bytemask_(20, 0x02, state); }
|
|
|
|
/* POWER USAGE */
|
|
float get_power_usage() const;
|
|
|
|
/// Set properties from another frame
|
|
void set_properties(const PropertiesFrame &p) { memcpy(this->pbuf_ + 11, p.data() + 11, 10); }
|
|
|
|
protected:
|
|
/* POWER */
|
|
bool get_power_() const { return this->pbuf_[11] & 0x01; }
|
|
void set_power_(bool state) { this->set_bytemask_(11, 0x01, state); }
|
|
};
|
|
|
|
// Query state frame (read-only)
|
|
class QueryFrame : public midea_dongle::StaticFrame<midea_dongle::Frame> {
|
|
public:
|
|
QueryFrame() : StaticFrame(FPSTR(this->INIT)) {}
|
|
|
|
private:
|
|
static const uint8_t PROGMEM INIT[];
|
|
};
|
|
|
|
// Power query state frame (read-only)
|
|
class PowerQueryFrame : public midea_dongle::StaticFrame<midea_dongle::Frame> {
|
|
public:
|
|
PowerQueryFrame() : StaticFrame(FPSTR(this->INIT)) {}
|
|
|
|
private:
|
|
static const uint8_t PROGMEM INIT[];
|
|
};
|
|
|
|
// Command frame
|
|
class CommandFrame : public midea_dongle::StaticFrame<PropertiesFrame> {
|
|
public:
|
|
CommandFrame() : StaticFrame(FPSTR(this->INIT)) {}
|
|
void set_beeper_feedback(bool state) { this->set_bytemask_(11, 0x40, state); }
|
|
|
|
private:
|
|
static const uint8_t PROGMEM INIT[];
|
|
};
|
|
|
|
} // namespace midea_ac
|
|
} // namespace esphome
|