mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Do not crash the Synology DSM options on an unloaded entry (#180692)
This commit is contained in:
@@ -20,6 +20,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigEntryState,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlowWithReload,
|
||||
@@ -463,6 +464,10 @@ class SynologyDSMOptionsFlowHandler(OptionsFlowWithReload):
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle options flow."""
|
||||
# The shares to pick from come from the running connection
|
||||
if self.config_entry.state is not ConfigEntryState.LOADED:
|
||||
return self.async_abort(reason="entry_not_loaded")
|
||||
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(title="", data=user_input)
|
||||
|
||||
|
||||
@@ -241,6 +241,9 @@
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"abort": {
|
||||
"entry_not_loaded": "The integration is not loaded, so the shares to back up to cannot be listed."
|
||||
},
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
|
||||
@@ -21,7 +21,12 @@ from homeassistant.components.synology_dsm.const import (
|
||||
CONF_SNAPSHOT_QUALITY,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_SSDP,
|
||||
SOURCE_USER,
|
||||
SOURCE_ZEROCONF,
|
||||
ConfigEntryState,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
@@ -707,6 +712,32 @@ async def test_options_flow(
|
||||
assert config_entry.options[CONF_BACKUP_SHARE] == "/ha_backup"
|
||||
|
||||
|
||||
async def test_options_flow_entry_not_loaded(
|
||||
hass: HomeAssistant, service_with_filestation: MagicMock
|
||||
) -> None:
|
||||
"""Test the options flow aborts when the integration is not loaded."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_MAC: MACS[0],
|
||||
},
|
||||
unique_id=SERIAL,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "entry_not_loaded"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_discovered_via_zeroconf(
|
||||
hass: HomeAssistant, service: MagicMock, snapshot: SnapshotAssertion
|
||||
|
||||
Reference in New Issue
Block a user