Compare commits

..
18 changed files with 186 additions and 116 deletions

No files matched your search

+1 -1
View File
@@ -181,7 +181,7 @@ _IDF6_ETHERNET_COMPONENTS: dict[str, IDFRegistryComponent] = {
"IP101": IDFRegistryComponent("espressif/ip101", "1.1.0"),
"KSZ8081": IDFRegistryComponent("espressif/ksz80xx", "1.1.0"),
"KSZ8081RNA": IDFRegistryComponent("espressif/ksz80xx", "1.1.0"),
"W5500": IDFRegistryComponent("espressif/w5500", "1.0.1"),
"W5500": IDFRegistryComponent("espressif/w5500", "2.0.1"),
"DM9051": IDFRegistryComponent("espressif/dm9051", "1.1.1"),
"ENC28J60": IDFRegistryComponent("espressif/enc28j60", "1.1.0"),
"LAN8670": IDFRegistryComponent("espressif/lan867x", "2.1.0"),
@@ -286,9 +286,16 @@ void EthernetComponent::ethernet_lazy_init_() {
#endif
#if defined(USE_ETHERNET_W5500)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
w5500_config.base.int_gpio_num = this->interrupt_pin_;
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
w5500_config.base.poll_period_ms = this->polling_interval_;
#endif
#else
w5500_config.int_gpio_num = this->interrupt_pin_;
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
w5500_config.poll_period_ms = this->polling_interval_;
#endif
#endif
// Install the custom SPI driver that offloads the bulk RX/TX frame transfers off the busy-wait
// path. w5500_config (and the devcfg it references) outlives esp_eth_mac_new_w5500() below, which
@@ -32,10 +32,16 @@ void *w5500_custom_spi_init(const void *spi_config) {
auto *ctx = &w5500_context;
// The W5500 SPI frame carries the 16-bit address in the command phase and the 8-bit control
// byte in the address phase; mirror what the stock driver configures.
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
spi_device_interface_config_t devcfg = *config->base.spi_devcfg;
const spi_host_device_t spi_host_id = config->base.spi_host_id;
#else
spi_device_interface_config_t devcfg = *config->spi_devcfg;
const spi_host_device_t spi_host_id = config->spi_host_id;
#endif
devcfg.command_bits = 16;
devcfg.address_bits = 8;
if (spi_bus_add_device(config->spi_host_id, &devcfg, &ctx->handle) != ESP_OK) {
if (spi_bus_add_device(spi_host_id, &devcfg, &ctx->handle) != ESP_OK) {
ctx->handle = nullptr;
return nullptr;
}
@@ -107,11 +113,19 @@ void install_w5500_async_spi(eth_w5500_config_t &config) {
// Point the custom driver's config at the W5500 config itself; init() reads spi_host_id and
// spi_devcfg back out of it. The self-reference is valid because both the config and the
// spi_devcfg it points at outlive the esp_eth_mac_new_w5500() call that runs init().
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
config.base.custom_spi_driver.config = &config;
config.base.custom_spi_driver.init = w5500_custom_spi_init;
config.base.custom_spi_driver.deinit = w5500_custom_spi_deinit;
config.base.custom_spi_driver.read = w5500_custom_spi_read;
config.base.custom_spi_driver.write = w5500_custom_spi_write;
#else
config.custom_spi_driver.config = &config;
config.custom_spi_driver.init = w5500_custom_spi_init;
config.custom_spi_driver.deinit = w5500_custom_spi_deinit;
config.custom_spi_driver.read = w5500_custom_spi_read;
config.custom_spi_driver.write = w5500_custom_spi_write;
#endif
}
} // namespace esphome::ethernet
+21 -7
View File
@@ -1,3 +1,5 @@
import logging
from esphome import pins
import esphome.codegen as cg
from esphome.components import light
@@ -35,6 +37,8 @@ from ._methods import (
)
from .const import CHIP_TYPES, CONF_ASYNC, CONF_BUS, ONE_WIRE_CHIPS
_LOGGER = logging.getLogger(__name__)
neopixelbus_ns = cg.esphome_ns.namespace("neopixelbus")
NeoPixelBusLightOutputBase = neopixelbus_ns.class_(
"NeoPixelBusLightOutputBase", light.AddressableLight
@@ -135,12 +139,13 @@ def _validate(config):
return config
def _reject_esp32(config: ConfigType) -> ConfigType:
def _warn_esp32_deprecated(config: ConfigType) -> ConfigType:
if CORE.is_esp32:
raise cv.Invalid(
"'neopixelbus' is no longer supported on ESP32. Use the "
"'esp32_rmt_led_strip' light platform instead: "
"https://esphome.io/components/light/esp32_rmt_led_strip/"
_LOGGER.warning(
"'neopixelbus' on ESP32 is deprecated. The upstream library "
"(makuna/NeoPixelBus) is no longer actively maintained. Migrate "
"to 'esp32_rmt_led_strip'. Removal is targeted for 2027.1 but "
"may happen sooner once ESPHome moves to ESP-IDF 6."
)
return config
@@ -178,10 +183,18 @@ def _validate_method(value):
CONFIG_SCHEMA = cv.All(
_reject_esp32,
cv.only_with_framework(frameworks=Framework.ARDUINO),
cv.only_with_framework(
frameworks=Framework.ARDUINO,
suggestions={
Framework.ESP_IDF: (
"esp32_rmt_led_strip",
"light/esp32_rmt_led_strip",
)
},
),
cv.require_framework_version(
esp8266_arduino=cv.Version(2, 4, 0),
esp32_arduino=cv.Version(0, 0, 0),
),
light.ADDRESSABLE_LIGHT_SCHEMA.extend(
{
@@ -198,6 +211,7 @@ CONFIG_SCHEMA = cv.All(
).extend(cv.COMPONENT_SCHEMA),
_choose_default_method,
_validate,
_warn_esp32_deprecated,
)
+1 -1
View File
@@ -80,7 +80,7 @@ dependencies:
rules:
- if: "idf_version >=6.0.0 && target in [esp32, esp32p4]"
espressif/w5500:
version: "1.0.1"
version: "2.0.1"
rules:
- if: "idf_version >=6.0.0"
espressif/dm9051:
@@ -0,0 +1,17 @@
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: ESP32_I2S_0
num_leds: 5
pin: 4
+33 -6
View File
@@ -4,7 +4,12 @@ from __future__ import annotations
import asyncio
from collections.abc import AsyncGenerator, Callable, Generator
from contextlib import AbstractAsyncContextManager, asynccontextmanager, suppress
from contextlib import (
AbstractAsyncContextManager,
asynccontextmanager,
contextmanager,
suppress,
)
import fcntl
from functools import cache
import hashlib
@@ -179,19 +184,36 @@ def integration_test_dir() -> Generator[Path]:
yield Path(tmpdir)
@pytest.fixture
def reserved_tcp_port() -> Generator[tuple[int, socket.socket]]:
"""Reserve an unused TCP port by holding the socket open."""
@contextmanager
def _reserve_port() -> Generator[tuple[int, socket.socket]]:
"""Hold an unused TCP port open until the caller is done with it."""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("", 0))
port = s.getsockname()[1]
try:
yield port, s
yield s.getsockname()[1], s
finally:
s.close()
@pytest.fixture
def reserved_tcp_port() -> Generator[tuple[int, socket.socket]]:
"""Reserve an unused TCP port by holding the socket open."""
with _reserve_port() as reserved:
yield reserved
@pytest.fixture
def reserved_ota_port() -> Generator[tuple[int, socket.socket]]:
"""Reserve a second port, for fixtures that name their OTA port __OTA_PORT__.
Only the api socket is closed by run_compiled, so a test using this one closes its
socket itself before starting the binary, or the device cannot bind the port.
"""
with _reserve_port() as reserved:
yield reserved
@pytest.fixture
def unused_tcp_port(reserved_tcp_port: tuple[int, socket.socket]) -> int:
"""Get the reserved TCP port number."""
@@ -227,6 +249,11 @@ async def yaml_config(request: pytest.FixtureRequest, unused_tcp_port: int) -> s
# Add port configuration after api:
content = content.replace("api:", f"api:\n port: {unused_tcp_port}")
# Filled here rather than by the test, so tests sharing an OTA fixture can share its build
if "__OTA_PORT__" in content:
ota_port, _ = request.getfixturevalue("reserved_ota_port")
content = content.replace("__OTA_PORT__", str(ota_port))
# Add debug build flags for integration tests to enable assertions
if "esphome:" in content and "build_flags:" not in content:
# Add build_flags with debug flags after esphome:
@@ -1,6 +0,0 @@
esphome:
name: zero-psk-plaintext-test
host:
api:
encryption:
logger:
@@ -1,9 +0,0 @@
esphome:
name: host-ota-test
host:
api:
ota:
- platform: esphome
port: __OTA_PORT__
logger:
level: DEBUG
@@ -1,9 +0,0 @@
esphome:
name: host-ota-test
host:
api:
ota:
- platform: esphome
port: __OTA_PORT__
logger:
level: DEBUG
@@ -1,9 +0,0 @@
esphome:
name: host-ota-test
host:
api:
ota:
- platform: esphome
port: __OTA_PORT__
logger:
level: DEBUG
@@ -1,11 +0,0 @@
esphome:
name: oversized-noise
host:
api:
encryption:
key: N4Yle5YirwZhPiHHsdZLdOA73ndj/84veVaLhTvxCuU=
logger:
level: VERY_VERBOSE
@@ -1,11 +0,0 @@
esphome:
name: oversized-noise
host:
api:
encryption:
key: N4Yle5YirwZhPiHHsdZLdOA73ndj/84veVaLhTvxCuU=
logger:
level: VERY_VERBOSE
@@ -1,9 +0,0 @@
esphome:
name: oversized-protobuf-plaintext
host:
api:
logger:
level: VERY_VERBOSE
@@ -154,6 +154,7 @@ async def light_entity(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("api_homeassistant_light")
async def test_api_homeassistant_light(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -29,6 +29,7 @@ NEW_KEY = PROVISIONING_PSK
@pytest.mark.asyncio
@pytest.mark.shared_yaml("api_zero_psk_provisioning")
async def test_api_zero_psk_provisioning(
yaml_config: str,
write_yaml_config: ConfigWriter,
@@ -116,6 +117,7 @@ async def test_api_zero_psk_provisioning(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("api_zero_psk_provisioning")
async def test_api_zero_psk_provisioning_plaintext(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -125,7 +127,7 @@ async def test_api_zero_psk_provisioning_plaintext(
log_lines: list[str] = []
async with run_compiled(yaml_config, line_callback=log_lines.append):
async with api_client_connected() as client:
await assert_device_name(client, "zero-psk-plaintext-test")
await assert_device_name(client, "zero-psk-provision-test")
assert await client.noise_encryption_set_key(NEW_KEY) is True
@@ -136,7 +138,7 @@ async def test_api_zero_psk_provisioning_plaintext(
# The new key works; the zero PSK does not
async with api_client_connected(noise_psk=NEW_KEY.decode()) as client:
await assert_device_name(client, "zero-psk-plaintext-test")
await assert_device_name(client, "zero-psk-provision-test")
with pytest.raises(InvalidEncryptionKeyAPIError):
async with api_client_connected(noise_psk=ZERO_PSK, timeout=5) as client:
+79 -32
View File
@@ -103,17 +103,6 @@ def _udp_mode(
yield used
@contextmanager
def _reserve_port() -> Generator[tuple[int, socket.socket]]:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("", 0))
try:
yield s.getsockname()[1], s
finally:
s.close()
async def _wait_for_line(lines: list[str], needle: str, timeout: float = 5.0) -> None:
"""The config dump prints after every setup, a little after the api port
opens, so wait for it rather than assert on the lines seen so far."""
@@ -143,18 +132,17 @@ async def _build(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
) -> tuple[int, int, Path, Path]:
"""Reserve an OTA port, compile the fixture with it, and release both
ports right before the binary is started. Returns the stripped binary to
run and upload, then the unstripped build for crash backtraces."""
"""Compile the fixture, which conftest already gave the reserved OTA port, and
release both ports right before the binary is started. Returns the stripped
binary to run and upload, then the unstripped build for crash backtraces."""
api_port, api_socket = reserved_tcp_port
with _reserve_port() as (ota_port, ota_socket):
config_path = await write_yaml_config(
yaml_config.replace("__OTA_PORT__", str(ota_port))
)
binary_path = await compile_esphome(config_path)
api_socket.close()
ota_socket.close()
ota_port, ota_socket = reserved_ota_port
config_path = await write_yaml_config(yaml_config)
binary_path = await compile_esphome(config_path)
api_socket.close()
ota_socket.close()
return api_port, ota_port, await _strip_debug(binary_path), binary_path
@@ -294,16 +282,22 @@ async def _provision_key(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("host_ota_self_update")
async def test_host_ota_self_update(
yaml_config: str,
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
) -> None:
"""Self-OTA: upload the running binary back to itself, expect re-exec."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -328,17 +322,23 @@ async def test_host_ota_self_update(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("host_ota_self_update")
async def test_host_ota_deflate_rtl8710b_bit(
yaml_config: str,
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""The device inflates an upload asked for with the RTL8710B deflate bit."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
monkeypatch.setattr(espota2, "_is_rtl8710b_image", lambda image: True)
@@ -354,18 +354,24 @@ async def test_host_ota_deflate_rtl8710b_bit(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("host_ota_self_update")
async def test_host_ota_deflate(
yaml_config: str,
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Deflate is negotiated by default, an old client gets an uncompressed
upload, and a corrupt stream is rejected without taking the device down."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
@@ -445,6 +451,7 @@ async def test_host_ota_encrypted(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""A client that leaves right after the handshake, as a key probe does,
@@ -453,7 +460,11 @@ async def test_host_ota_encrypted(
pytest.importorskip("aioesphomeapi.noise")
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -483,13 +494,18 @@ async def test_host_ota_encrypted_safe_mode(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
) -> None:
"""Safe mode never constructs the api server, so an encrypted OTA with the
api key has to run on the ota component's own copy of that key."""
pytest.importorskip("aioesphomeapi.noise")
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
# The api port never opens in safe mode, so wait for the log line instead
@@ -510,6 +526,7 @@ async def test_host_ota_api_key_offer_with_password(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
caplog: pytest.LogCaptureFixture,
) -> None:
"""With only an api key the device offers encryption without requiring
@@ -520,7 +537,11 @@ async def test_host_ota_api_key_offer_with_password(
wrong_key = base64.b64encode(b"w" * 32).decode()
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -562,12 +583,17 @@ async def test_host_ota_cleared_password(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
) -> None:
"""A password cleared at boot with set_auth_password("") must not be
asked for: the auth path is compiled in but the device skips it."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -588,6 +614,7 @@ async def test_host_ota_provisioned_api_key(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
api_client_connected: APIClientConnectedFactory,
) -> None:
"""A key provisioned over the api feeds the OTA offer: plaintext works
@@ -597,7 +624,11 @@ async def test_host_ota_provisioned_api_key(
pytest.importorskip("aioesphomeapi.noise")
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -627,6 +658,7 @@ async def test_host_ota_provisioned_api_key_safe_mode(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
api_client_connected: APIClientConnectedFactory,
) -> None:
"""Safe mode never constructs the api server, so the OTA has to load the
@@ -634,7 +666,11 @@ async def test_host_ota_provisioned_api_key_safe_mode(
pytest.importorskip("aioesphomeapi.noise")
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
async with run_binary(
@@ -665,17 +701,23 @@ async def test_host_ota_provisioned_api_key_safe_mode(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("host_ota_self_update")
async def test_host_ota_rejects_garbage(
yaml_config: str,
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
integration_test_dir,
) -> None:
"""Bogus payload is rejected and the device keeps running."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
# 192 bytes that are neither ELF nor Mach-O.
@@ -733,6 +775,7 @@ async def test_host_ota_automations(
write_yaml_config: ConfigWriter,
compile_esphome: CompileFunction,
reserved_tcp_port: tuple[int, socket.socket],
reserved_ota_port: tuple[int, socket.socket],
integration_test_dir: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
@@ -740,7 +783,11 @@ async def test_host_ota_automations(
automation on one key fires."""
dev = _Device(
*await _build(
yaml_config, write_yaml_config, compile_esphome, reserved_tcp_port
yaml_config,
write_yaml_config,
compile_esphome,
reserved_tcp_port,
reserved_ota_port,
)
)
bogus_path = integration_test_dir / "bogus.bin"
+7 -2
View File
@@ -20,6 +20,7 @@ def _crashed(waiter: LineWaiter) -> bool:
@pytest.mark.asyncio
@pytest.mark.shared_yaml("oversized_payload_plaintext")
async def test_oversized_payload_plaintext(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -61,6 +62,7 @@ async def test_oversized_payload_plaintext(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("oversized_payload_plaintext")
async def test_oversized_protobuf_message_id_plaintext(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -75,7 +77,7 @@ async def test_oversized_protobuf_message_id_plaintext(
async with run_compiled(yaml_config, line_callback=waiter.callback):
async with api_client_connected_with_disconnect() as (client, disconnect_event):
# Verify basic connection works first
await assert_device_name(client, "oversized-protobuf-plaintext")
await assert_device_name(client, "oversized-plaintext")
# Access the internal connection to send raw message with large ID
frame_helper = client._connection._frame_helper
@@ -101,10 +103,11 @@ async def test_oversized_protobuf_message_id_plaintext(
# Try to reconnect to verify the process is still running
async with api_client_connected_with_disconnect() as (client2, _):
await assert_device_name(client2, "oversized-protobuf-plaintext")
await assert_device_name(client2, "oversized-plaintext")
@pytest.mark.asyncio
@pytest.mark.shared_yaml("oversized_payload_noise")
async def test_oversized_payload_noise(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -154,6 +157,7 @@ async def test_oversized_payload_noise(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("oversized_payload_noise")
async def test_oversized_protobuf_message_id_noise(
yaml_config: str,
run_compiled: RunCompiledFunction,
@@ -211,6 +215,7 @@ async def test_oversized_protobuf_message_id_noise(
@pytest.mark.asyncio
@pytest.mark.shared_yaml("oversized_payload_noise")
async def test_noise_corrupt_encrypted_frame(
yaml_config: str,
run_compiled: RunCompiledFunction,