mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Hold back ESPHome serial proxy ports until their identity arrives (#193540)
This commit is contained in:
@@ -25,6 +25,7 @@ from .domain_data import DomainData
|
||||
from .encryption_key_storage import async_get_encryption_key_storage
|
||||
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
||||
from .manager import (
|
||||
MIN_VERSION_SERIAL_PROXY_IDENTITY,
|
||||
ESPHomeManager,
|
||||
async_create_api_client,
|
||||
async_get_manufacturer_model,
|
||||
@@ -54,9 +55,15 @@ def _async_scan_serial_ports(
|
||||
continue
|
||||
|
||||
identities = entry_data.serial_proxy_identities
|
||||
sends_identities = entry_data.api_version >= MIN_VERSION_SERIAL_PROXY_IDENTITY
|
||||
|
||||
for instance, proxy in enumerate(device_info.serial_proxies):
|
||||
identity = identities.get(instance)
|
||||
|
||||
# Until its identity arrives, a port may be an empty USB socket
|
||||
if identity is None and sends_identities:
|
||||
continue
|
||||
|
||||
url = serial_proxy.build_port_url(entry.entry_id, proxy.name, identity)
|
||||
|
||||
if url is None:
|
||||
|
||||
@@ -183,6 +183,9 @@ async def test_scan_serial_ports_happy_path(
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""A loaded entry with serial proxies emits a SerialDevice per proxy."""
|
||||
_mock_identities(
|
||||
mock_client, [SerialProxyIdentity(instance=0), SerialProxyIdentity(instance=1)]
|
||||
)
|
||||
device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={
|
||||
@@ -222,6 +225,7 @@ async def test_scan_serial_ports_uses_project_info(
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""Project information takes precedence over manufacturer and model."""
|
||||
_mock_identities(mock_client, [SerialProxyIdentity(instance=0)])
|
||||
device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={
|
||||
@@ -254,6 +258,7 @@ async def test_scan_serial_ports_defaults_manufacturer(
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""A device without a manufacturer falls back to espressif."""
|
||||
_mock_identities(mock_client, [SerialProxyIdentity(instance=0)])
|
||||
device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={
|
||||
@@ -319,6 +324,25 @@ async def test_scan_serial_ports_usb(
|
||||
assert _async_scan_serial_ports(hass) == [_zbt2_port(device.entry.entry_id)]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_scan_serial_ports_before_identity(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
mock_esphome_device: MockESPHomeDeviceType,
|
||||
) -> None:
|
||||
"""A port is not listed until the device has sent its identity."""
|
||||
callbacks = _mock_identities(mock_client, [])
|
||||
device = await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
device_info={"serial_proxies": USB_PROXIES},
|
||||
)
|
||||
|
||||
assert _async_scan_serial_ports(hass) == []
|
||||
|
||||
callbacks[0](ZBT2)
|
||||
assert _async_scan_serial_ports(hass) == [_zbt2_port(device.entry.entry_id)]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_device_capabilities_match_scan(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user