Compare commits

...

3 Commits

Author SHA1 Message Date
abmantis 5669eb583e Fix google sheets test 2026-05-28 20:00:31 +01:00
abmantis f059eef5aa Merge branch 'dev' of github.com:home-assistant/core into authfailed_noflow 2026-05-28 19:49:48 +01:00
abmantis 1bde5f0d6c Skip reauth flow on ConfigEntryAuthFailed when integration has none 2026-05-28 19:08:04 +01:00
4 changed files with 47 additions and 4 deletions
+14 -1
View File
@@ -824,7 +824,7 @@ class ConfigEntry[_DataT = Any]:
auth_message,
)
logger.debug("Full exception", exc_info=True)
self.async_start_reauth(hass)
self.async_start_reauth_if_available(hass)
except ConfigEntryNotReady as exc:
message = str(exc)
error_reason_translation_key = exc.translation_key
@@ -1290,6 +1290,19 @@ class ConfigEntry[_DataT = Any]:
eager_start=True,
)
@callback
def async_start_reauth_if_available(
self,
hass: HomeAssistant,
context: ConfigFlowContext | None = None,
data: dict[str, Any] | None = None,
) -> None:
"""Start a reauth flow only if the integration implements one."""
handler = HANDLERS.get(self.domain)
if handler is None or not hasattr(handler, "async_step_reauth"):
return
self.async_start_reauth(hass, context, data)
async def _async_init_reauth(
self,
hass: HomeAssistant,
+2 -2
View File
@@ -458,7 +458,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
raise ConfigEntryAuthFailed from err
if self.config_entry:
self.config_entry.async_start_reauth(self.hass)
self.config_entry.async_start_reauth_if_available(self.hass)
return
# Recoverable error
@@ -536,7 +536,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
raise
if self.config_entry:
self.config_entry.async_start_reauth(self.hass)
self.config_entry.async_start_reauth_if_available(self.hass)
except NotImplementedError as err:
self.last_exception = err
self.last_update_success = False
+1 -1
View File
@@ -235,7 +235,7 @@ async def test_setup_oauth_reauth_error(
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.SETUP_ERROR
mock_async_start_reauth.assert_called_once_with(hass)
mock_async_start_reauth.assert_called_once_with(hass, None, None)
async def test_setup_oauth_transient_error(
+30
View File
@@ -5755,6 +5755,36 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(
assert len(flows) == 1
async def test_setup_raise_auth_failed_without_reauth_flow(
hass: HomeAssistant,
manager: config_entries.ConfigEntries,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test ConfigEntryAuthFailed when the integration has no reauth flow."""
entry = MockConfigEntry(title="test_title", domain="test")
entry.add_to_hass(hass)
mock_setup_entry = AsyncMock(
side_effect=ConfigEntryAuthFailed("The password is no longer valid")
)
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
mock_platform(hass, "test.config_flow", None)
class NoReauthFlow(config_entries.ConfigFlow):
"""Config flow without reauth support."""
VERSION = 1
with mock_config_flow("test", NoReauthFlow):
await manager.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert "could not authenticate: The password is no longer valid" in caplog.text
assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR
assert entry.reason == "The password is no longer valid"
assert len(hass.config_entries.flow.async_progress()) == 0
async def test_initialize_and_shutdown(hass: HomeAssistant) -> None:
"""Test we call the shutdown function at stop."""
manager = config_entries.ConfigEntries(hass, {})