Fix for HA <= 2024.3, closes #973 (#974)

* Fix for HA <= 2024.3, closes #973

* Link
This commit is contained in:
Bas Nijholt 2024-04-09 08:59:18 +02:00 committed by GitHub
commit 1a2cd7399d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -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"
}

View file

@ -60,6 +60,7 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
)
from homeassistant.const import __version__ as ha_version
from homeassistant.core import (
CALLBACK_TYPE,
Context,
@ -949,10 +950,15 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
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