Handle exception introduced with recent PyViCare update (#103110)
This commit is contained in:
parent
193ce08b39
commit
22126a1280
2 changed files with 25 additions and 3 deletions
|
@ -4,7 +4,10 @@ from __future__ import annotations
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError
|
||||
from PyViCare.PyViCareUtils import (
|
||||
PyViCareInvalidConfigurationError,
|
||||
PyViCareInvalidCredentialsError,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -53,7 +56,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
await self.hass.async_add_executor_job(
|
||||
vicare_login, self.hass, user_input
|
||||
)
|
||||
except PyViCareInvalidCredentialsError:
|
||||
except (PyViCareInvalidConfigurationError, PyViCareInvalidCredentialsError):
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
return self.async_create_entry(title=VICARE_NAME, data=user_input)
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError
|
||||
from PyViCare.PyViCareUtils import (
|
||||
PyViCareInvalidConfigurationError,
|
||||
PyViCareInvalidCredentialsError,
|
||||
)
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import dhcp
|
||||
|
@ -43,6 +46,22 @@ async def test_user_create_entry(
|
|||
assert result["step_id"] == "user"
|
||||
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
|
||||
with patch(
|
||||
f"{MODULE}.config_flow.vicare_login",
|
||||
|
|
Loading…
Add table
Reference in a new issue