mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 20:25:07 +02:00
Fix uncaught exception in bond config flow (#61184)
This commit is contained in:
@@ -87,7 +87,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._discovered[CONF_ACCESS_TOKEN] = token
|
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
|
self._discovered[CONF_NAME] = hub_name
|
||||||
|
|
||||||
async def async_step_zeroconf(
|
async def async_step_zeroconf(
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
"""Test the Bond config flow."""
|
"""Test the Bond config flow."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from http import HTTPStatus
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, Mock, patch
|
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
|
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):
|
async def test_zeroconf_already_configured(hass: core.HomeAssistant):
|
||||||
"""Test starting a flow from discovery when already configured."""
|
"""Test starting a flow from discovery when already configured."""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user