mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Handle exception introduced with recent PyViCare update (#103110)
This commit is contained in:
parent
193ce08b39
commit
22126a1280
@ -4,7 +4,10 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError
|
from PyViCare.PyViCareUtils import (
|
||||||
|
PyViCareInvalidConfigurationError,
|
||||||
|
PyViCareInvalidCredentialsError,
|
||||||
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -53,7 +56,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await self.hass.async_add_executor_job(
|
await self.hass.async_add_executor_job(
|
||||||
vicare_login, self.hass, user_input
|
vicare_login, self.hass, user_input
|
||||||
)
|
)
|
||||||
except PyViCareInvalidCredentialsError:
|
except (PyViCareInvalidConfigurationError, PyViCareInvalidCredentialsError):
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
else:
|
else:
|
||||||
return self.async_create_entry(title=VICARE_NAME, data=user_input)
|
return self.async_create_entry(title=VICARE_NAME, data=user_input)
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError
|
from PyViCare.PyViCareUtils import (
|
||||||
|
PyViCareInvalidConfigurationError,
|
||||||
|
PyViCareInvalidCredentialsError,
|
||||||
|
)
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
@ -43,6 +46,22 @@ async def test_user_create_entry(
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
# test PyViCareInvalidConfigurationError
|
||||||
|
with patch(
|
||||||
|
f"{MODULE}.config_flow.vicare_login",
|
||||||
|
side_effect=PyViCareInvalidConfigurationError(
|
||||||
|
{"error": "foo", "error_description": "bar"}
|
||||||
|
),
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
VALID_CONFIG,
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
assert result["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
# test PyViCareInvalidCredentialsError
|
# test PyViCareInvalidCredentialsError
|
||||||
with patch(
|
with patch(
|
||||||
f"{MODULE}.config_flow.vicare_login",
|
f"{MODULE}.config_flow.vicare_login",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user