Show HomeKit Controller unhandled pairing error reason in the UI (#82505)
This commit is contained in:
parent
a7caa038be
commit
7df711f1f3
4 changed files with 64 additions and 7 deletions
|
@ -8,6 +8,7 @@ from aiohomekit.exceptions import AuthenticationError
|
|||
from aiohomekit.model import Accessories, Accessory
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
from bleak.exc import BleakError
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -743,6 +744,57 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected)
|
|||
}
|
||||
|
||||
|
||||
async def test_pair_unknown_errors(hass, controller):
|
||||
"""Test describing unknown errors."""
|
||||
device = setup_mock_accessory(controller)
|
||||
discovery_info = get_device_discovery_info(device)
|
||||
|
||||
# Device is discovered
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"homekit_controller",
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data=discovery_info,
|
||||
)
|
||||
|
||||
assert get_flow_context(hass, result) == {
|
||||
"title_placeholders": {"name": "TestDevice", "category": "Outlet"},
|
||||
"unique_id": "00:00:00:00:00:00",
|
||||
"source": config_entries.SOURCE_ZEROCONF,
|
||||
}
|
||||
|
||||
# User initiates pairing - this triggers the device to show a pairing code
|
||||
# and then HA to show a pairing form
|
||||
finish_pairing = unittest.mock.AsyncMock(
|
||||
side_effect=BleakError("The bluetooth connection failed")
|
||||
)
|
||||
with patch.object(device, "async_start_pairing", return_value=finish_pairing):
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert get_flow_context(hass, result) == {
|
||||
"title_placeholders": {"name": "TestDevice", "category": "Outlet"},
|
||||
"unique_id": "00:00:00:00:00:00",
|
||||
"source": config_entries.SOURCE_ZEROCONF,
|
||||
}
|
||||
|
||||
# User enters pairing code
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={"pairing_code": "111-22-333"}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"]["pairing_code"] == "pairing_failed"
|
||||
assert (
|
||||
result["description_placeholders"]["error"] == "The bluetooth connection failed"
|
||||
)
|
||||
|
||||
assert get_flow_context(hass, result) == {
|
||||
"title_placeholders": {"name": "TestDevice", "category": "Outlet"},
|
||||
"unique_id": "00:00:00:00:00:00",
|
||||
"source": config_entries.SOURCE_ZEROCONF,
|
||||
"pairing": True,
|
||||
}
|
||||
|
||||
|
||||
async def test_user_works(hass, controller):
|
||||
"""Test user initiated disovers devices."""
|
||||
setup_mock_accessory(controller)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue