mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Warn user if Gateway is already paired (#57530)
* Warn user if Gateway is already paired. Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
abcacd2a00
commit
8d7744a74f
@ -182,7 +182,8 @@ async def authenticate(
|
||||
raise AuthError("timeout") from err
|
||||
finally:
|
||||
await api_factory.shutdown()
|
||||
|
||||
if key is None:
|
||||
raise AuthError("cannot_authenticate")
|
||||
return await get_gateway_info(hass, host, identity, key)
|
||||
|
||||
|
||||
|
@ -13,7 +13,8 @@
|
||||
"error": {
|
||||
"invalid_key": "Failed to register with provided key. If this keeps happening, try restarting the gateway.",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"timeout": "Timeout validating the code."
|
||||
"timeout": "Timeout validating the code.",
|
||||
"cannot_authenticate": "Cannot authenticate, is Gateway paired with another server like e.g. Homekit?"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Test the Tradfri config flow."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@ -18,6 +18,26 @@ def mock_auth():
|
||||
yield mock_auth
|
||||
|
||||
|
||||
async def test_already_paired(hass, mock_entry_setup):
|
||||
"""Test Gateway already paired."""
|
||||
with patch(
|
||||
"homeassistant.components.tradfri.config_flow.APIFactory",
|
||||
autospec=True,
|
||||
) as mock_lib:
|
||||
mx = AsyncMock()
|
||||
mx.generate_psk.return_value = None
|
||||
mock_lib.init.return_value = mx
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tradfri", context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"host": "123.123.123.123", "security_code": "abcd"}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] == {"base": "cannot_authenticate"}
|
||||
|
||||
|
||||
async def test_user_connection_successful(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a successful connection."""
|
||||
mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user