Fix #745, first time YAML setup (#752)

* Check whether this is the first time setup

* Keep list

* simplify

* no UI tracking
This commit is contained in:
Bas Nijholt 2023-08-15 14:47:43 -07:00 committed by GitHub
commit 0e23e906da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -42,13 +42,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
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

View file

@ -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 @@ class AdaptiveLightingManager:
self._service_interceptor_turn_on_handler,
),
)
_LOGGER.debug("Proactive adaptation enabled")
except RuntimeError:
_LOGGER.warning(
"Failed to set up service call interceptors, "