|
16 | 16 | from homeassistant.const import CONF_WEBHOOK_ID, Platform |
17 | 17 | from homeassistant.core import CoreState, HomeAssistant |
18 | 18 | from homeassistant.helpers import device_registry as dr, entity_registry as er |
| 19 | +from homeassistant.helpers.config_entry_oauth2_flow import ( |
| 20 | + ImplementationUnavailableError, |
| 21 | +) |
19 | 22 | from homeassistant.setup import async_setup_component |
20 | 23 | from homeassistant.util import dt as dt_util |
21 | 24 |
|
@@ -65,7 +68,7 @@ async def test_setup_component( |
65 | 68 | "homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth", |
66 | 69 | ) as mock_auth, |
67 | 70 | patch( |
68 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 71 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
69 | 72 | ) as mock_impl, |
70 | 73 | patch("homeassistant.components.netatmo.webhook_generate_url") as mock_webhook, |
71 | 74 | ): |
@@ -108,7 +111,7 @@ async def fake_post(*args, **kwargs): |
108 | 111 |
|
109 | 112 | with ( |
110 | 113 | patch( |
111 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 114 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
112 | 115 | ) as mock_impl, |
113 | 116 | patch("homeassistant.components.netatmo.webhook_generate_url") as mock_webhook, |
114 | 117 | patch( |
@@ -181,7 +184,7 @@ async def test_setup_without_https( |
181 | 184 | "homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth" |
182 | 185 | ) as mock_auth, |
183 | 186 | patch( |
184 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 187 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
185 | 188 | ), |
186 | 189 | patch( |
187 | 190 | "homeassistant.components.netatmo.webhook_generate_url" |
@@ -225,7 +228,7 @@ async def test_setup_with_cloud( |
225 | 228 | ) as mock_auth, |
226 | 229 | patch("homeassistant.components.netatmo.data_handler.PLATFORMS", []), |
227 | 230 | patch( |
228 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 231 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
229 | 232 | ), |
230 | 233 | patch( |
231 | 234 | "homeassistant.components.netatmo.webhook_generate_url", |
@@ -295,7 +298,7 @@ async def test_setup_with_cloudhook(hass: HomeAssistant) -> None: |
295 | 298 | ) as mock_auth, |
296 | 299 | patch("homeassistant.components.netatmo.data_handler.PLATFORMS", []), |
297 | 300 | patch( |
298 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 301 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
299 | 302 | ), |
300 | 303 | patch( |
301 | 304 | "homeassistant.components.netatmo.webhook_generate_url", |
@@ -340,7 +343,7 @@ async def test_setup_component_with_delay( |
340 | 343 | "pyatmo.AbstractAsyncAuth.async_dropwebhook", side_effect=AsyncMock() |
341 | 344 | ) as mock_dropwebhook, |
342 | 345 | patch( |
343 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 346 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
344 | 347 | ) as mock_impl, |
345 | 348 | patch("homeassistant.components.netatmo.webhook_generate_url") as mock_webhook, |
346 | 349 | patch( |
@@ -410,7 +413,7 @@ async def test_setup_component_invalid_token_scope(hass: HomeAssistant) -> None: |
410 | 413 | "homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth", |
411 | 414 | ) as mock_auth, |
412 | 415 | patch( |
413 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 416 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
414 | 417 | ) as mock_impl, |
415 | 418 | patch("homeassistant.components.netatmo.webhook_generate_url") as mock_webhook, |
416 | 419 | ): |
@@ -459,12 +462,10 @@ async def fake_ensure_valid_token(*args, **kwargs): |
459 | 462 | "homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth", |
460 | 463 | ) as mock_auth, |
461 | 464 | patch( |
462 | | - "homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation", |
| 465 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
463 | 466 | ) as mock_impl, |
464 | 467 | patch("homeassistant.components.netatmo.webhook_generate_url") as mock_webhook, |
465 | | - patch( |
466 | | - "homeassistant.helpers.config_entry_oauth2_flow.OAuth2Session" |
467 | | - ) as mock_session, |
| 468 | + patch("homeassistant.components.netatmo.OAuth2Session") as mock_session, |
468 | 469 | ): |
469 | 470 | mock_auth.return_value.async_post_api_request.side_effect = partial( |
470 | 471 | fake_post_request, hass |
@@ -557,3 +558,19 @@ async def test_device_remove_devices( |
557 | 558 | ) |
558 | 559 | response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) |
559 | 560 | assert response["success"] |
| 561 | + |
| 562 | + |
| 563 | +async def test_oauth_implementation_not_available( |
| 564 | + hass: HomeAssistant, config_entry: MockConfigEntry |
| 565 | +) -> None: |
| 566 | + """Test that unavailable OAuth implementation raises ConfigEntryNotReady.""" |
| 567 | + config_entry.add_to_hass(hass) |
| 568 | + |
| 569 | + with patch( |
| 570 | + "homeassistant.components.netatmo.async_get_config_entry_implementation", |
| 571 | + side_effect=ImplementationUnavailableError, |
| 572 | + ): |
| 573 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 574 | + await hass.async_block_till_done() |
| 575 | + |
| 576 | + assert config_entry.state is ConfigEntryState.SETUP_RETRY |
0 commit comments