mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Remove runtime_data dependency from SIA options flow (#174489)
This commit is contained in:
@@ -29,7 +29,7 @@ from .const import (
|
||||
DOMAIN,
|
||||
TITLE,
|
||||
)
|
||||
from .hub import SIAConfigEntry, SIAHub
|
||||
from .hub import SIAConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -180,17 +180,15 @@ class SIAOptionsFlowHandler(OptionsFlow):
|
||||
def __init__(self, config_entry: SIAConfigEntry) -> None:
|
||||
"""Initialize SIA options flow."""
|
||||
self.options = deepcopy(dict(config_entry.options))
|
||||
self.hub: SIAHub | None = None
|
||||
self.accounts_todo: list = []
|
||||
self.accounts_todo: list[str] = []
|
||||
|
||||
async def async_step_init(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Manage the SIA options."""
|
||||
self.hub = self.config_entry.runtime_data
|
||||
assert self.hub is not None
|
||||
assert self.hub.sia_accounts is not None
|
||||
self.accounts_todo = [a.account_id for a in self.hub.sia_accounts]
|
||||
self.accounts_todo = [
|
||||
a[CONF_ACCOUNT] for a in self.config_entry.data[CONF_ACCOUNTS]
|
||||
]
|
||||
return await self.async_step_options()
|
||||
|
||||
async def async_step_options(
|
||||
|
||||
@@ -312,6 +312,30 @@ async def test_unknown_account(hass: HomeAssistant, flow_at_user_step) -> None:
|
||||
assert result_err["data_schema"] == ACCOUNT_SCHEMA
|
||||
|
||||
|
||||
async def test_options_not_loaded(hass: HomeAssistant) -> None:
|
||||
"""Test options flow works when entry is not loaded."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=BASE_OUT["data"],
|
||||
options=BASE_OUT["options"],
|
||||
title="SIA Alarm on port 7777",
|
||||
entry_id=BASIS_CONFIG_ENTRY_ID,
|
||||
version=1,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "options"
|
||||
|
||||
updated = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"], BASIC_OPTIONS
|
||||
)
|
||||
assert updated["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert updated["data"] == {
|
||||
CONF_ACCOUNTS: {BASIC_CONFIG[CONF_ACCOUNT]: BASIC_OPTIONS}
|
||||
}
|
||||
|
||||
|
||||
async def test_options_basic(hass: HomeAssistant) -> None:
|
||||
"""Test options flow for single account."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
||||
Reference in New Issue
Block a user