mirror of
https://github.com/esphome/esphome.git
synced 2026-10-22 05:46:12 +00:00
[packet_interface] Check the layers in the link schema
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5950471b8e
commit
98aad83407
@@ -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:
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user