From 5b146e1f1212d270f61d4e87958fb67618b9ec98 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 9 Oct 2025 10:39:41 -1000 Subject: [PATCH 1/2] fix --- esphome/components/esp32_ble/ble.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index 3139e3f8ab..41a90150ef 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -15,6 +15,10 @@ #include #include +#ifdef USE_ARDUINO +#include +#endif + namespace esphome::esp32_ble { static const char *const TAG = "esp32_ble"; @@ -136,6 +140,12 @@ void ESP32BLE::advertising_init_() { bool ESP32BLE::ble_setup_() { esp_err_t err; +#ifdef USE_ARDUINO + if (!btStart()) { + ESP_LOGE(TAG, "btStart failed: %d", esp_bt_controller_get_status()); + return false; + } +#else if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { // start bt controller if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) { @@ -160,6 +170,7 @@ bool ESP32BLE::ble_setup_() { return false; } } +#endif esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); @@ -251,6 +262,12 @@ bool ESP32BLE::ble_dismantle_() { return false; } +#ifdef USE_ARDUINO + if (!btStop()) { + ESP_LOGE(TAG, "btStop failed: %d", esp_bt_controller_get_status()); + return false; + } +#else if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) { // stop bt controller if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) { @@ -274,6 +291,7 @@ bool ESP32BLE::ble_dismantle_() { return false; } } +#endif return true; } From cdc87a44456fc813a4f195410b125ea86723245d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 9 Oct 2025 22:46:45 -1000 Subject: [PATCH 2/2] [mdns] Restore mdns_txt_record() public API for external components --- esphome/components/mdns/__init__.py | 83 +++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/esphome/components/mdns/__init__.py b/esphome/components/mdns/__init__.py index 6e148092fe..25c004ac5d 100644 --- a/esphome/components/mdns/__init__.py +++ b/esphome/components/mdns/__init__.py @@ -11,7 +11,7 @@ from esphome.const import ( CONF_SERVICES, PlatformFramework, ) -from esphome.core import CORE, coroutine_with_priority +from esphome.core import CORE, Lambda, coroutine_with_priority from esphome.coroutine import CoroPriority CODEOWNERS = ["@esphome/core"] @@ -58,9 +58,64 @@ CONFIG_SCHEMA = cv.All( ) +def mdns_txt_record(key: str, value: str) -> cg.RawExpression: + """Create a mDNS TXT record. + + Public API for external components. Do not remove. + + Args: + key: The TXT record key + value: The TXT record value (static string only) + + Returns: + A RawExpression representing a MDNSTXTRecord struct + """ + return cg.RawExpression( + f"{{MDNS_STR({cg.safe_exp(key)}), MDNS_STR({cg.safe_exp(value)})}}" + ) + + +async def _mdns_txt_record_templated( + mdns_comp: cg.Pvariable, key: str, value: Lambda | str +) -> cg.RawExpression: + """Create a mDNS TXT record with support for templated values. + + Internal helper function. + + Args: + mdns_comp: The MDNSComponent instance (from cg.get_variable()) + key: The TXT record key + value: The TXT record value (can be a static string or a lambda template) + + Returns: + A RawExpression representing a MDNSTXTRecord struct + """ + if not cg.is_template(value): + # It's a static string - use directly in flash, no need to store in vector + return mdns_txt_record(key, value) + # It's a lambda - evaluate and store using helper + templated_value = await cg.templatable(value, [], cg.std_string) + safe_key = cg.safe_exp(key) + dynamic_call = f"{mdns_comp}->add_dynamic_txt_value(({templated_value})())" + return cg.RawExpression(f"{{MDNS_STR({safe_key}), MDNS_STR({dynamic_call})}}") + + def mdns_service( service: str, proto: str, port: int, txt_records: list[dict[str, str]] -): +) -> cg.StructInitializer: + """Create a mDNS service. + + Public API for external components. Do not remove. + + Args: + service: Service name (e.g., "_http") + proto: Protocol (e.g., "_tcp" or "_udp") + port: Port number + txt_records: List of MDNSTXTRecord expressions + + Returns: + A StructInitializer representing a MDNSService struct + """ return cg.StructInitializer( MDNSService, ("service_type", cg.RawExpression(f"MDNS_STR({cg.safe_exp(service)})")), @@ -120,26 +175,10 @@ async def to_code(config): await cg.register_component(var, config) for service in config[CONF_SERVICES]: - # Build the txt records list for the service - txt_records = [] - for txt_key, txt_value in service[CONF_TXT].items(): - if cg.is_template(txt_value): - # It's a lambda - evaluate and store using helper - templated_value = await cg.templatable(txt_value, [], cg.std_string) - safe_key = cg.safe_exp(txt_key) - dynamic_call = f"{var}->add_dynamic_txt_value(({templated_value})())" - txt_records.append( - cg.RawExpression( - f"{{MDNS_STR({safe_key}), MDNS_STR({dynamic_call})}}" - ) - ) - else: - # It's a static string - use directly in flash, no need to store in vector - txt_records.append( - cg.RawExpression( - f"{{MDNS_STR({cg.safe_exp(txt_key)}), MDNS_STR({cg.safe_exp(txt_value)})}}" - ) - ) + txt_records = [ + await _mdns_txt_record_templated(var, txt_key, txt_value) + for txt_key, txt_value in service[CONF_TXT].items() + ] exp = mdns_service( service[CONF_SERVICE],