1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-11 22:33:49 +01:00

Merge branch 'mdns_back_compat' into integration

This commit is contained in:
J. Nick Koston
2025-10-09 22:48:05 -10:00
22 changed files with 69 additions and 131 deletions

View File

@@ -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],

View File

@@ -7,7 +7,7 @@
#include "opentherm.h"
#include "esphome/core/helpers.h"
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
#include "driver/timer.h"
#include "esp_err.h"
#endif
@@ -31,7 +31,7 @@ OpenTherm *OpenTherm::instance = nullptr;
OpenTherm::OpenTherm(InternalGPIOPin *in_pin, InternalGPIOPin *out_pin, int32_t device_timeout)
: in_pin_(in_pin),
out_pin_(out_pin),
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
timer_group_(TIMER_GROUP_0),
timer_idx_(TIMER_0),
#endif
@@ -57,7 +57,7 @@ bool OpenTherm::initialize() {
this->out_pin_->setup();
this->out_pin_->digital_write(true);
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
return this->init_esp32_timer_();
#else
return true;
@@ -238,7 +238,7 @@ void IRAM_ATTR OpenTherm::write_bit_(uint8_t high, uint8_t clock) {
}
}
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
bool OpenTherm::init_esp32_timer_() {
// Search for a free timer. Maybe unstable, we'll see.
@@ -365,7 +365,7 @@ void IRAM_ATTR OpenTherm::stop_timer_() {
}
}
#endif // END ESP32
#endif // USE_ESP32
#ifdef ESP8266
// 5 kHz timer_

View File

@@ -12,7 +12,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
#include "driver/timer.h"
#endif
@@ -356,7 +356,7 @@ class OpenTherm {
ISRInternalGPIOPin isr_in_pin_;
ISRInternalGPIOPin isr_out_pin_;
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
timer_group_t timer_group_;
timer_idx_t timer_idx_;
#endif
@@ -370,7 +370,7 @@ class OpenTherm {
int32_t timeout_counter_; // <0 no timeout
int32_t device_timeout_;
#if defined(ESP32) || defined(USE_ESP_IDF)
#ifdef USE_ESP32
esp_err_t timer_error_ = ESP_OK;
TimerErrorType timer_error_type_ = TimerErrorType::NO_TIMER_ERROR;

View File

@@ -1,5 +0,0 @@
substitutions:
gate_pin: GPIO5
zero_cross_pin: GPIO4
<<: !include common.yaml

View File

@@ -1,6 +0,0 @@
substitutions:
tx_pin: GPIO4
rx_pin: GPIO5
request_pin: GPIO6
<<: !include common.yaml

View File

@@ -1,4 +0,0 @@
substitutions:
pin: GPIO2
<<: !include common.yaml

View File

@@ -1,4 +0,0 @@
substitutions:
verify_ssl: "false"
<<: !include common.yaml

View File

@@ -1,5 +0,0 @@
substitutions:
scl_pin: GPIO5
sda_pin: GPIO4
<<: !include common.yaml

View File

@@ -1,6 +0,0 @@
substitutions:
tx_pin: GPIO4
rx_pin: GPIO5
pin: GPIO2
<<: !include common.yaml

View File

@@ -1,19 +0,0 @@
light:
- platform: neopixelbus
id: addr3
name: Neopixelbus Light
gamma_correct: 2.8
color_correct: [0.0, 0.0, 0.0, 0.0]
default_transition_length: 10s
effects:
- addressable_flicker:
name: Flicker Effect With Custom Values
update_interval: 16ms
intensity: 5%
type: GRBW
variant: SK6812
method:
type: esp32_rmt
channel: 0
num_leds: 5
pin: 4

View File

@@ -1,10 +0,0 @@
substitutions:
tx_pin: GPIO4
rx_pin: GPIO5
packages:
base: !include common.yaml
display:
- id: !extend main_lcd
tft_url: http://esphome.io/default35.tft

View File

@@ -1 +0,0 @@
<<: !include common.yaml

View File

@@ -1,9 +0,0 @@
substitutions:
scl_pin: GPIO5
sda_pin: GPIO4
i2s_bclk_pin: GPIO7
i2s_lrclk_pin: GPIO6
i2s_mclk_pin: GPIO9
i2s_dout_pin: GPIO8
<<: !include common-audio_dac.yaml

View File

@@ -1,9 +0,0 @@
substitutions:
scl_pin: GPIO5
sda_pin: GPIO4
i2s_bclk_pin: GPIO7
i2s_lrclk_pin: GPIO6
i2s_mclk_pin: GPIO9
i2s_dout_pin: GPIO8
<<: !include common.yaml

View File

@@ -1,6 +0,0 @@
substitutions:
clk_pin: GPIO6
mosi_pin: GPIO7
miso_pin: GPIO5
<<: !include common.yaml

View File

@@ -1 +0,0 @@
<<: !include common_v2.yaml

View File

@@ -1,16 +0,0 @@
wifi:
ssid: MySSID
password: password1
wled:
light:
- platform: esp32_rmt_led_strip
id: led_matrix_32x8
default_transition_length: 500ms
chipset: ws2812
rgb_order: GRB
num_leds: 256
pin: 2
effects:
- wled: