mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Fix reconnect rather than reauth when both HA and UniFi controller restarts at the same time (#63994)
This commit is contained in:
parent
d3f980d402
commit
59cea56e17
@ -500,6 +500,7 @@ async def get_controller(
|
|||||||
aiounifi.BadGateway,
|
aiounifi.BadGateway,
|
||||||
aiounifi.ServiceUnavailable,
|
aiounifi.ServiceUnavailable,
|
||||||
aiounifi.RequestError,
|
aiounifi.RequestError,
|
||||||
|
aiounifi.ResponseError,
|
||||||
) as err:
|
) as err:
|
||||||
LOGGER.error("Error connecting to the UniFi Network at %s: %s", host, err)
|
LOGGER.error("Error connecting to the UniFi Network at %s: %s", host, err)
|
||||||
raise CannotConnect from err
|
raise CannotConnect from err
|
||||||
|
@ -473,49 +473,22 @@ async def test_get_controller_verify_ssl_false(hass):
|
|||||||
assert await get_controller(hass, **controller_data)
|
assert await get_controller(hass, **controller_data)
|
||||||
|
|
||||||
|
|
||||||
async def test_get_controller_login_failed(hass):
|
@pytest.mark.parametrize(
|
||||||
"""Check that get_controller can handle a failed login."""
|
"side_effect,raised_exception",
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
[
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.Unauthorized
|
(asyncio.TimeoutError, CannotConnect),
|
||||||
), pytest.raises(AuthenticationRequired):
|
(aiounifi.BadGateway, CannotConnect),
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
(aiounifi.ServiceUnavailable, CannotConnect),
|
||||||
|
(aiounifi.RequestError, CannotConnect),
|
||||||
|
(aiounifi.ResponseError, CannotConnect),
|
||||||
async def test_get_controller_controller_bad_gateway(hass):
|
(aiounifi.Unauthorized, AuthenticationRequired),
|
||||||
|
(aiounifi.LoginRequired, AuthenticationRequired),
|
||||||
|
(aiounifi.AiounifiException, AuthenticationRequired),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_get_controller_fails_to_connect(hass, side_effect, raised_exception):
|
||||||
"""Check that get_controller can handle controller being unavailable."""
|
"""Check that get_controller can handle controller being unavailable."""
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.BadGateway
|
"aiounifi.Controller.login", side_effect=side_effect
|
||||||
), pytest.raises(CannotConnect):
|
), pytest.raises(raised_exception):
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_controller_controller_service_unavailable(hass):
|
|
||||||
"""Check that get_controller can handle controller being unavailable."""
|
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.ServiceUnavailable
|
|
||||||
), pytest.raises(CannotConnect):
|
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_controller_controller_unavailable(hass):
|
|
||||||
"""Check that get_controller can handle controller being unavailable."""
|
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.RequestError
|
|
||||||
), pytest.raises(CannotConnect):
|
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_controller_login_required(hass):
|
|
||||||
"""Check that get_controller can handle unknown errors."""
|
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.LoginRequired
|
|
||||||
), pytest.raises(AuthenticationRequired):
|
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_controller_unknown_error(hass):
|
|
||||||
"""Check that get_controller can handle unknown errors."""
|
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
|
||||||
"aiounifi.Controller.login", side_effect=aiounifi.AiounifiException
|
|
||||||
), pytest.raises(AuthenticationRequired):
|
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
await get_controller(hass, **CONTROLLER_DATA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user