Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception introduced with recent PyViCare update #103110

Merged
merged 10 commits into from
Oct 31, 2023
7 changes: 5 additions & 2 deletions homeassistant/components/vicare/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
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
Expand Down Expand Up @@ -53,7 +56,7 @@ async def async_step_user(
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)
Expand Down
21 changes: 20 additions & 1 deletion tests/components/vicare/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading