Skip to content

Commit

Permalink
Fix #745, first time YAML setup (#752)
Browse files Browse the repository at this point in the history
* Check whether this is the first time setup

* Keep list

* simplify

* no UI tracking
  • Loading branch information
basnijholt authored Aug 15, 2023
1 parent e9b7988 commit 0e23e90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions custom_components/adaptive_lighting/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, "
Expand Down

0 comments on commit 0e23e90

Please sign in to comment.