File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
homeassistant/components/weheat Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1414from homeassistant .exceptions import ConfigEntryAuthFailed , ConfigEntryNotReady
1515from homeassistant .helpers .aiohttp_client import async_get_clientsession
1616from homeassistant .helpers .config_entry_oauth2_flow import (
17+ ImplementationUnavailableError ,
1718 OAuth2Session ,
1819 async_get_config_entry_implementation ,
1920)
2021
21- from .const import API_URL , LOGGER
22+ from .const import API_URL , DOMAIN , LOGGER
2223from .coordinator import (
2324 HeatPumpInfo ,
2425 WeheatConfigEntry ,
3233
3334async def async_setup_entry (hass : HomeAssistant , entry : WeheatConfigEntry ) -> bool :
3435 """Set up Weheat from a config entry."""
35- implementation = await async_get_config_entry_implementation (hass , entry )
36+ try :
37+ implementation = await async_get_config_entry_implementation (hass , entry )
38+ except ImplementationUnavailableError as err :
39+ raise ConfigEntryNotReady (
40+ translation_domain = DOMAIN ,
41+ translation_key = "oauth2_implementation_unavailable" ,
42+ ) from err
3643
3744 session = OAuth2Session (hass , entry , implementation )
3845
Original file line number Diff line number Diff line change 124124 "name" : " Water outlet temperature"
125125 }
126126 }
127+ },
128+ "exceptions" : {
129+ "oauth2_implementation_unavailable" : {
130+ "message" : " [%key:common::exceptions::oauth2_implementation_unavailable::message%]"
131+ }
127132 }
128133}
Original file line number Diff line number Diff line change 99from homeassistant .components .weheat import UnauthorizedException
1010from homeassistant .config_entries import ConfigEntryState
1111from homeassistant .core import HomeAssistant
12+ from homeassistant .helpers .config_entry_oauth2_flow import (
13+ ImplementationUnavailableError ,
14+ )
1215
1316from . import setup_integration
1417
@@ -83,3 +86,21 @@ async def test_setup_fail_discover(
8386 await setup_integration (hass , mock_config_entry )
8487
8588 assert mock_config_entry .state is ConfigEntryState .SETUP_ERROR
89+
90+
91+ @pytest .mark .usefixtures ("setup_credentials" )
92+ async def test_oauth_implementation_not_available (
93+ hass : HomeAssistant ,
94+ mock_config_entry : MockConfigEntry ,
95+ ) -> None :
96+ """Test that unavailable OAuth implementation raises ConfigEntryNotReady."""
97+ mock_config_entry .add_to_hass (hass )
98+
99+ with patch (
100+ "homeassistant.components.weheat.async_get_config_entry_implementation" ,
101+ side_effect = ImplementationUnavailableError ,
102+ ):
103+ await hass .config_entries .async_setup (mock_config_entry .entry_id )
104+ await hass .async_block_till_done ()
105+
106+ assert mock_config_entry .state is ConfigEntryState .SETUP_RETRY
You can’t perform that action at this time.
0 commit comments