Skip to content

Commit a94c333

Browse files
authored
Use error introduced in home-assistant#154579 in yale integration (home-assistant#156095)
1 parent 7fd482e commit a94c333

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

homeassistant/components/yale/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
1717
from homeassistant.core import HomeAssistant
1818
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
19-
from homeassistant.helpers import config_entry_oauth2_flow, device_registry as dr
19+
from homeassistant.helpers import device_registry as dr
20+
from homeassistant.helpers.config_entry_oauth2_flow import (
21+
ImplementationUnavailableError,
22+
OAuth2Session,
23+
async_get_config_entry_implementation,
24+
)
2025

2126
from .const import DOMAIN, PLATFORMS
2227
from .data import YaleData
@@ -30,14 +35,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool
3035
"""Set up Yale from a config entry."""
3136
session = async_create_yale_clientsession(hass)
3237
try:
33-
implementation = (
34-
await config_entry_oauth2_flow.async_get_config_entry_implementation(
35-
hass, entry
36-
)
37-
)
38-
except ValueError as err:
38+
implementation = await async_get_config_entry_implementation(hass, entry)
39+
except ImplementationUnavailableError as err:
3940
raise ConfigEntryNotReady("OAuth implementation not available") from err
40-
oauth_session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
41+
oauth_session = OAuth2Session(hass, entry, implementation)
4142
yale_gateway = YaleGateway(Path(hass.config.config_dir), session, oauth_session)
4243
try:
4344
await async_setup_yale(hass, entry, yale_gateway)

tests/components/yale/mocks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ def patch_yale_setup():
137137
patch.object(_RateLimitChecker, "register_wakeup") as authenticate_mock,
138138
patch("yalexs.manager.data.SocketIORunner") as socketio_mock,
139139
patch.object(socketio_mock, "run"),
140-
patch(
141-
"homeassistant.components.yale.config_entry_oauth2_flow.async_get_config_entry_implementation"
142-
),
140+
patch("homeassistant.components.yale.async_get_config_entry_implementation"),
143141
):
144142
yield api_mock, authenticate_mock, socketio_mock
145143

tests/components/yale/test_init.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
from homeassistant.core import HomeAssistant
2020
from homeassistant.exceptions import HomeAssistantError
2121
from homeassistant.helpers import device_registry as dr, entity_registry as er
22+
from homeassistant.helpers.config_entry_oauth2_flow import (
23+
ImplementationUnavailableError,
24+
)
2225
from homeassistant.setup import async_setup_component
2326

2427
from .mocks import (
@@ -244,8 +247,8 @@ async def test_oauth_implementation_not_available(hass: HomeAssistant) -> None:
244247
entry = await mock_yale_config_entry(hass)
245248

246249
with patch(
247-
"homeassistant.components.yale.config_entry_oauth2_flow.async_get_config_entry_implementation",
248-
side_effect=ValueError("Implementation not available"),
250+
"homeassistant.components.yale.async_get_config_entry_implementation",
251+
side_effect=ImplementationUnavailableError,
249252
):
250253
await hass.config_entries.async_setup(entry.entry_id)
251254
await hass.async_block_till_done()

0 commit comments

Comments
 (0)