From 1a2cd7399d99a8dece62d6ad1c99cc7a5448c855 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 9 Apr 2024 08:59:18 +0200 Subject: [PATCH] Fix for HA <= 2024.3, closes #973 (#974) * Fix for HA <= 2024.3, closes #973 * Link --- custom_components/adaptive_lighting/manifest.json | 2 +- custom_components/adaptive_lighting/switch.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index 96cec4ac..2ec04e27 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -8,5 +8,5 @@ "iot_class": "calculated", "issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues", "requirements": ["ulid-transform"], - "version": "1.21.0" + "version": "1.21.1" } diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 9408d90b..2b23c71c 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -60,6 +60,7 @@ STATE_OFF, STATE_ON, ) +from homeassistant.const import __version__ as ha_version from homeassistant.core import ( CALLBACK_TYPE, Context, @@ -949,10 +950,15 @@ async def async_added_to_hass(self) -> None: if self.hass.is_running: await self._setup_listeners() else: + kw = {} + year, month = (int(x) for x in ha_version.split(".")[:2]) + if (year, month) >= (2024, 4): + # Added in https://github.com/home-assistant/core/pull/113020 + kw["run_immediately"] = False self.hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STARTED, self._setup_listeners, - run_immediately=False, + **kw, ) last_state: State | None = await self.async_get_last_state() is_new_entry = last_state is None # newly added to HA