From 174717dd85a2dd11cbea680520510b0dad175ec4 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 1 May 2022 21:00:38 +0200 Subject: [PATCH] Abort UniFi Network options flow if integration is not setup (#71128) --- homeassistant/components/unifi/config_flow.py | 2 ++ homeassistant/components/unifi/strings.json | 5 ++++- homeassistant/components/unifi/translations/en.json | 3 +++ tests/components/unifi/test_config_flow.py | 11 +++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/unifi/config_flow.py b/homeassistant/components/unifi/config_flow.py index 6e40798fb7a..d02f3f49a5e 100644 --- a/homeassistant/components/unifi/config_flow.py +++ b/homeassistant/components/unifi/config_flow.py @@ -256,6 +256,8 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow): async def async_step_init(self, user_input=None): """Manage the UniFi Network options.""" + if self.config_entry.entry_id not in self.hass.data[UNIFI_DOMAIN]: + return self.async_abort(reason="integration_not_setup") self.controller = self.hass.data[UNIFI_DOMAIN][self.config_entry.entry_id] self.options[CONF_BLOCK_CLIENT] = self.controller.option_block_clients diff --git a/homeassistant/components/unifi/strings.json b/homeassistant/components/unifi/strings.json index 476a0bfdd61..8d6df90b704 100644 --- a/homeassistant/components/unifi/strings.json +++ b/homeassistant/components/unifi/strings.json @@ -21,11 +21,14 @@ }, "abort": { "already_configured": "UniFi Network site is already configured", - "configuration_updated": "Configuration updated.", + "configuration_updated": "Configuration updated", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } }, "options": { + "abort": { + "integration_not_setup": "UniFi integration is not setup" + }, "step": { "device_tracker": { "data": { diff --git a/homeassistant/components/unifi/translations/en.json b/homeassistant/components/unifi/translations/en.json index 5d08c8b816d..2a1c17cb6e3 100644 --- a/homeassistant/components/unifi/translations/en.json +++ b/homeassistant/components/unifi/translations/en.json @@ -26,6 +26,9 @@ } }, "options": { + "abort": { + "integration_not_setup": "UniFi integration is not setup" + }, "step": { "client_control": { "data": { diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index 4c4ff7006fd..321cbdfd9e8 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -542,6 +542,17 @@ async def test_simple_option_flow(hass, aioclient_mock): } +async def test_option_flow_integration_not_setup(hass, aioclient_mock): + """Test advanced config flow options.""" + config_entry = await setup_unifi_integration(hass, aioclient_mock) + + hass.data[UNIFI_DOMAIN].pop(config_entry.entry_id) + result = await hass.config_entries.options.async_init(config_entry.entry_id) + + assert result["type"] == "abort" + assert result["reason"] == "integration_not_setup" + + async def test_form_ssdp(hass): """Test we get the form with ssdp source."""