[packet_interface] Check the layers in the link schema

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
clydebarrow
2026-10-19 22:21:49 +11:00
co-authored by Claude Opus 5.5
parent 5950471b8e
commit 98aad83407
2 changed files with 19 additions and 28 deletions
+16 -19
View File
@@ -54,16 +54,9 @@ def AUTO_LOAD(config: list[ConfigType] | None = None) -> list[str]:
return sorted(loads)
def _final_validate(config: list[ConfigType]) -> None:
for index, interface in enumerate(config):
try:
check_session(interface)
except cv.Invalid as err:
err.prepend([index])
raise
FINAL_VALIDATE_SCHEMA = _final_validate
def _validate_layers(config: ConfigType) -> ConfigType:
check_session(config)
return config
def packet_interface_schema(
@@ -72,15 +65,19 @@ def packet_interface_schema(
max_packet_size_limit: int = 4096,
) -> cv.Schema:
"""Schema for a link platform, with the layers that can be stacked on it."""
return cv.Schema(
{
cv.GenerateID(): cv.declare_id(class_),
cv.Optional(
CONF_MAX_PACKET_SIZE, default=default_max_packet_size
): cv.int_range(16, max_packet_size_limit),
**LINK_LAYER_SCHEMAS,
}
).extend(cv.COMPONENT_SCHEMA)
return (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(class_),
cv.Optional(
CONF_MAX_PACKET_SIZE, default=default_max_packet_size
): cv.int_range(16, max_packet_size_limit),
**LINK_LAYER_SCHEMAS,
}
)
.extend(cv.COMPONENT_SCHEMA)
.add_extra(_validate_layers)
)
async def new_packet_interface(config: ConfigType, *args: Any) -> MockObj:
+3 -9
View File
@@ -166,15 +166,9 @@ def test_rolling_code_requires_session(setup_core) -> None:
"""The rolling code needs the session's keep-alives, so the peer sends this device's boot number back."""
rolling = {CONF_ENCRYPTION: {"key": "secret", "rolling_code_enable": True}}
with pytest.raises(cv.Invalid, match="session"):
packet_interface.FINAL_VALIDATE_SCHEMA(
[uart_packet_interface.CONFIG_SCHEMA(rolling)]
)
packet_interface.FINAL_VALIDATE_SCHEMA(
[
uart_packet_interface.CONFIG_SCHEMA({**rolling, CONF_SESSION: None}),
uart_packet_interface.CONFIG_SCHEMA({CONF_ENCRYPTION: "secret"}),
]
)
uart_packet_interface.CONFIG_SCHEMA(rolling)
uart_packet_interface.CONFIG_SCHEMA({**rolling, CONF_SESSION: None})
uart_packet_interface.CONFIG_SCHEMA({CONF_ENCRYPTION: "secret"})
@pytest.mark.parametrize(