From 3ca00152847d37e205ac2464eded443fd3d87b31 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 21 Aug 2025 18:48:48 +1200 Subject: [PATCH 1/3] [opentherm] Rename c++ files for predictable doxygen generation (#10314) --- esphome/components/opentherm/hub.h | 12 ++++++------ .../number/{number.cpp => opentherm_number.cpp} | 2 +- .../number/{number.h => opentherm_number.h} | 0 .../output/{output.cpp => opentherm_output.cpp} | 2 +- .../output/{output.h => opentherm_output.h} | 0 .../switch/{switch.cpp => opentherm_switch.cpp} | 2 +- .../switch/{switch.h => opentherm_switch.h} | 0 7 files changed, 9 insertions(+), 9 deletions(-) rename esphome/components/opentherm/number/{number.cpp => opentherm_number.cpp} (97%) rename esphome/components/opentherm/number/{number.h => opentherm_number.h} (100%) rename esphome/components/opentherm/output/{output.cpp => opentherm_output.cpp} (95%) rename esphome/components/opentherm/output/{output.h => opentherm_output.h} (100%) rename esphome/components/opentherm/switch/{switch.cpp => opentherm_switch.cpp} (96%) rename esphome/components/opentherm/switch/{switch.h => opentherm_switch.h} (100%) diff --git a/esphome/components/opentherm/hub.h b/esphome/components/opentherm/hub.h index 80fd268820..ee0cfd104d 100644 --- a/esphome/components/opentherm/hub.h +++ b/esphome/components/opentherm/hub.h @@ -1,10 +1,10 @@ #pragma once +#include +#include "esphome/core/component.h" #include "esphome/core/defines.h" #include "esphome/core/hal.h" -#include "esphome/core/component.h" #include "esphome/core/log.h" -#include #include "opentherm.h" @@ -17,21 +17,21 @@ #endif #ifdef OPENTHERM_USE_SWITCH -#include "esphome/components/opentherm/switch/switch.h" +#include "esphome/components/opentherm/switch/opentherm_switch.h" #endif #ifdef OPENTHERM_USE_OUTPUT -#include "esphome/components/opentherm/output/output.h" +#include "esphome/components/opentherm/output/opentherm_output.h" #endif #ifdef OPENTHERM_USE_NUMBER -#include "esphome/components/opentherm/number/number.h" +#include "esphome/components/opentherm/number/opentherm_number.h" #endif +#include #include #include #include -#include #include "opentherm_macros.h" diff --git a/esphome/components/opentherm/number/number.cpp b/esphome/components/opentherm/number/opentherm_number.cpp similarity index 97% rename from esphome/components/opentherm/number/number.cpp rename to esphome/components/opentherm/number/opentherm_number.cpp index 90ab5d6490..c5d094aa36 100644 --- a/esphome/components/opentherm/number/number.cpp +++ b/esphome/components/opentherm/number/opentherm_number.cpp @@ -1,4 +1,4 @@ -#include "number.h" +#include "opentherm_number.h" namespace esphome { namespace opentherm { diff --git a/esphome/components/opentherm/number/number.h b/esphome/components/opentherm/number/opentherm_number.h similarity index 100% rename from esphome/components/opentherm/number/number.h rename to esphome/components/opentherm/number/opentherm_number.h diff --git a/esphome/components/opentherm/output/output.cpp b/esphome/components/opentherm/output/opentherm_output.cpp similarity index 95% rename from esphome/components/opentherm/output/output.cpp rename to esphome/components/opentherm/output/opentherm_output.cpp index 486aa0d4e7..ff82ddd72c 100644 --- a/esphome/components/opentherm/output/output.cpp +++ b/esphome/components/opentherm/output/opentherm_output.cpp @@ -1,5 +1,5 @@ #include "esphome/core/helpers.h" // for clamp() and lerp() -#include "output.h" +#include "opentherm_output.h" namespace esphome { namespace opentherm { diff --git a/esphome/components/opentherm/output/output.h b/esphome/components/opentherm/output/opentherm_output.h similarity index 100% rename from esphome/components/opentherm/output/output.h rename to esphome/components/opentherm/output/opentherm_output.h diff --git a/esphome/components/opentherm/switch/switch.cpp b/esphome/components/opentherm/switch/opentherm_switch.cpp similarity index 96% rename from esphome/components/opentherm/switch/switch.cpp rename to esphome/components/opentherm/switch/opentherm_switch.cpp index 228d9ac8f3..5c5d62e68e 100644 --- a/esphome/components/opentherm/switch/switch.cpp +++ b/esphome/components/opentherm/switch/opentherm_switch.cpp @@ -1,4 +1,4 @@ -#include "switch.h" +#include "opentherm_switch.h" namespace esphome { namespace opentherm { diff --git a/esphome/components/opentherm/switch/switch.h b/esphome/components/opentherm/switch/opentherm_switch.h similarity index 100% rename from esphome/components/opentherm/switch/switch.h rename to esphome/components/opentherm/switch/opentherm_switch.h From 94accd5abe8d70713f3b4db7809e4b47824e7ce4 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 21 Aug 2025 18:49:26 +1200 Subject: [PATCH 2/3] [ld2420] Rename c++ files for predictable doxygen generation (#10315) --- .../text_sensor/{text_sensor.cpp => ld2420_text_sensor.cpp} | 2 +- .../ld2420/text_sensor/{text_sensor.h => ld2420_text_sensor.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename esphome/components/ld2420/text_sensor/{text_sensor.cpp => ld2420_text_sensor.cpp} (91%) rename esphome/components/ld2420/text_sensor/{text_sensor.h => ld2420_text_sensor.h} (100%) diff --git a/esphome/components/ld2420/text_sensor/text_sensor.cpp b/esphome/components/ld2420/text_sensor/ld2420_text_sensor.cpp similarity index 91% rename from esphome/components/ld2420/text_sensor/text_sensor.cpp rename to esphome/components/ld2420/text_sensor/ld2420_text_sensor.cpp index 73af3b3660..f647a36936 100644 --- a/esphome/components/ld2420/text_sensor/text_sensor.cpp +++ b/esphome/components/ld2420/text_sensor/ld2420_text_sensor.cpp @@ -1,4 +1,4 @@ -#include "text_sensor.h" +#include "ld2420_text_sensor.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" diff --git a/esphome/components/ld2420/text_sensor/text_sensor.h b/esphome/components/ld2420/text_sensor/ld2420_text_sensor.h similarity index 100% rename from esphome/components/ld2420/text_sensor/text_sensor.h rename to esphome/components/ld2420/text_sensor/ld2420_text_sensor.h From 2f101c0a202bb1f58ee4caac8e33021a0ac8e415 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 21 Aug 2025 08:11:17 -0500 Subject: [PATCH 3/3] [esp32_ble_client] Adjust connection parameters to improve device compatibility --- .../esp32_ble_client/ble_client_base.cpp | 69 ++++++++----------- .../esp32_ble_client/ble_client_base.h | 3 +- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index e23be2e0c1..040e3db613 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -111,36 +111,8 @@ void BLEClientBase::connect() { this->remote_addr_type_); this->paired_ = false; - // Set preferred connection parameters before connecting - // Use FAST for all V3 connections (better latency and reliability) - // Use MEDIUM for V1/legacy connections (balanced performance) - uint16_t min_interval, max_interval, timeout; - const char *param_type; - - if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE || - this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) { - min_interval = FAST_MIN_CONN_INTERVAL; - max_interval = FAST_MAX_CONN_INTERVAL; - timeout = FAST_CONN_TIMEOUT; - param_type = "fast"; - } else { - min_interval = MEDIUM_MIN_CONN_INTERVAL; - max_interval = MEDIUM_MAX_CONN_INTERVAL; - timeout = MEDIUM_CONN_TIMEOUT; - param_type = "medium"; - } - - auto param_ret = esp_ble_gap_set_prefer_conn_params(this->remote_bda_, min_interval, max_interval, - 0, // latency: 0 - timeout); - if (param_ret != ESP_OK) { - ESP_LOGW(TAG, "[%d] [%s] esp_ble_gap_set_prefer_conn_params failed: %d", this->connection_index_, - this->address_str_.c_str(), param_ret); - } else { - this->log_connection_params_(param_type); - } - - // Now open the connection + // Open the connection without setting connection parameters + // Parameters will be set after connection is established if needed auto ret = esp_ble_gattc_open(this->gattc_if_, this->remote_bda_, this->remote_addr_type_, true); if (ret) { this->log_gattc_warning_("esp_ble_gattc_open", ret); @@ -243,8 +215,21 @@ void BLEClientBase::log_warning_(const char *message) { ESP_LOGW(TAG, "[%d] [%s] %s", this->connection_index_, this->address_str_.c_str(), message); } -void BLEClientBase::restore_medium_conn_params_() { - // Restore to medium connection parameters after initial connection phase +void BLEClientBase::set_fast_conn_params_() { + // Switch to fast connection parameters for service discovery + // This improves discovery speed for devices with short timeouts + esp_ble_conn_update_params_t conn_params = {{0}}; + memcpy(conn_params.bda, this->remote_bda_, sizeof(esp_bd_addr_t)); + conn_params.min_int = FAST_MIN_CONN_INTERVAL; + conn_params.max_int = FAST_MAX_CONN_INTERVAL; + conn_params.latency = 0; + conn_params.timeout = FAST_CONN_TIMEOUT; + this->log_connection_params_("fast"); + esp_ble_gap_update_conn_params(&conn_params); +} + +void BLEClientBase::set_medium_conn_params_() { + // Set medium connection parameters for balanced performance // This balances performance with bandwidth usage for normal operation esp_ble_conn_update_params_t conn_params = {{0}}; memcpy(conn_params.bda, this->remote_bda_, sizeof(esp_bd_addr_t)); @@ -308,12 +293,19 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ this->set_state(espbt::ClientState::CONNECTED); ESP_LOGI(TAG, "[%d] [%s] Connection open", this->connection_index_, this->address_str_.c_str()); if (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) { - // Restore to medium connection parameters for cached connections too - this->restore_medium_conn_params_(); + // Cached connections use medium connection parameters + this->set_medium_conn_params_(); // only set our state, subclients might have more stuff to do yet. this->state_ = espbt::ClientState::ESTABLISHED; break; } + // For V3_WITHOUT_CACHE, switch to fast params for service discovery + // Service discovery period is critical - we typically have only 10s to complete + // discovery before the device disconnects us. Fast connection parameters are + // essential to finish service resolution in time and avoid retry loops. + if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE) { + this->set_fast_conn_params_(); + } this->log_event_("Searching for services"); esp_ble_gattc_search_service(esp_gattc_if, param->cfg_mtu.conn_id, nullptr); break; @@ -395,12 +387,11 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ if (this->conn_id_ != param->search_cmpl.conn_id) return false; this->log_gattc_event_("SEARCH_CMPL"); - // For V3 connections, restore to medium connection parameters after service discovery + // For V3_WITHOUT_CACHE, switch back to medium connection parameters after service discovery // This balances performance with bandwidth usage after the critical discovery phase - if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE || - this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) { - this->restore_medium_conn_params_(); - } else { + if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE) { + this->set_medium_conn_params_(); + } else if (this->connection_type_ != espbt::ConnectionType::V3_WITH_CACHE) { #ifdef USE_ESP32_BLE_DEVICE for (auto &svc : this->services_) { ESP_LOGV(TAG, "[%d] [%s] Service UUID: %s", this->connection_index_, this->address_str_.c_str(), diff --git a/esphome/components/esp32_ble_client/ble_client_base.h b/esphome/components/esp32_ble_client/ble_client_base.h index 1850b2c5b3..2bfa0f6759 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.h +++ b/esphome/components/esp32_ble_client/ble_client_base.h @@ -133,7 +133,8 @@ class BLEClientBase : public espbt::ESPBTClient, public Component { void log_event_(const char *name); void log_gattc_event_(const char *name); - void restore_medium_conn_params_(); + void set_fast_conn_params_(); + void set_medium_conn_params_(); void log_gattc_warning_(const char *operation, esp_gatt_status_t status); void log_gattc_warning_(const char *operation, esp_err_t err); void log_connection_params_(const char *param_type);