Return unsubscribe callback from start.async_at_start (#69083)
* Return unsubscribe callback from start.async_at_start * Update calling code
This commit is contained in:
parent
4b5996c5ed
commit
ae9c2df691
4 changed files with 8 additions and 8 deletions
|
@ -454,7 +454,7 @@ class GroupEntity(Entity):
|
|||
self.async_update_group_state()
|
||||
self.async_write_ha_state()
|
||||
|
||||
start.async_at_start(self.hass, _update_at_start)
|
||||
self.async_on_remove(start.async_at_start(self.hass, _update_at_start))
|
||||
|
||||
@callback
|
||||
def async_defer_or_update_ha_state(self) -> None:
|
||||
|
@ -689,7 +689,7 @@ class Group(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle addition to Home Assistant."""
|
||||
start.async_at_start(self.hass, self._async_start)
|
||||
self.async_on_remove(start.async_at_start(self.hass, self._async_start))
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Handle removal from Home Assistant."""
|
||||
|
|
|
@ -247,7 +247,7 @@ class HERETravelTimeSensor(SensorEntity, CoordinatorEntity):
|
|||
async def _update_at_start(_):
|
||||
await self.async_update()
|
||||
|
||||
async_at_start(self.hass, _update_at_start)
|
||||
self.async_on_remove(async_at_start(self.hass, _update_at_start))
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | None:
|
||||
|
|
|
@ -302,7 +302,7 @@ class StatisticsSensor(SensorEntity):
|
|||
if "recorder" in self.hass.config.components:
|
||||
self.hass.async_create_task(self._initialize_from_database())
|
||||
|
||||
async_at_start(self.hass, async_stats_sensor_startup)
|
||||
self.async_on_remove(async_at_start(self.hass, async_stats_sensor_startup))
|
||||
|
||||
def _add_state_to_queue(self, new_state: State) -> None:
|
||||
"""Add the state to the queue."""
|
||||
|
|
|
@ -4,13 +4,13 @@ from __future__ import annotations
|
|||
from collections.abc import Awaitable, Callable
|
||||
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.core import Event, HassJob, HomeAssistant, callback
|
||||
from homeassistant.core import CALLBACK_TYPE, Event, HassJob, HomeAssistant, callback
|
||||
|
||||
|
||||
@callback
|
||||
def async_at_start(
|
||||
hass: HomeAssistant, at_start_cb: Callable[[HomeAssistant], Awaitable[None] | None]
|
||||
) -> None:
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Execute something when Home Assistant is started.
|
||||
|
||||
Will execute it now if Home Assistant is already started.
|
||||
|
@ -18,10 +18,10 @@ def async_at_start(
|
|||
at_start_job = HassJob(at_start_cb)
|
||||
if hass.is_running:
|
||||
hass.async_run_hass_job(at_start_job, hass)
|
||||
return
|
||||
return lambda: None
|
||||
|
||||
async def _matched_event(event: Event) -> None:
|
||||
"""Call the callback when Home Assistant started."""
|
||||
hass.async_run_hass_job(at_start_job, hass)
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _matched_event)
|
||||
return hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _matched_event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue