Improve Ikea Idasen config flow error messages (#101567)
This commit is contained in:
parent
bd93fbe91d
commit
da3e36aa3b
6 changed files with 64 additions and 7 deletions
|
@ -4,9 +4,9 @@ from __future__ import annotations
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from bleak import BleakError
|
||||
from bleak.exc import BleakError
|
||||
from bluetooth_data_tools import human_readable_name
|
||||
from idasen_ha import Desk
|
||||
from idasen_ha import AuthFailedError, Desk
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -64,6 +64,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
desk = Desk(None)
|
||||
try:
|
||||
await desk.connect(discovery_info.device, monitor_height=False)
|
||||
except AuthFailedError as err:
|
||||
_LOGGER.exception("AuthFailedError", exc_info=err)
|
||||
errors["base"] = "auth_failed"
|
||||
except TimeoutError as err:
|
||||
_LOGGER.exception("TimeoutError", exc_info=err)
|
||||
errors["base"] = "cannot_connect"
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
"dependencies": ["bluetooth_adapters"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/idasen_desk",
|
||||
"iot_class": "local_push",
|
||||
"requirements": ["idasen-ha==1.4"]
|
||||
"requirements": ["idasen-ha==1.4.1"]
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
}
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"auth_failed": "Unable to authenticate with the desk. This is usually solved by using an ESPHome Bluetooth Proxy. Please check the integration documentation for alternative workarounds.",
|
||||
"cannot_connect": "Cannot connect. Make sure that the desk is in Bluetooth pairing mode. If not already, you can also use an ESPHome Bluetooth Proxy, as it provides a better connection.",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
},
|
||||
"abort": {
|
||||
|
|
|
@ -1042,7 +1042,7 @@ ical==5.0.1
|
|||
icmplib==3.0
|
||||
|
||||
# homeassistant.components.idasen_desk
|
||||
idasen-ha==1.4
|
||||
idasen-ha==1.4.1
|
||||
|
||||
# homeassistant.components.network
|
||||
ifaddr==0.2.0
|
||||
|
|
|
@ -822,7 +822,7 @@ ical==5.0.1
|
|||
icmplib==3.0
|
||||
|
||||
# homeassistant.components.idasen_desk
|
||||
idasen-ha==1.4
|
||||
idasen-ha==1.4.1
|
||||
|
||||
# homeassistant.components.network
|
||||
ifaddr==0.2.0
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from bleak import BleakError
|
||||
from idasen_ha import AuthFailedError
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -89,7 +90,7 @@ async def test_user_step_no_new_devices_found(hass: HomeAssistant) -> None:
|
|||
async def test_user_step_cannot_connect(
|
||||
hass: HomeAssistant, exception: Exception
|
||||
) -> None:
|
||||
"""Test user step and we cannot connect."""
|
||||
"""Test user step with a cannot connect error."""
|
||||
with patch(
|
||||
"homeassistant.components.idasen_desk.config_flow.async_discovered_service_info",
|
||||
return_value=[IDASEN_DISCOVERY_INFO],
|
||||
|
@ -140,6 +141,58 @@ async def test_user_step_cannot_connect(
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_step_auth_failed(hass: HomeAssistant) -> None:
|
||||
"""Test user step with an auth failed error."""
|
||||
with patch(
|
||||
"homeassistant.components.idasen_desk.config_flow.async_discovered_service_info",
|
||||
return_value=[IDASEN_DISCOVERY_INFO],
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.idasen_desk.config_flow.Desk.connect",
|
||||
side_effect=AuthFailedError,
|
||||
), patch("homeassistant.components.idasen_desk.config_flow.Desk.disconnect"):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["step_id"] == "user"
|
||||
assert result2["errors"] == {"base": "auth_failed"}
|
||||
|
||||
with patch("homeassistant.components.idasen_desk.config_flow.Desk.connect"), patch(
|
||||
"homeassistant.components.idasen_desk.config_flow.Desk.disconnect"
|
||||
), patch(
|
||||
"homeassistant.components.idasen_desk.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{
|
||||
CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == IDASEN_DISCOVERY_INFO.name
|
||||
assert result3["data"] == {
|
||||
CONF_ADDRESS: IDASEN_DISCOVERY_INFO.address,
|
||||
}
|
||||
assert result3["result"].unique_id == IDASEN_DISCOVERY_INFO.address
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_user_step_unknown_exception(hass: HomeAssistant) -> None:
|
||||
"""Test user step with an unknown exception."""
|
||||
with patch(
|
||||
|
|
Loading…
Add table
Reference in a new issue