This commit is contained in:
J. Nick Koston 2025-07-06 13:16:49 -05:00
parent 629c891dfc
commit 8677918157
No known key found for this signature in database
20 changed files with 324 additions and 216 deletions

View File

@ -19,6 +19,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@esphome/core"]
@ -237,16 +238,18 @@ def validate_adc_pin(value):
raise NotImplementedError
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"adc_sensor_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"adc_sensor_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"adc_sensor_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"adc_sensor_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"adc_sensor_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"adc_sensor_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"adc_sensor_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"adc_sensor_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -9,6 +9,7 @@ from esphome.const import (
CONF_LOOP_TIME,
PlatformFramework,
)
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@OttoWinter"]
DEPENDENCIES = ["logger"]
@ -47,14 +48,19 @@ async def to_code(config):
await cg.register_component(var, config)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"debug_esp32.cpp": {PlatformFramework.ESP32_ARDUINO, PlatformFramework.ESP32_IDF},
"debug_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"debug_host.cpp": {PlatformFramework.HOST_NATIVE},
"debug_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"debug_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"debug_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"debug_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"debug_host.cpp": {PlatformFramework.HOST_NATIVE},
"debug_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"debug_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -29,6 +29,7 @@ from esphome.const import (
PLATFORM_ESP8266,
PlatformFramework,
)
from esphome.helpers import filter_source_files_from_platform
WAKEUP_PINS = {
VARIANT_ESP32: [
@ -316,10 +317,12 @@ async def deep_sleep_action_to_code(config, action_id, template_arg, args):
return var
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"deep_sleep_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"deep_sleep_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"deep_sleep_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"deep_sleep_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
}
)

View File

@ -17,7 +17,7 @@ from esphome.const import (
__version__,
)
from esphome.core import CORE, Lambda
from esphome.helpers import IS_MACOS
from esphome.helpers import IS_MACOS, filter_source_files_from_platform
DEPENDENCIES = ["network"]
AUTO_LOAD = ["json", "watchdog"]
@ -322,15 +322,17 @@ async def http_request_action_to_code(config, action_id, template_arg, args):
return var
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"http_request_host.cpp": {PlatformFramework.HOST_NATIVE},
"http_request_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"http_request_idf.cpp": {PlatformFramework.ESP32_IDF},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"http_request_host.cpp": {PlatformFramework.HOST_NATIVE},
"http_request_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"http_request_idf.cpp": {PlatformFramework.ESP32_IDF},
}
)

View File

@ -22,6 +22,7 @@ from esphome.const import (
)
from esphome.core import CORE, coroutine_with_priority
import esphome.final_validate as fv
from esphome.helpers import filter_source_files_from_platform
LOGGER = logging.getLogger(__name__)
CODEOWNERS = ["@esphome/core"]
@ -208,14 +209,16 @@ def final_validate_device_schema(
)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"i2c_bus_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"i2c_bus_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"i2c_bus_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"i2c_bus_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
}
)

View File

@ -24,6 +24,7 @@ from esphome.const import (
__version__,
)
from esphome.core import CORE
from esphome.helpers import filter_source_files_from_platform
from . import gpio # noqa
from .const import (
@ -343,10 +344,12 @@ async def component_to_code(config):
await cg.register_component(var, config)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"gpio_arduino.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"gpio_arduino.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -45,6 +45,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE, Lambda, coroutine_with_priority
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@esphome/core"]
logger_ns = cg.esphome_ns.namespace("logger")
@ -447,18 +448,23 @@ async def logger_set_level_to_code(config, action_id, template_arg, args):
return cg.new_Pvariable(action_id, template_arg, lambda_)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"logger_esp32.cpp": {PlatformFramework.ESP32_ARDUINO, PlatformFramework.ESP32_IDF},
"logger_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"logger_host.cpp": {PlatformFramework.HOST_NATIVE},
"logger_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"logger_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"task_log_buffer.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"logger_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"logger_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"logger_host.cpp": {PlatformFramework.HOST_NATIVE},
"logger_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"logger_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"task_log_buffer.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
}
)

View File

