mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Fix reversed raise_on_progress in baf config_flow (#72094)
This commit is contained in:
parent
037f6947d8
commit
bd78eec732
@ -54,7 +54,7 @@ class BAFFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
uuid = properties["uuid"]
|
uuid = properties["uuid"]
|
||||||
model = properties["model"]
|
model = properties["model"]
|
||||||
name = properties["name"]
|
name = properties["name"]
|
||||||
await self.async_set_unique_id(uuid, raise_on_progress=False)
|
await self.async_set_unique_id(uuid)
|
||||||
self._abort_if_unique_id_configured(updates={CONF_IP_ADDRESS: ip_address})
|
self._abort_if_unique_id_configured(updates={CONF_IP_ADDRESS: ip_address})
|
||||||
self.discovery = BAFDiscovery(ip_address, name, uuid, model)
|
self.discovery = BAFDiscovery(ip_address, name, uuid, model)
|
||||||
return await self.async_step_discovery_confirm()
|
return await self.async_step_discovery_confirm()
|
||||||
@ -98,7 +98,9 @@ class BAFFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
await self.async_set_unique_id(device.dns_sd_uuid)
|
await self.async_set_unique_id(
|
||||||
|
device.dns_sd_uuid, raise_on_progress=False
|
||||||
|
)
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(
|
||||||
updates={CONF_IP_ADDRESS: ip_address}
|
updates={CONF_IP_ADDRESS: ip_address}
|
||||||
)
|
)
|
||||||
|
@ -1 +1,37 @@
|
|||||||
"""Tests for the Big Ass Fans integration."""
|
"""Tests for the Big Ass Fans integration."""
|
||||||
|
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from aiobafi6 import Device
|
||||||
|
|
||||||
|
MOCK_UUID = "1234"
|
||||||
|
MOCK_NAME = "Living Room Fan"
|
||||||
|
|
||||||
|
|
||||||
|
class MockBAFDevice(Device):
|
||||||
|
"""A simple mock for a BAF Device."""
|
||||||
|
|
||||||
|
def __init__(self, async_wait_available_side_effect=None):
|
||||||
|
"""Init simple mock."""
|
||||||
|
self._async_wait_available_side_effect = async_wait_available_side_effect
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dns_sd_uuid(self):
|
||||||
|
"""Mock the unique id."""
|
||||||
|
return MOCK_UUID
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Mock the name of the device."""
|
||||||
|
return MOCK_NAME
|
||||||
|
|
||||||
|
async def async_wait_available(self):
|
||||||
|
"""Mock async_wait_available."""
|
||||||
|
if self._async_wait_available_side_effect:
|
||||||
|
raise self._async_wait_available_side_effect
|
||||||
|
return
|
||||||
|
|
||||||
|
def async_run(self):
|
||||||
|
"""Mock async_run."""
|
||||||
|
return asyncio.Future()
|
||||||
|
@ -12,9 +12,20 @@ from homeassistant.data_entry_flow import (
|
|||||||
RESULT_TYPE_FORM,
|
RESULT_TYPE_FORM,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from . import MOCK_NAME, MOCK_UUID, MockBAFDevice
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
def _patch_device_config_flow(side_effect=None):
|
||||||
|
"""Mock out the BAF Device object."""
|
||||||
|
|
||||||
|
def _create_mock_baf(*args, **kwargs):
|
||||||
|
return MockBAFDevice(side_effect)
|
||||||
|
|
||||||
|
return patch("homeassistant.components.baf.config_flow.Device", _create_mock_baf)
|
||||||
|
|
||||||
|
|
||||||
async def test_form_user(hass):
|
async def test_form_user(hass):
|
||||||
"""Test we get the user form."""
|
"""Test we get the user form."""
|
||||||
|
|
||||||
@ -24,9 +35,7 @@ async def test_form_user(hass):
|
|||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch("homeassistant.components.baf.config_flow.Device.async_run",), patch(
|
with _patch_device_config_flow(), patch(
|
||||||
"homeassistant.components.baf.config_flow.Device.async_wait_available",
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.baf.async_setup_entry",
|
"homeassistant.components.baf.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
@ -37,7 +46,7 @@ async def test_form_user(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result2["title"] == "127.0.0.1"
|
assert result2["title"] == MOCK_NAME
|
||||||
assert result2["data"] == {CONF_IP_ADDRESS: "127.0.0.1"}
|
assert result2["data"] == {CONF_IP_ADDRESS: "127.0.0.1"}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -48,10 +57,7 @@ async def test_form_cannot_connect(hass):
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.baf.config_flow.Device.async_run",), patch(
|
with _patch_device_config_flow(asyncio.TimeoutError):
|
||||||
"homeassistant.components.baf.config_flow.Device.async_wait_available",
|
|
||||||
side_effect=asyncio.TimeoutError,
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_IP_ADDRESS: "127.0.0.1"},
|
{CONF_IP_ADDRESS: "127.0.0.1"},
|
||||||
@ -67,10 +73,7 @@ async def test_form_unknown_exception(hass):
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.baf.config_flow.Device.async_run",), patch(
|
with _patch_device_config_flow(Exception):
|
||||||
"homeassistant.components.baf.config_flow.Device.async_wait_available",
|
|
||||||
side_effect=Exception,
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_IP_ADDRESS: "127.0.0.1"},
|
{CONF_IP_ADDRESS: "127.0.0.1"},
|
||||||
@ -92,7 +95,7 @@ async def test_zeroconf_discovery(hass):
|
|||||||
hostname="mock_hostname",
|
hostname="mock_hostname",
|
||||||
name="testfan",
|
name="testfan",
|
||||||
port=None,
|
port=None,
|
||||||
properties={"name": "My Fan", "model": "Haiku", "uuid": "1234"},
|
properties={"name": "My Fan", "model": "Haiku", "uuid": MOCK_UUID},
|
||||||
type="mock_type",
|
type="mock_type",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -118,7 +121,7 @@ async def test_zeroconf_discovery(hass):
|
|||||||
async def test_zeroconf_updates_existing_ip(hass):
|
async def test_zeroconf_updates_existing_ip(hass):
|
||||||
"""Test we can setup from zeroconf discovery."""
|
"""Test we can setup from zeroconf discovery."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN, data={CONF_IP_ADDRESS: "127.0.0.2"}, unique_id="1234"
|
domain=DOMAIN, data={CONF_IP_ADDRESS: "127.0.0.2"}, unique_id=MOCK_UUID
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -130,7 +133,7 @@ async def test_zeroconf_updates_existing_ip(hass):
|
|||||||
hostname="mock_hostname",
|
hostname="mock_hostname",
|
||||||
name="testfan",
|
name="testfan",
|
||||||
port=None,
|
port=None,
|
||||||
properties={"name": "My Fan", "model": "Haiku", "uuid": "1234"},
|
properties={"name": "My Fan", "model": "Haiku", "uuid": MOCK_UUID},
|
||||||
type="mock_type",
|
type="mock_type",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -150,9 +153,48 @@ async def test_zeroconf_rejects_ipv6(hass):
|
|||||||
hostname="mock_hostname",
|
hostname="mock_hostname",
|
||||||
name="testfan",
|
name="testfan",
|
||||||
port=None,
|
port=None,
|
||||||
properties={"name": "My Fan", "model": "Haiku", "uuid": "1234"},
|
properties={"name": "My Fan", "model": "Haiku", "uuid": MOCK_UUID},
|
||||||
type="mock_type",
|
type="mock_type",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert result["type"] == RESULT_TYPE_ABORT
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "ipv6_not_supported"
|
assert result["reason"] == "ipv6_not_supported"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_flow_is_not_blocked_by_discovery(hass):
|
||||||
|
"""Test we can setup from the user flow when there is also a discovery."""
|
||||||
|
discovery_result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="127.0.0.1",
|
||||||
|
addresses=["127.0.0.1"],
|
||||||
|
hostname="mock_hostname",
|
||||||
|
name="testfan",
|
||||||
|
port=None,
|
||||||
|
properties={"name": "My Fan", "model": "Haiku", "uuid": MOCK_UUID},
|
||||||
|
type="mock_type",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert discovery_result["type"] == RESULT_TYPE_FORM
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with _patch_device_config_flow(), patch(
|
||||||
|
"homeassistant.components.baf.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_IP_ADDRESS: "127.0.0.1"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
|
assert result2["title"] == MOCK_NAME
|
||||||
|
assert result2["data"] == {CONF_IP_ADDRESS: "127.0.0.1"}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user