Fix uncaught exception in bond config flow (#61184)
parent
ea58778a5c
commit
6b70bd7495
|
@ -87,7 +87,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
return
|
||||
|
||||
self._discovered[CONF_ACCESS_TOKEN] = token
|
||||
_, hub_name = await _validate_input(self.hass, self._discovered)
|
||||
try:
|
||||
_, hub_name = await _validate_input(self.hass, self._discovered)
|
||||
except InputValidationError:
|
||||
return
|
||||
self._discovered[CONF_NAME] = hub_name
|
||||
|
||||
async def async_step_zeroconf(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Test the Bond config flow."""
|
||||
from __future__ import annotations
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
|
@ -304,6 +305,46 @@ async def test_zeroconf_form_with_token_available(hass: core.HomeAssistant):
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_zeroconf_form_with_token_available_name_unavailable(
|
||||
hass: core.HomeAssistant,
|
||||
):
|
||||
"""Test we get the discovery form when we can get the token but the name is unavailable."""
|
||||
|
||||
with patch_bond_version(
|
||||
side_effect=ClientResponseError(Mock(), (), status=HTTPStatus.BAD_REQUEST)
|
||||
), patch_bond_token(return_value={"token": "discovered-token"}):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="test-host",
|
||||
hostname="mock_hostname",
|
||||
name="test-bond-id.some-other-tail-info",
|
||||
port=None,
|
||||
properties={},
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "test-bond-id"
|
||||
assert result2["data"] == {
|
||||
CONF_HOST: "test-host",
|
||||
CONF_ACCESS_TOKEN: "discovered-token",
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_zeroconf_already_configured(hass: core.HomeAssistant):
|
||||
"""Test starting a flow from discovery when already configured."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue