From c466008fb4910d7e8d37de8e094936fbd45673c8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 13 Mar 2024 23:45:59 -1000 Subject: [PATCH] Migrate sun to use single_config_entry (#113370) --- homeassistant/components/sun/__init__.py | 16 ++++++++++------ homeassistant/components/sun/config_flow.py | 3 --- homeassistant/components/sun/manifest.json | 3 ++- homeassistant/components/sun/strings.json | 3 --- homeassistant/generated/integrations.json | 3 ++- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/sun/__init__.py b/homeassistant/components/sun/__init__.py index 0c494b7a268..a4964c94009 100644 --- a/homeassistant/components/sun/__init__.py +++ b/homeassistant/components/sun/__init__.py @@ -84,13 +84,17 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Track the state of the sun.""" - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, + if not hass.config_entries.async_entries(DOMAIN): + # We avoid creating an import flow if its already + # setup since it will have to import the config_flow + # module. + hass.async_create_task( + hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_IMPORT}, + data=config, + ) ) - ) return True diff --git a/homeassistant/components/sun/config_flow.py b/homeassistant/components/sun/config_flow.py index 399373c8cb4..30b64c60b9f 100644 --- a/homeassistant/components/sun/config_flow.py +++ b/homeassistant/components/sun/config_flow.py @@ -18,9 +18,6 @@ class SunConfigFlow(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Handle a flow initialized by the user.""" - if self._async_current_entries(): - return self.async_abort(reason="single_instance_allowed") - if user_input is not None: return self.async_create_entry(title=DEFAULT_NAME, data={}) diff --git a/homeassistant/components/sun/manifest.json b/homeassistant/components/sun/manifest.json index 2fdcaafe114..f6b4ae1976b 100644 --- a/homeassistant/components/sun/manifest.json +++ b/homeassistant/components/sun/manifest.json @@ -5,5 +5,6 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/sun", "iot_class": "calculated", - "quality_scale": "internal" + "quality_scale": "internal", + "single_config_entry": true } diff --git a/homeassistant/components/sun/strings.json b/homeassistant/components/sun/strings.json index eb538eedf09..7c7accd8cc6 100644 --- a/homeassistant/components/sun/strings.json +++ b/homeassistant/components/sun/strings.json @@ -5,9 +5,6 @@ "user": { "description": "[%key:common::config_flow::description::confirm_setup%]" } - }, - "abort": { - "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } }, "entity_component": { diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index a84a78324cf..e745c52db69 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -5743,7 +5743,8 @@ "sun": { "integration_type": "hub", "config_flow": true, - "iot_class": "calculated" + "iot_class": "calculated", + "single_config_entry": true }, "sunweg": { "name": "Sun WEG",