mirror of
https://github.com/esphome/esphome.git
synced 2026-10-21 21:36:14 +00:00
[packet_interface] Name a peer in the error for a link used with peers
The link may have only one peer, so the error no longer says several. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fa5c769943
commit
aae7b6e466
@@ -115,14 +115,16 @@ def interface_layers(interface_id: ID) -> ConfigType | None:
|
||||
|
||||
|
||||
def final_validate_interface(key: str) -> Callable[[ConfigType], ConfigType]:
|
||||
"""Final validation for an application: a link with several peers must be used through one of the peers."""
|
||||
"""Final validation for an application: a link with peers must be used through one of the peers."""
|
||||
|
||||
def validator(config: ConfigType) -> ConfigType:
|
||||
interface_id: ID = config[key]
|
||||
interface = interface_layers(interface_id)
|
||||
if interface is not None and CONF_PEERS in interface.get(CONF_ADDRESSING, {}):
|
||||
if interface is not None and (
|
||||
peers := interface.get(CONF_ADDRESSING, {}).get(CONF_PEERS)
|
||||
):
|
||||
raise cv.Invalid(
|
||||
f"'{interface_id.id}' has several peers, so use the id of one of them",
|
||||
f"'{interface_id.id}' has peers, so use the id of one of them, such as '{peers[0][CONF_ID].id}'",
|
||||
path=[key],
|
||||
)
|
||||
return config
|
||||
|
||||
@@ -368,8 +368,8 @@ def test_addressing_own_address_rejected(setup_core, addressing: dict) -> None:
|
||||
uart_packet_interface.CONFIG_SCHEMA({CONF_ADDRESSING: addressing})
|
||||
|
||||
|
||||
def test_application_needs_peer_id_with_several_peers(setup_core) -> None:
|
||||
"""An application must use one peer's id, not the id of a link with several peers."""
|
||||
def test_application_needs_peer_id_with_peers(setup_core) -> None:
|
||||
"""An application must use one peer's id, not the id of a link with peers."""
|
||||
validator = packet_interface.final_validate_interface("packet_interface")
|
||||
token = fv.full_config.set(
|
||||
{
|
||||
@@ -380,7 +380,9 @@ def test_application_needs_peer_id_with_several_peers(setup_core) -> None:
|
||||
}
|
||||
)
|
||||
try:
|
||||
with pytest.raises(cv.Invalid, match="several peers"):
|
||||
with pytest.raises(
|
||||
cv.Invalid, match="has peers, so use the id of one of them, such as 'a'"
|
||||
):
|
||||
validator({"packet_interface": ID("bus")})
|
||||
assert validator({"packet_interface": ID("single")})
|
||||
assert validator({"packet_interface": ID("a")})
|
||||
|
||||
Reference in New Issue
Block a user