Update Awair config entry on discovery (#78521)

pull/78590/head
Franck Nijhof 2022-09-16 17:42:44 +02:00 committed by GitHub
parent 0b97dcf0bd
commit 8774f34271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -39,7 +39,10 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
if self._device is not None:
await self.async_set_unique_id(self._device.mac_address)
self._abort_if_unique_id_configured(error="already_configured_device")
self._abort_if_unique_id_configured(
updates={CONF_HOST: self._device.device_addr},
error="already_configured_device",
)
self.context.update(
{
"host": host,

View File

@ -1,4 +1,5 @@
"""Define tests for the Awair config flow."""
from typing import Any
from unittest.mock import Mock, patch
from aiohttp.client_exceptions import ClientConnectorError
@ -364,3 +365,37 @@ async def test_unsuccessful_create_zeroconf_entry(hass: HomeAssistant):
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
async def test_zeroconf_discovery_update_configuration(
hass: HomeAssistant, local_devices: Any
) -> None:
"""Test updating an existing Awair config entry with discovery info."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: "127.0.0.1"},
unique_id=LOCAL_UNIQUE_ID,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.awair.async_setup_entry",
return_value=True,
) as mock_setup_entry, patch(
"python_awair.AwairClient.query", side_effect=[local_devices]
), patch(
"homeassistant.components.awair.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=ZEROCONF_DISCOVERY,
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "already_configured_device"
assert config_entry.data[CONF_HOST] == ZEROCONF_DISCOVERY.host
assert mock_setup_entry.call_count == 0