Use OptionsFlowWithReload in unifiprotect (#149064)

This commit is contained in:
G Johansson
2025-07-19 17:40:16 +02:00
committed by GitHub
parent c15bf097f0
commit 7e04a7ec19
3 changed files with 3 additions and 26 deletions

View File

@ -114,7 +114,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: UFPConfigEntry) -> bool:
hass.config_entries.async_update_entry(entry, unique_id=nvr_info.mac)
entry.runtime_data = data_service
entry.async_on_unload(entry.add_update_listener(_async_options_updated))
entry.async_on_unload(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, data_service.async_stop)
)
@ -139,11 +138,6 @@ async def _async_setup_entry(
hass.http.register_view(VideoEventProxyView(hass))
async def _async_options_updated(hass: HomeAssistant, entry: UFPConfigEntry) -> None:
"""Update options."""
await hass.config_entries.async_reload(entry.entry_id)
async def async_unload_entry(hass: HomeAssistant, entry: UFPConfigEntry) -> bool:
"""Unload UniFi Protect config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):

View File

@ -20,7 +20,7 @@ from homeassistant.config_entries import (
ConfigEntryState,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
OptionsFlowWithReload,
)
from homeassistant.const import (
CONF_HOST,
@ -223,7 +223,7 @@ class ProtectFlowHandler(ConfigFlow, domain=DOMAIN):
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
) -> OptionsFlow:
) -> OptionsFlowHandler:
"""Get the options flow for this handler."""
return OptionsFlowHandler()
@ -372,7 +372,7 @@ class ProtectFlowHandler(ConfigFlow, domain=DOMAIN):
)
class OptionsFlowHandler(OptionsFlow):
class OptionsFlowHandler(OptionsFlowWithReload):
"""Handle options."""
async def async_step_init(

View File

@ -12,7 +12,6 @@ from uiprotect.data import NVR, Bootstrap, CloudAccount, Light
from homeassistant.components.unifiprotect.const import (
AUTH_RETRIES,
CONF_ALLOW_EA,
CONF_DISABLE_RTSP,
DOMAIN,
)
from homeassistant.components.unifiprotect.data import (
@ -87,22 +86,6 @@ async def test_setup_multiple(
assert mock_config.unique_id == ufp.api.bootstrap.nvr.mac
async def test_reload(hass: HomeAssistant, ufp: MockUFPFixture) -> None:
"""Test updating entry reload entry."""
await hass.config_entries.async_setup(ufp.entry.entry_id)
await hass.async_block_till_done()
assert ufp.entry.state is ConfigEntryState.LOADED
options = dict(ufp.entry.options)
options[CONF_DISABLE_RTSP] = True
hass.config_entries.async_update_entry(ufp.entry, options=options)
await hass.async_block_till_done()
assert ufp.entry.state is ConfigEntryState.LOADED
assert ufp.api.async_disconnect_ws.called
async def test_unload(hass: HomeAssistant, ufp: MockUFPFixture, light: Light) -> None:
"""Test unloading of unifiprotect entry."""