From 5f44ada3ea4ea465bdf6e1c0c3d0915cb2b1616f Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Fri, 30 Oct 2026 10:26:09 +0100 Subject: [PATCH] Raise `HomeAssistantError` when `AuthFailedError` occurs in the NAM integration (#189541) --- homeassistant/components/nam/button.py | 9 ++++++++- tests/components/nam/test_button.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/nam/button.py b/homeassistant/components/nam/button.py index 839560590511..afddf91d7b4d 100644 --- a/homeassistant/components/nam/button.py +++ b/homeassistant/components/nam/button.py @@ -62,5 +62,12 @@ class NAMButton(NAMEntity, ButtonEntity): "device": self.coordinator.config_entry.title, }, ) from err - except AuthFailedError: + except AuthFailedError as err: self.coordinator.config_entry.async_start_reauth(self.hass) + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="auth_error", + translation_placeholders={ + "device": self.coordinator.config_entry.title, + }, + ) from err diff --git a/tests/components/nam/test_button.py b/tests/components/nam/test_button.py index 0d3e84e79dcd..0baed52f2bd3 100644 --- a/tests/components/nam/test_button.py +++ b/tests/components/nam/test_button.py @@ -100,12 +100,16 @@ async def test_button_press_auth_error( await setup_integration(hass, mock_config_entry) mock_nam_client.async_restart.side_effect = AuthFailedError("auth error") - await hass.services.async_call( - BUTTON_DOMAIN, - SERVICE_PRESS, - {ATTR_ENTITY_ID: "button.nettigo_air_monitor_restart"}, - blocking=True, - ) + with pytest.raises( + HomeAssistantError, + match="Authentication failed for 10.10.2.3", + ): + await hass.services.async_call( + BUTTON_DOMAIN, + SERVICE_PRESS, + {ATTR_ENTITY_ID: "button.nettigo_air_monitor_restart"}, + blocking=True, + ) assert mock_config_entry.state is ConfigEntryState.LOADED