mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 07:20:24 +00:00
[uart_mux] New component to share a UART between a CDC-ACM bridge and local consumers (#19066)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
co-authored by
Claude Fable 5.1
J. Nick Koston
parent
ec1d8fa953
commit
d824a32ef1
@@ -0,0 +1,42 @@
|
||||
"""Tests for the uart_mux component's final validation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome import config_validation as cv
|
||||
from esphome.const import CONF_ID, PlatformFramework
|
||||
from esphome.core import ID
|
||||
from esphome.types import ConfigType
|
||||
from tests.component_tests.types import SetCoreConfigCallable
|
||||
|
||||
CONF_BRIDGE_ID = "bridge_id"
|
||||
|
||||
|
||||
def _set_esp32_s3(set_core_config: SetCoreConfigCallable) -> None:
|
||||
from esphome.components.esp32 import KEY_VARIANT, VARIANT_ESP32S3
|
||||
|
||||
set_core_config(
|
||||
PlatformFramework.ESP32_IDF, platform_data={KEY_VARIANT: VARIANT_ESP32S3}
|
||||
)
|
||||
|
||||
|
||||
def _mux_conf(mux_id: str, bridge_id: str) -> ConfigType:
|
||||
return {CONF_ID: ID(mux_id), CONF_BRIDGE_ID: ID(bridge_id)}
|
||||
|
||||
|
||||
def test_accepts_one_mux_per_bridge(set_core_config: SetCoreConfigCallable) -> None:
|
||||
_set_esp32_s3(set_core_config)
|
||||
from esphome.components import uart_mux
|
||||
|
||||
uart_mux._final_validate(_mux_conf("mux_0", "bridge_0"))
|
||||
uart_mux._final_validate(_mux_conf("mux_1", "bridge_1"))
|
||||
|
||||
|
||||
def test_rejects_two_muxes_on_one_bridge(
|
||||
set_core_config: SetCoreConfigCallable,
|
||||
) -> None:
|
||||
_set_esp32_s3(set_core_config)
|
||||
from esphome.components import uart_mux
|
||||
|
||||
uart_mux._final_validate(_mux_conf("mux_0", "bridge_0"))
|
||||
with pytest.raises(cv.Invalid, match="already routed by another 'uart_mux'"):
|
||||
uart_mux._final_validate(_mux_conf("mux_1", "bridge_0"))
|
||||
Reference in New Issue
Block a user