Skip to content

Commit

Permalink
Handle exception introduced with recent PyViCare update (#103110)
Browse files Browse the repository at this point in the history
  • Loading branch information
CFenner authored and frenck committed Oct 31, 2023
1 parent 040ecb7 commit 09ed6e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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

0 comments on commit 09ed6e9

Please sign in to comment.