Replace hass.helpers: async_call_later() (#63929)

This commit is contained in:
Franck Nijhof 2022-01-11 22:30:59 +01:00 committed by GitHub
parent 259975c116
commit f4aa18de31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 12 deletions

View File

@ -32,6 +32,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_send,
)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.service import verify_domain_control
from homeassistant.helpers.typing import ConfigType
import homeassistant.util.dt as dt_util
@ -434,7 +435,7 @@ class EvoBroker:
return
if update_state: # wait a moment for system to quiesce before updating state
self.hass.helpers.event.async_call_later(1, self._update_v2_api_state)
async_call_later(self.hass, 1, self._update_v2_api_state)
return result

View File

@ -25,6 +25,7 @@ from homeassistant.const import (
from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client, device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.network import get_url
from .const import (
@ -136,8 +137,8 @@ class AlarmPanel:
# retry in a bit, never more than ~3 min
self.connect_attempts += 1
self.cancel_connect_retry = self.hass.helpers.event.async_call_later(
2 ** min(self.connect_attempts, 5) * 5, self.async_connect
self.cancel_connect_retry = async_call_later(
self.hass, 2 ** min(self.connect_attempts, 5) * 5, self.async_connect
)
return

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.event import async_call_later
from homeassistant.loader import Integration, async_get_custom_components
from .const import (
@ -101,7 +102,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
system_info = await hass.helpers.system_info.async_get_system_info()
# Update system info every hour
hass.helpers.event.async_call_later(3600, update_system_info)
async_call_later(hass, 3600, update_system_info)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, update_system_info)

View File

@ -48,6 +48,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_send,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.util.dt import utcnow
from .browse_media import build_item_response, generate_playlist, library_payload
@ -178,7 +179,7 @@ async def async_setup_entry(
hass.data[DOMAIN][config_entry.entry_id][
PLAYER_DISCOVERY_UNSUB
] = hass.helpers.event.async_call_later(DISCOVERY_INTERVAL, _discovery)
] = async_call_later(hass, DISCOVERY_INTERVAL, _discovery)
_LOGGER.debug("Adding player discovery job for LMS server: %s", host)
asyncio.create_task(_discovery())

View File

@ -19,6 +19,7 @@ from .const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP, Platfo
from .core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
from .exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, HomeAssistantError
from .helpers import device_registry, entity_registry
from .helpers.event import async_call_later
from .helpers.frame import report
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
from .setup import async_process_deps_reqs, async_setup_component
@ -375,8 +376,8 @@ class ConfigEntry:
await self.async_setup(hass, integration=integration, tries=tries)
if hass.state == CoreState.running:
self._async_cancel_retry_setup = hass.helpers.event.async_call_later(
wait_time, setup_again
self._async_cancel_retry_setup = async_call_later(
hass, wait_time, setup_again
)
else:
self._async_cancel_retry_setup = hass.bus.async_listen_once(
@ -1561,8 +1562,8 @@ class EntityRegistryDisabledHandler:
if self._remove_call_later:
self._remove_call_later()
self._remove_call_later = self.hass.helpers.event.async_call_later(
RELOAD_AFTER_UPDATE_DELAY, self._handle_reload
self._remove_call_later = async_call_later(
self.hass, RELOAD_AFTER_UPDATE_DELAY, self._handle_reload
)
async def _handle_reload(self, _now: Any) -> None:

View File

@ -886,7 +886,7 @@ async def test_setup_raise_not_ready(hass, caplog):
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
mock_entity_platform(hass, "config_flow.test", None)
with patch("homeassistant.helpers.event.async_call_later") as mock_call:
with patch("homeassistant.config_entries.async_call_later") as mock_call:
await entry.async_setup(hass)
assert len(mock_call.mock_calls) == 1
@ -921,7 +921,7 @@ async def test_setup_raise_not_ready_from_exception(hass, caplog):
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
mock_entity_platform(hass, "config_flow.test", None)
with patch("homeassistant.helpers.event.async_call_later") as mock_call:
with patch("homeassistant.config_entries.async_call_later") as mock_call:
await entry.async_setup(hass)
assert len(mock_call.mock_calls) == 1
@ -939,7 +939,7 @@ async def test_setup_retrying_during_unload(hass):
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
mock_entity_platform(hass, "config_flow.test", None)
with patch("homeassistant.helpers.event.async_call_later") as mock_call:
with patch("homeassistant.config_entries.async_call_later") as mock_call:
await entry.async_setup(hass)
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY