Add reauth support to NUT (#114131)

This commit is contained in:
J. Nick Koston 2024-03-25 07:59:46 -10:00 committed by GitHub
parent 135c40cad8
commit c3f4aca4e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 295 additions and 71 deletions

View file

@ -2,7 +2,7 @@
from unittest.mock import patch
from aionut import NUTError
from aionut import NUTError, NUTLoginError
from homeassistant.components.nut.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
@ -66,3 +66,27 @@ async def test_config_not_ready(hass: HomeAssistant) -> None:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_auth_fails(hass: HomeAssistant) -> None:
"""Test for setup failure if auth has changed."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: "mock", CONF_PORT: "mock"},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.nut.AIONUTClient.list_ups",
return_value={"ups1"},
), patch(
"homeassistant.components.nut.AIONUTClient.list_vars",
side_effect=NUTLoginError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.SETUP_ERROR
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
assert flows[0]["context"]["source"] == "reauth"