baf: Raise ConfigEntryNotReady when the device has a mismatched UUID (#98898)
This commit is contained in:
parent
39992c2ccc
commit
e96ce3f520
5 changed files with 51 additions and 3 deletions
|
@ -6,6 +6,7 @@ from asyncio import timeout
|
|||
|
||||
from aiobafi6 import Device, Service
|
||||
from aiobafi6.discovery import PORT
|
||||
from aiobafi6.exceptions import DeviceUUIDMismatchError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, Platform
|
||||
|
@ -37,6 +38,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
try:
|
||||
async with timeout(RUN_TIMEOUT):
|
||||
await device.async_wait_available()
|
||||
except DeviceUUIDMismatchError as ex:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Unexpected device found at {ip_address}; expected {entry.unique_id}, found {device.dns_sd_uuid}"
|
||||
) from ex
|
||||
except asyncio.TimeoutError as ex:
|
||||
run_future.cancel()
|
||||
raise ConfigEntryNotReady(f"Timed out connecting to {ip_address}") from ex
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/baf",
|
||||
"iot_class": "local_push",
|
||||
"requirements": ["aiobafi6==0.8.2"],
|
||||
"requirements": ["aiobafi6==0.9.0"],
|
||||
"zeroconf": [
|
||||
{
|
||||
"type": "_api._tcp.local.",
|
||||
|
|
|
@ -203,7 +203,7 @@ aioasuswrt==1.4.0
|
|||
aioazuredevops==1.3.5
|
||||
|
||||
# homeassistant.components.baf
|
||||
aiobafi6==0.8.2
|
||||
aiobafi6==0.9.0
|
||||
|
||||
# homeassistant.components.aws
|
||||
aiobotocore==2.6.0
|
||||
|
|
|
@ -184,7 +184,7 @@ aioasuswrt==1.4.0
|
|||
aioazuredevops==1.3.5
|
||||
|
||||
# homeassistant.components.baf
|
||||
aiobafi6==0.8.2
|
||||
aiobafi6==0.9.0
|
||||
|
||||
# homeassistant.components.aws
|
||||
aiobotocore==2.6.0
|
||||
|
|
43
tests/components/baf/test_init.py
Normal file
43
tests/components/baf/test_init.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
"""Test the baf init flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiobafi6.exceptions import DeviceUUIDMismatchError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.baf.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import MOCK_UUID, MockBAFDevice
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
def _patch_device_init(side_effect=None):
|
||||
"""Mock out the BAF Device object."""
|
||||
|
||||
def _create_mock_baf(*args, **kwargs):
|
||||
return MockBAFDevice(side_effect)
|
||||
|
||||
return patch("homeassistant.components.baf.Device", _create_mock_baf)
|
||||
|
||||
|
||||
async def test_config_entry_wrong_uuid(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test config entry enters setup retry when uuid mismatches."""
|
||||
mismatched_uuid = MOCK_UUID + "0"
|
||||
already_migrated_config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_IP_ADDRESS: "127.0.0.1"}, unique_id=mismatched_uuid
|
||||
)
|
||||
already_migrated_config_entry.add_to_hass(hass)
|
||||
with _patch_device_init(DeviceUUIDMismatchError):
|
||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
assert already_migrated_config_entry.state == ConfigEntryState.SETUP_RETRY
|
||||
assert (
|
||||
"Unexpected device found at 127.0.0.1; expected 12340, found 1234"
|
||||
in caplog.text
|
||||
)
|
Loading…
Add table
Reference in a new issue