@ -11,6 +11,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE, coroutine_with_priority
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@esphome/core"]
DEPENDENCIES = ["network"]
@ -111,14 +112,19 @@ async def to_code(config):
cg.add(var.add_extra_service(exp))
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"mdns_esp32.cpp": {PlatformFramework.ESP32_ARDUINO, PlatformFramework.ESP32_IDF},
"mdns_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"mdns_host.cpp": {PlatformFramework.HOST_NATIVE},
"mdns_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"mdns_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"mdns_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"mdns_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"mdns_host.cpp": {PlatformFramework.HOST_NATIVE},
"mdns_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"mdns_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -57,6 +57,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE, coroutine_with_priority
from esphome.helpers import filter_source_files_from_platform
DEPENDENCIES = ["network"]
@ -599,9 +600,11 @@ async def mqtt_disable_to_code(config, action_id, template_arg, args):
return cg.new_Pvariable(action_id, template_arg, paren)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"mqtt_backend_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"mqtt_backend_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
}
)

View File

@ -1,6 +1,7 @@
import esphome.codegen as cg
from esphome.components import uart
from esphome.const import PlatformFramework
from esphome.helpers import filter_source_files_from_platform
nextion_ns = cg.esphome_ns.namespace("nextion")
Nextion = nextion_ns.class_("Nextion", cg.PollingComponent, uart.UARTDevice)
@ -10,14 +11,16 @@ CONF_NEXTION_ID = "nextion_id"
CONF_PUBLISH_STATE = "publish_state"
CONF_SEND_TO_NEXTION = "send_to_nextion"
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"nextion_upload_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"nextion_upload_idf.cpp": {PlatformFramework.ESP32_IDF},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"nextion_upload_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"nextion_upload_idf.cpp": {PlatformFramework.ESP32_IDF},
}
)

View File

@ -10,6 +10,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE, coroutine_with_priority
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@esphome/core"]
AUTO_LOAD = ["md5", "safe_mode"]
@ -123,14 +124,16 @@ async def ota_to_code(var, config):
cg.add_define("USE_OTA_STATE_CALLBACK")
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"ota_backend_arduino_esp32.cpp": {PlatformFramework.ESP32_ARDUINO},
"ota_backend_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"ota_backend_arduino_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"ota_backend_arduino_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"ota_backend_arduino_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"ota_backend_arduino_esp32.cpp": {PlatformFramework.ESP32_ARDUINO},
"ota_backend_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"ota_backend_arduino_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"ota_backend_arduino_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"ota_backend_arduino_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -18,6 +18,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE, TimePeriod
from esphome.helpers import filter_source_files_from_platform
CONF_FILTER_SYMBOLS = "filter_symbols"
CONF_RECEIVE_SYMBOLS = "receive_symbols"
@ -173,15 +174,17 @@ async def to_code(config):
cg.add(var.set_idle_us(config[CONF_IDLE]))
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"remote_receiver_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"remote_receiver_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"remote_receiver_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"remote_receiver_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"remote_receiver_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"remote_receiver_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -15,6 +15,7 @@ from esphome.const import (
PlatformFramework,
)
from esphome.core import CORE
from esphome.helpers import filter_source_files_from_platform
AUTO_LOAD = ["remote_base"]
@ -98,15 +99,17 @@ async def to_code(config):
)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"remote_transmitter_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"remote_transmitter_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"remote_transmitter_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"remote_transmitter_esp32.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
"remote_transmitter_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"remote_transmitter_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -1,5 +1,6 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
@ -40,3 +41,21 @@ async def to_code(config):
elif impl == IMPLEMENTATION_BSD_SOCKETS:
cg.add_define("USE_SOCKET_IMPL_BSD_SOCKETS")
cg.add_define("USE_SOCKET_SELECT_SUPPORT")
def FILTER_SOURCE_FILES() -> list[str]:
"""Return list of socket implementation files that aren't selected by the user."""
if not hasattr(CORE, "config") or "socket" not in CORE.config:
return []
impl = CORE.config["socket"][CONF_IMPLEMENTATION]
# Build list of files to exclude based on selected implementation
excluded = []
if impl != IMPLEMENTATION_LWIP_TCP:
excluded.append("lwip_raw_tcp_impl.cpp")
if impl != IMPLEMENTATION_BSD_SOCKETS:
excluded.append("bsd_sockets_impl.cpp")
if impl != IMPLEMENTATION_LWIP_SOCKETS:
excluded.append("lwip_sockets_impl.cpp")
return excluded

