mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 21:29:58 -04:00
Raise HomeAssistantError when AuthFailedError occurs in the NAM integration (#189541)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user