From 0b34c977425a417869fec5c5dfbd8520ec2d4663 Mon Sep 17 00:00:00 2001 From: ShaTie <52978334+ShaTie@users.noreply.github.com> Date: Tue, 4 Aug 2026 02:21:27 +0300 Subject: [PATCH] [midea] Add ESP-IDF framework support (#12646) Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 --- esphome/components/midea/ac_adapter.cpp | 4 ++-- esphome/components/midea/ac_adapter.h | 4 ++-- esphome/components/midea/ac_automations.h | 4 ++-- esphome/components/midea/air_conditioner.cpp | 4 ++-- esphome/components/midea/air_conditioner.h | 4 ++-- esphome/components/midea/appliance_base.h | 5 +++-- esphome/components/midea/climate.py | 14 ++++++++++---- esphome/components/midea/ir_transmitter.h | 6 +++--- platformio.ini | 2 +- tests/components/midea/common.yaml | 4 ---- tests/components/midea/test.esp32-ard.yaml | 5 ++++- tests/components/midea/test.esp32-h2-idf.yaml | 5 +++++ tests/components/midea/test.esp32-idf.yaml | 8 ++++++++ tests/components/midea/test.esp8266-ard.yaml | 5 ++++- .../common/uart/esp32-h2-idf.yaml | 13 +++++++++++++ 15 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 tests/components/midea/test.esp32-h2-idf.yaml create mode 100644 tests/components/midea/test.esp32-idf.yaml create mode 100644 tests/test_build_components/common/uart/esp32-h2-idf.yaml diff --git a/esphome/components/midea/ac_adapter.cpp b/esphome/components/midea/ac_adapter.cpp index 77bb9bbe86..30771d25ca 100644 --- a/esphome/components/midea/ac_adapter.cpp +++ b/esphome/components/midea/ac_adapter.cpp @@ -1,4 +1,4 @@ -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) #include "esphome/core/log.h" #include "ac_adapter.h" @@ -172,4 +172,4 @@ void Converters::to_climate_traits(ClimateTraits &traits, const dudanov::midea:: } // namespace esphome::midea::ac -#endif // USE_ARDUINO +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/esphome/components/midea/ac_adapter.h b/esphome/components/midea/ac_adapter.h index 4545743564..4a888ee8ff 100644 --- a/esphome/components/midea/ac_adapter.h +++ b/esphome/components/midea/ac_adapter.h @@ -1,6 +1,6 @@ #pragma once -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) // MideaUART #include @@ -44,4 +44,4 @@ class Converters { } // namespace esphome::midea::ac -#endif // USE_ARDUINO +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/esphome/components/midea/ac_automations.h b/esphome/components/midea/ac_automations.h index b595a018b3..9572ec6c65 100644 --- a/esphome/components/midea/ac_automations.h +++ b/esphome/components/midea/ac_automations.h @@ -1,6 +1,6 @@ #pragma once -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) #include "esphome/core/automation.h" #include "air_conditioner.h" @@ -63,4 +63,4 @@ template class PowerToggleAction : public MideaActionBase } // namespace esphome::midea::ac -#endif // USE_ARDUINO +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index e55afedd8a..24bbfe76b0 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -1,4 +1,4 @@ -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) #include "esphome/core/helpers.h" #include "esphome/core/log.h" @@ -197,4 +197,4 @@ void AirConditioner::do_display_toggle() { } // namespace esphome::midea::ac -#endif // USE_ARDUINO +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/esphome/components/midea/air_conditioner.h b/esphome/components/midea/air_conditioner.h index 089928902e..9977d2088f 100644 --- a/esphome/components/midea/air_conditioner.h +++ b/esphome/components/midea/air_conditioner.h @@ -1,6 +1,6 @@ #pragma once -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) // MideaUART #include @@ -61,4 +61,4 @@ class AirConditioner final : public ApplianceBase #include +#include // Include global defines #include "esphome/core/defines.h" @@ -99,4 +100,4 @@ template class ApplianceBase : public Component { } // namespace esphome::midea -#endif // USE_ARDUINO +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/esphome/components/midea/climate.py b/esphome/components/midea/climate.py index b0c102af6d..292e7215a9 100644 --- a/esphome/components/midea/climate.py +++ b/esphome/components/midea/climate.py @@ -153,7 +153,6 @@ CONFIG_SCHEMA = cv.All( ) .extend(uart.UART_DEVICE_SCHEMA) .extend(cv.COMPONENT_SCHEMA), - cv.only_with_arduino, cv.only_on( [ PLATFORM_ESP32, @@ -305,7 +304,14 @@ async def to_code(config): if CONF_HUMIDITY_SETPOINT in config: sens = await sensor.new_sensor(config[CONF_HUMIDITY_SETPOINT]) cg.add(var.set_humidity_setpoint_sensor(sens)) - # MideaUART library requires WiFi (WiFi auto-enables Network via dependency mapping) - if CORE.is_esp32: + # MideaUART uses the Arduino WiFi API for the network-notify frame + # (WiFi auto-enables Network via dependency mapping). On ESP-IDF the + # library talks to esp_wifi directly, so no library entry is needed. + if CORE.is_esp32 and CORE.using_arduino: cg.add_library("WiFi", None) - cg.add_library("dudanov/MideaUART", "1.1.9") + # Using the repository until a release containing ESP-IDF support is published + cg.add_library( + name="MideaUART", + version=None, + repository="https://github.com/dudanov/MideaUART.git#7a4d1e9a4b6f07a3464c2453ee828c0c7b7e1bcf", + ) diff --git a/esphome/components/midea/ir_transmitter.h b/esphome/components/midea/ir_transmitter.h index ecf3fa1c1a..e54df1fd70 100644 --- a/esphome/components/midea/ir_transmitter.h +++ b/esphome/components/midea/ir_transmitter.h @@ -1,6 +1,6 @@ #pragma once -#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY) +#if (defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)) || defined(USE_ESP_IDF) #ifdef USE_REMOTE_TRANSMITTER #include "esphome/components/remote_base/midea_protocol.h" @@ -85,5 +85,5 @@ class IrTransmitter { } // namespace esphome::midea -#endif -#endif // USE_ARDUINO +#endif // USE_REMOTE_TRANSMITTER +#endif // USE_ARDUINO || USE_ESP_IDF diff --git a/platformio.ini b/platformio.ini index 9f2ac74ac0..df5c22492c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,6 +44,7 @@ lib_deps_base = lib_deps = ${common.lib_deps_base} + https://github.com/dudanov/MideaUART.git#7a4d1e9a4b6f07a3464c2453ee828c0c7b7e1bcf ; midea esphome/noise-c@0.1.11 ; api improv/Improv@1.2.6 ; improv_serial / esp32_improv kikuchan98/pngle@1.1.0 ; online_image @@ -80,7 +81,6 @@ lib_deps = Wire ; i2c (Arduino built-int) heman/AsyncMqttClient-esphome@1.0.0 ; mqtt freekode/TM1651@1.0.1 ; tm1651 - dudanov/MideaUART@1.1.9 ; midea tonia/HeatpumpIR@1.0.42 ; heatpumpir build_flags = ${common.build_flags} diff --git a/tests/components/midea/common.yaml b/tests/components/midea/common.yaml index c7b18a6701..25fc2debcd 100644 --- a/tests/components/midea/common.yaml +++ b/tests/components/midea/common.yaml @@ -1,7 +1,3 @@ -wifi: - ssid: MySSID - password: password1 - climate: - platform: midea id: midea_unit diff --git a/tests/components/midea/test.esp32-ard.yaml b/tests/components/midea/test.esp32-ard.yaml index 1e3fe0ff51..17ced80477 100644 --- a/tests/components/midea/test.esp32-ard.yaml +++ b/tests/components/midea/test.esp32-ard.yaml @@ -1,5 +1,8 @@ packages: remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-ard.yaml uart: !include ../../test_build_components/common/uart/esp32-ard.yaml + midea: !include common.yaml -<<: !include common.yaml +wifi: + ssid: MySSID + password: password1 diff --git a/tests/components/midea/test.esp32-h2-idf.yaml b/tests/components/midea/test.esp32-h2-idf.yaml new file mode 100644 index 0000000000..45b73dc6c7 --- /dev/null +++ b/tests/components/midea/test.esp32-h2-idf.yaml @@ -0,0 +1,5 @@ +# ESP32-H2 has no WiFi PHY; this verifies the component builds without wifi +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + uart: !include ../../test_build_components/common/uart/esp32-h2-idf.yaml + midea: !include common.yaml diff --git a/tests/components/midea/test.esp32-idf.yaml b/tests/components/midea/test.esp32-idf.yaml new file mode 100644 index 0000000000..ae12002b31 --- /dev/null +++ b/tests/components/midea/test.esp32-idf.yaml @@ -0,0 +1,8 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + uart: !include ../../test_build_components/common/uart/esp32-idf.yaml + midea: !include common.yaml + +wifi: + ssid: MySSID + password: password1 diff --git a/tests/components/midea/test.esp8266-ard.yaml b/tests/components/midea/test.esp8266-ard.yaml index 9825ff85a1..70a0b00105 100644 --- a/tests/components/midea/test.esp8266-ard.yaml +++ b/tests/components/midea/test.esp8266-ard.yaml @@ -1,5 +1,8 @@ packages: remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml + midea: !include common.yaml -<<: !include common.yaml +wifi: + ssid: MySSID + password: password1 diff --git a/tests/test_build_components/common/uart/esp32-h2-idf.yaml b/tests/test_build_components/common/uart/esp32-h2-idf.yaml new file mode 100644 index 0000000000..51d45fe6d5 --- /dev/null +++ b/tests/test_build_components/common/uart/esp32-h2-idf.yaml @@ -0,0 +1,13 @@ +# Common UART configuration for ESP32-H2 IDF tests +# Provides a shared UART bus that components can use +# Components will auto-use this bus if they don't specify uart_id + +substitutions: + tx_pin: GPIO12 + rx_pin: GPIO13 + +uart: + - id: uart_bus + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + baud_rate: 9600