Fix lingering timers in analytics (#91363)

This commit is contained in:
epenet 2023-04-14 06:37:22 +02:00 committed by GitHub
parent 7061b104a9
commit e39f0320df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ import voluptuous as vol
from homeassistant.components import websocket_api from homeassistant.components import websocket_api
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HassJob, HomeAssistant, callback
from homeassistant.helpers.event import async_call_later, async_track_time_interval from homeassistant.helpers.event import async_call_later, async_track_time_interval
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
@ -24,11 +24,23 @@ async def async_setup(hass: HomeAssistant, _: ConfigType) -> bool:
def start_schedule(_event: Event) -> None: def start_schedule(_event: Event) -> None:
"""Start the send schedule after the started event.""" """Start the send schedule after the started event."""
# Wait 15 min after started # Wait 15 min after started
async_call_later(hass, 900, analytics.send_analytics) async_call_later(
hass,
900,
HassJob(
analytics.send_analytics,
name="analytics schedule",
cancel_on_shutdown=True,
),
)
# Send every day # Send every day
async_track_time_interval( async_track_time_interval(
hass, analytics.send_analytics, INTERVAL, name="analytics daily" hass,
analytics.send_analytics,
INTERVAL,
name="analytics daily",
cancel_on_shutdown=True,
) )
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, start_schedule) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, start_schedule)