[uart] Share uart_tcp's write pacing and uart_id matcher (#20464)

This commit is contained in:
Bascht74
2026-10-09 15:11:48 -10:00
committed by GitHub
parent e5f5ca07c4
commit 4e4056d790
8 changed files with 131 additions and 40 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Tests for the uart helpers shared by components that own a UART."""
from esphome.components.uart import subtree_references_uart
from esphome.core import ID
def test_finds_a_nested_uart_id() -> None:
config = {"modbus": [{"id": ID("hub"), "uart_id": ID("bus")}]}
assert subtree_references_uart(config, "bus")
def test_ignores_other_uarts_and_other_keys() -> None:
config = {"modbus": [{"uart_id": ID("other")}], "sensor": [{"id": ID("bus")}]}
assert not subtree_references_uart(config, "bus")
def test_finds_another_key() -> None:
config = {"modbus_tcp_uart": [{"tcp_uart_id": ID("bus")}]}
assert subtree_references_uart(config, "bus", "tcp_uart_id")
assert not subtree_references_uart(config, "bus")
def test_handles_scalars() -> None:
assert not subtree_references_uart("bus", "bus")