Dump states in event handler for HA_Stop (#33974)

* Dump states in event handler for HA_Stop

* Fix type
This commit is contained in:
Paulus Schoutsen 2020-04-13 17:41:01 -07:00 committed by GitHub
parent 89fe488b7c
commit 5a9970e63c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 10 deletions

View file

@ -361,7 +361,9 @@ class HomeAssistant:
self._track_task = False self._track_task = False
@callback @callback
def async_run_job(self, target: Callable[..., None], *args: Any) -> None: def async_run_job(
self, target: Callable[..., Union[None, Awaitable]], *args: Any
) -> None:
"""Run a job from within the event loop. """Run a job from within the event loop.
This method must be run in the event loop. This method must be run in the event loop.

View file

@ -300,9 +300,7 @@ class EntityPlatform:
return return
self._async_unsub_polling = async_track_time_interval( self._async_unsub_polling = async_track_time_interval(
self.hass, self.hass, self._update_entity_states, self.scan_interval,
self._update_entity_states, # type: ignore
self.scan_interval,
) )
async def _async_add_entity( async def _async_add_entity(

View file

@ -1,7 +1,7 @@
"""Helpers for listening to events.""" """Helpers for listening to events."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
import functools as ft import functools as ft
from typing import Any, Callable, Dict, Iterable, Optional, Union, cast from typing import Any, Awaitable, Callable, Dict, Iterable, Optional, Union, cast
import attr import attr
@ -274,7 +274,9 @@ call_later = threaded_listener_factory(async_call_later)
@callback @callback
@bind_hass @bind_hass
def async_track_time_interval( def async_track_time_interval(
hass: HomeAssistant, action: Callable[..., None], interval: timedelta hass: HomeAssistant,
action: Callable[..., Union[None, Awaitable]],
interval: timedelta,
) -> CALLBACK_TYPE: ) -> CALLBACK_TYPE:
"""Add a listener that fires repetitively at every timedelta interval.""" """Add a listener that fires repetitively at every timedelta interval."""
remove = None remove = None

View file

@ -171,14 +171,13 @@ class RestoreStateData:
def async_setup_dump(self, *args: Any) -> None: def async_setup_dump(self, *args: Any) -> None:
"""Set up the restore state listeners.""" """Set up the restore state listeners."""
@callback async def _async_dump_states(*_: Any) -> None:
def _async_dump_states(*_: Any) -> None: await self.async_dump_states()
self.hass.async_create_task(self.async_dump_states())
# Dump the initial states now. This helps minimize the risk of having # Dump the initial states now. This helps minimize the risk of having
# old states loaded by overwriting the last states once Home Assistant # old states loaded by overwriting the last states once Home Assistant
# has started and the old states have been read. # has started and the old states have been read.
_async_dump_states() self.hass.async_create_task(_async_dump_states())
# Dump states periodically # Dump states periodically
async_track_time_interval(self.hass, _async_dump_states, STATE_DUMP_INTERVAL) async_track_time_interval(self.hass, _async_dump_states, STATE_DUMP_INTERVAL)