View File

@ -35,6 +35,7 @@ from esphome.const import (
)
from esphome.core import CORE, coroutine_with_priority
import esphome.final_validate as fv
from esphome.helpers import filter_source_files_from_platform
CODEOWNERS = ["@esphome/core", "@clydebarrow"]
spi_ns = cg.esphome_ns.namespace("spi")
@ -426,14 +427,16 @@ def final_validate_device_schema(name: str, *, require_mosi: bool, require_miso:
)
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"spi_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"spi_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"spi_arduino.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP8266_ARDUINO,
PlatformFramework.RP2040_ARDUINO,
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
"spi_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
}
)

View File

@ -31,6 +31,7 @@ from esphome.const import (
)
from esphome.core import CORE
import esphome.final_validate as fv
from esphome.helpers import filter_source_files_from_platform
from esphome.yaml_util import make_data_base
CODEOWNERS = ["@esphome/core"]
@ -441,15 +442,17 @@ async def uart_write_to_code(config, action_id, template_arg, args):
return var
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"uart_component_esp32_arduino.cpp": {PlatformFramework.ESP32_ARDUINO},
"uart_component_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"uart_component_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"uart_component_host.cpp": {PlatformFramework.HOST_NATIVE},
"uart_component_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"uart_component_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"uart_component_esp32_arduino.cpp": {PlatformFramework.ESP32_ARDUINO},
"uart_component_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"uart_component_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"uart_component_host.cpp": {PlatformFramework.HOST_NATIVE},
"uart_component_rp2040.cpp": {PlatformFramework.RP2040_ARDUINO},
"uart_component_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -43,6 +43,7 @@ from esphome.const import (
)
from esphome.core import CORE, HexInt, coroutine_with_priority
import esphome.final_validate as fv
from esphome.helpers import filter_source_files_from_platform
from . import wpa2_eap
@ -529,13 +530,15 @@ async def wifi_set_sta_to_code(config, action_id, template_arg, args):
return var
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"wifi_component_esp32_arduino.cpp": {PlatformFramework.ESP32_ARDUINO},
"wifi_component_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"wifi_component_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"wifi_component_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"wifi_component_esp32_arduino.cpp": {PlatformFramework.ESP32_ARDUINO},
"wifi_component_esp_idf.cpp": {PlatformFramework.ESP32_IDF},
"wifi_component_esp8266.cpp": {PlatformFramework.ESP8266_ARDUINO},
"wifi_component_libretiny.cpp": {
PlatformFramework.BK72XX_ARDUINO,
PlatformFramework.RTL87XX_ARDUINO,
PlatformFramework.LN882X_ARDUINO,
},
}
)

View File

