mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve type hints in duckdns (#87270)
This commit is contained in:
parent
695a453159
commit
9306e0371e
@ -1,6 +1,8 @@
|
|||||||
"""Integrate with DuckDNS."""
|
"""Integrate with DuckDNS."""
|
||||||
from datetime import timedelta
|
from collections.abc import Callable, Coroutine
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -100,14 +102,18 @@ async def _update_duckdns(session, domain, token, *, txt=_SENTINEL, clear=False)
|
|||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_track_time_interval_backoff(hass, action, intervals) -> CALLBACK_TYPE:
|
def async_track_time_interval_backoff(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
action: Callable[[datetime], Coroutine[Any, Any, bool]],
|
||||||
|
intervals,
|
||||||
|
) -> CALLBACK_TYPE:
|
||||||
"""Add a listener that fires repetitively at every timedelta interval."""
|
"""Add a listener that fires repetitively at every timedelta interval."""
|
||||||
if not isinstance(intervals, (list, tuple)):
|
if not isinstance(intervals, (list, tuple)):
|
||||||
intervals = (intervals,)
|
intervals = (intervals,)
|
||||||
remove = None
|
remove = None
|
||||||
failed = 0
|
failed = 0
|
||||||
|
|
||||||
async def interval_listener(now):
|
async def interval_listener(now: datetime) -> None:
|
||||||
"""Handle elapsed intervals with backoff."""
|
"""Handle elapsed intervals with backoff."""
|
||||||
nonlocal failed, remove
|
nonlocal failed, remove
|
||||||
try:
|
try:
|
||||||
@ -120,7 +126,7 @@ def async_track_time_interval_backoff(hass, action, intervals) -> CALLBACK_TYPE:
|
|||||||
|
|
||||||
hass.async_run_job(interval_listener, dt_util.utcnow())
|
hass.async_run_job(interval_listener, dt_util.utcnow())
|
||||||
|
|
||||||
def remove_listener():
|
def remove_listener() -> None:
|
||||||
"""Remove interval listener."""
|
"""Remove interval listener."""
|
||||||
if remove:
|
if remove:
|
||||||
remove() # pylint: disable=not-callable
|
remove() # pylint: disable=not-callable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user