mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Update Awair config entry on discovery (#78521)
This commit is contained in:
parent
0b97dcf0bd
commit
8774f34271
@ -39,7 +39,10 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if self._device is not None:
|
if self._device is not None:
|
||||||
await self.async_set_unique_id(self._device.mac_address)
|
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(
|
self.context.update(
|
||||||
{
|
{
|
||||||
"host": host,
|
"host": host,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""Define tests for the Awair config flow."""
|
"""Define tests for the Awair config flow."""
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
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
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user