mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Use OptionsFlowWithReload in onewire (#149164)
This commit is contained in:
parent
6eab118a2d
commit
ff9fb6228b
@ -39,8 +39,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: OneWireConfigEntry) -> b
|
||||
|
||||
onewire_hub.schedule_scan_for_new_devices()
|
||||
|
||||
entry.async_on_unload(entry.add_update_listener(options_update_listener))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@ -59,11 +57,3 @@ async def async_unload_entry(
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, _PLATFORMS)
|
||||
|
||||
|
||||
async def options_update_listener(
|
||||
hass: HomeAssistant, entry: OneWireConfigEntry
|
||||
) -> None:
|
||||
"""Handle options update."""
|
||||
_LOGGER.debug("Configuration options updated, reloading OneWire integration")
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
@ -8,7 +8,11 @@ from typing import Any
|
||||
from pyownet import protocol
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
||||
from homeassistant.config_entries import (
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlowWithReload,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
@ -160,7 +164,7 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
return OnewireOptionsFlowHandler(config_entry)
|
||||
|
||||
|
||||
class OnewireOptionsFlowHandler(OptionsFlow):
|
||||
class OnewireOptionsFlowHandler(OptionsFlowWithReload):
|
||||
"""Handle OneWire Config options."""
|
||||
|
||||
configurable_devices: dict[str, str]
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Tests for 1-Wire config flow."""
|
||||
|
||||
from copy import deepcopy
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
@ -63,27 +62,6 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: MockConfigEntry)
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
async def test_update_options(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, owproxy: MagicMock
|
||||
) -> None:
|
||||
"""Test update options triggers reload."""
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert owproxy.call_count == 1
|
||||
|
||||
new_options = deepcopy(dict(config_entry.options))
|
||||
new_options["device_options"].clear()
|
||||
hass.config_entries.async_update_entry(config_entry, options=new_options)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
assert owproxy.call_count == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_registry(
|
||||
hass: HomeAssistant,
|
||||
|
Loading…
x
Reference in New Issue
Block a user