From 0e23e906dadd44127b2eebc51d1fd632549f4986 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 15 Aug 2023 14:47:43 -0700 Subject: [PATCH] Fix #745, first time YAML setup (#752) * Check whether this is the first time setup * Keep list * simplify * no UI tracking --- custom_components/adaptive_lighting/config_flow.py | 8 +++++--- custom_components/adaptive_lighting/switch.py | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 3dd89fd4..8f82582a 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -42,13 +42,15 @@ async def async_step_user(self, user_input=None): async def async_step_import(self, user_input=None): """Handle configuration by YAML file.""" await self.async_set_unique_id(user_input[CONF_NAME]) + # Keep a list of switches that are configured via YAML + data = self.hass.data.setdefault(DOMAIN, {}) + data.setdefault("__yaml__", set()).add(self.unique_id) + for entry in self._async_current_entries(): if entry.unique_id == self.unique_id: - # Keep a list of switches that are configured via YAML - data = self.hass.data.setdefault(DOMAIN, {}) - data.setdefault("__yaml__", []).append(self.unique_id) self.hass.config_entries.async_update_entry(entry, data=user_input) self._abort_if_unique_id_configured() + return self.async_create_entry(title=user_input[CONF_NAME], data=user_input) @staticmethod diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 5f69dd5f..ff951d15 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -410,9 +410,9 @@ async def async_setup_entry( # noqa: PLR0915 data, config_entry, ) - if ( # Skip deleted YAML config entries + if ( # Skip deleted YAML config entries or first time YAML config entries config_entry.source == SOURCE_IMPORT - and config_entry.unique_id not in data.get("__yaml__", []) + and config_entry.unique_id not in data.get("__yaml__", set()) ): _LOGGER.warning( "Deleting AdaptiveLighting switch '%s' because YAML" @@ -1680,8 +1680,6 @@ def __init__(self, hass: HomeAssistant) -> None: self._service_interceptor_turn_on_handler, ), ) - - _LOGGER.debug("Proactive adaptation enabled") except RuntimeError: _LOGGER.warning( "Failed to set up service call interceptors, "