@ -41,6 +41,7 @@ from esphome.const import (
from esphome.core import CORE, coroutine_with_priority
from esphome.helpers import (
copy_file_if_changed,
filter_source_files_from_platform,
fnv1a_32bit_hash,
get_str_env,
walk_files,
@ -555,8 +556,13 @@ async def to_code(config: ConfigType) -> None:
# Platform-specific source files for core
PLATFORM_SOURCE_FILES: dict[str, set[PlatformFramework]] = {
"ring_buffer.cpp": {PlatformFramework.ESP32_ARDUINO, PlatformFramework.ESP32_IDF},
# Note: lock_free_queue.h and event_pool.h are header files and don't need to be filtered
# as they are only included when needed by the preprocessor
}
FILTER_SOURCE_FILES = filter_source_files_from_platform(
{
"ring_buffer.cpp": {
PlatformFramework.ESP32_ARDUINO,
PlatformFramework.ESP32_IDF,
},
# Note: lock_free_queue.h and event_pool.h are header files and don't need to be filtered
# as they are only included when needed by the preprocessor
}
)

View File

@ -1,4 +1,5 @@
import codecs
from collections.abc import Callable
from contextlib import suppress
import ipaddress
import logging
@ -7,8 +8,12 @@ from pathlib import Path
import platform
import re
import tempfile
from typing import TYPE_CHECKING
from urllib.parse import urlparse
if TYPE_CHECKING:
from esphome.const import PlatformFramework
_LOGGER = logging.getLogger(__name__)
IS_MACOS = platform.system() == "Darwin"
@ -505,3 +510,54 @@ _DISALLOWED_CHARS = re.compile(r"[^a-zA-Z0-9-_]")
def sanitize(value):
"""Same behaviour as `helpers.cpp` method `str_sanitize`."""
return _DISALLOWED_CHARS.sub("_", value)
def filter_source_files_from_platform(
files_map: dict[str, set["PlatformFramework"]],
) -> Callable[[], list[str]]:
"""Helper to build a FILTER_SOURCE_FILES function from platform mapping.
Args:
files_map: Dict mapping filename to set of PlatformFramework enums
that should compile this file
Returns:
Function that returns list of files to exclude for current platform
"""
from esphome.const import (
KEY_CORE,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
PlatformFramework,
)
from esphome.core import CORE
# Pre-build lookup map from (platform, framework) tuples to PlatformFramework enum
_PLATFORM_FRAMEWORK_LOOKUP = {pf.value: pf for pf in PlatformFramework}
def filter_source_files() -> list[str]:
# Get current platform/framework
core_data = CORE.data.get(KEY_CORE, {})
target_platform = core_data.get(KEY_TARGET_PLATFORM)
target_framework = core_data.get(KEY_TARGET_FRAMEWORK)
if not target_platform or not target_framework:
return []
# Direct lookup of current PlatformFramework
current_platform_framework = _PLATFORM_FRAMEWORK_LOOKUP.get(
(target_platform, target_framework)
)
if not current_platform_framework:
return []
# Return files that should be excluded for current platform
excluded = []
for filename, platforms in files_map.items():
if current_platform_framework not in platforms:
excluded.append(filename)
return excluded
return filter_source_files

View File

@ -11,26 +11,13 @@ import sys
from types import ModuleType
from typing import Any
from esphome.const import (
KEY_CORE,
KEY_TARGET_FRAMEWORK,
KEY_TARGET_PLATFORM,
SOURCE_FILE_EXTENSIONS,
Framework,
Platform,
PlatformFramework,
)
from esphome.const import SOURCE_FILE_EXTENSIONS
from esphome.core import CORE
import esphome.core.config
from esphome.types import ConfigType
_LOGGER = logging.getLogger(__name__)
# Build unified lookup table from PlatformFramework enum
_PLATFORM_FRAMEWORK_LOOKUP: dict[
tuple[Platform, Framework | None], PlatformFramework
] = {pf.value: pf for pf in PlatformFramework}
@dataclass(frozen=True, order=True)
class FileResource:
@ -123,28 +110,13 @@ class ComponentManifest:
"""Return a list of all file resources defined in the package of this component."""
ret: list[FileResource] = []
# Get current platform-framework combination
core_data: dict[str, Any] = CORE.data.get(KEY_CORE, {})
target_platform: Platform | None = core_data.get(KEY_TARGET_PLATFORM)
target_framework: Framework | None = core_data.get(KEY_TARGET_FRAMEWORK)
# Get filter function for source files
filter_source_files_func = getattr(self.module, "FILTER_SOURCE_FILES", None)
# Get platform-specific files mapping
platform_source_files: dict[str, set[PlatformFramework]] = getattr(
self.module, "PLATFORM_SOURCE_FILES", {}
)
# Get current PlatformFramework
lookup_key = (target_platform, target_framework)
current_platform_framework: PlatformFramework | None = (
_PLATFORM_FRAMEWORK_LOOKUP.get(lookup_key)
)
# Build set of allowed filenames for current platform
allowed_filenames: set[str] = set()
if current_platform_framework and platform_source_files:
for filename, platforms in platform_source_files.items():
if current_platform_framework in platforms:
allowed_filenames.add(filename)
# Get list of files to exclude
excluded_files: set[str] = set()
if filter_source_files_func is not None:
excluded_files = set(filter_source_files_func())
# Process all resources
for resource in (
@ -157,9 +129,8 @@ class ComponentManifest:
if not importlib.resources.files(self.package).joinpath(resource).is_file():
continue
# Check platform restrictions only if file is platform-specific
# Common files (not in platform_source_files) are always included
if resource in platform_source_files and resource not in allowed_filenames:
# Skip excluded files
if resource in excluded_files:
continue
ret.append(FileResource(self.package, resource))