Do not crash the Synology DSM options on an unloaded entry (#180692)

This commit is contained in:
Franck Nijhof
2026-08-31 08:51:03 +00:00
parent 2952e31c18
commit 30ca4465c8
3 changed files with 40 additions and 1 deletions
@@ -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