Use OptionsFlowWithReload in motioneye (#149130)

This commit is contained in:
G Johansson 2025-07-21 08:15:51 +02:00 committed by GitHub
parent bc9ad5eac6
commit 00c4b09773
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 11 deletions

View File

@ -277,11 +277,6 @@ def _add_camera(
) )
async def _async_entry_updated(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Handle entry updates."""
await hass.config_entries.async_reload(config_entry.entry_id)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up motionEye from a config entry.""" """Set up motionEye from a config entry."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
@ -382,7 +377,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator.async_add_listener(_async_process_motioneye_cameras) coordinator.async_add_listener(_async_process_motioneye_cameras)
) )
await coordinator.async_refresh() await coordinator.async_refresh()
entry.async_on_unload(entry.add_update_listener(_async_entry_updated))
return True return True

View File

@ -17,7 +17,7 @@ from homeassistant.config_entries import (
ConfigEntry, ConfigEntry,
ConfigFlow, ConfigFlow,
ConfigFlowResult, ConfigFlowResult,
OptionsFlow, OptionsFlowWithReload,
) )
from homeassistant.const import CONF_URL, CONF_WEBHOOK_ID from homeassistant.const import CONF_URL, CONF_WEBHOOK_ID
from homeassistant.core import callback from homeassistant.core import callback
@ -186,7 +186,7 @@ class MotionEyeConfigFlow(ConfigFlow, domain=DOMAIN):
return MotionEyeOptionsFlow() return MotionEyeOptionsFlow()
class MotionEyeOptionsFlow(OptionsFlow): class MotionEyeOptionsFlow(OptionsFlowWithReload):
"""motionEye options flow.""" """motionEye options flow."""
async def async_step_init( async def async_step_init(

View File

@ -532,7 +532,7 @@ async def test_advanced_options(hass: HomeAssistant) -> None:
assert result["data"][CONF_WEBHOOK_SET_OVERWRITE] assert result["data"][CONF_WEBHOOK_SET_OVERWRITE]
assert CONF_STREAM_URL_TEMPLATE not in result["data"] assert CONF_STREAM_URL_TEMPLATE not in result["data"]
assert len(mock_setup.mock_calls) == 0 assert len(mock_setup.mock_calls) == 0
assert len(mock_setup_entry.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 1
result = await hass.config_entries.options.async_init( result = await hass.config_entries.options.async_init(
config_entry.entry_id, context={"show_advanced_options": True} config_entry.entry_id, context={"show_advanced_options": True}
@ -551,4 +551,4 @@ async def test_advanced_options(hass: HomeAssistant) -> None:
assert result["data"][CONF_WEBHOOK_SET_OVERWRITE] assert result["data"][CONF_WEBHOOK_SET_OVERWRITE]
assert result["data"][CONF_STREAM_URL_TEMPLATE] == "http://moo" assert result["data"][CONF_STREAM_URL_TEMPLATE] == "http://moo"
assert len(mock_setup.mock_calls) == 0 assert len(mock_setup.mock_calls) == 0
assert len(mock_setup_entry.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 1

View File

@ -116,7 +116,6 @@ async def test_setup_camera_with_wrong_webhook(
) )
assert not client.async_set_camera.called assert not client.async_set_camera.called
# Update the options, which will trigger a reload with the new behavior.
with patch( with patch(
"homeassistant.components.motioneye.MotionEyeClient", "homeassistant.components.motioneye.MotionEyeClient",
return_value=client, return_value=client,
@ -124,6 +123,7 @@ async def test_setup_camera_with_wrong_webhook(
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
config_entry, options={CONF_WEBHOOK_SET_OVERWRITE: True} config_entry, options={CONF_WEBHOOK_SET_OVERWRITE: True}
) )
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
device = device_registry.async_get_device( device = device_registry.async_get_device(