Skip to content

Commit

Permalink
Enable strict typing for duckdns (home-assistant#108022)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Jan 15, 2024
1 parent 5bde007 commit 16f1106
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ homeassistant.components.doorbird.*
homeassistant.components.dormakaba_dkey.*
homeassistant.components.downloader.*
homeassistant.components.dsmr.*
homeassistant.components.duckdns.*
homeassistant.components.dunehd.*
homeassistant.components.duotecno.*
homeassistant.components.easyenergy.*
Expand Down
28 changes: 18 additions & 10 deletions homeassistant/components/duckdns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Integrate with DuckDNS."""
from collections.abc import Callable, Coroutine
from __future__ import annotations

from collections.abc import Callable, Coroutine, Sequence
from datetime import datetime, timedelta
import logging
from typing import Any
from typing import Any, cast

from aiohttp import ClientSession
import voluptuous as vol

from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DOMAIN
Expand Down Expand Up @@ -50,11 +53,11 @@

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Initialize the DuckDNS component."""
domain = config[DOMAIN][CONF_DOMAIN]
token = config[DOMAIN][CONF_ACCESS_TOKEN]
domain: str = config[DOMAIN][CONF_DOMAIN]
token: str = config[DOMAIN][CONF_ACCESS_TOKEN]
session = async_get_clientsession(hass)

async def update_domain_interval(_now):
async def update_domain_interval(_now: datetime) -> bool:
"""Update the DuckDNS entry."""
return await _update_duckdns(session, domain, token)

Expand All @@ -81,7 +84,14 @@ async def update_domain_service(call: ServiceCall) -> None:
_SENTINEL = object()


async def _update_duckdns(session, domain, token, *, txt=_SENTINEL, clear=False):
async def _update_duckdns(
session: ClientSession,
domain: str,
token: str,
*,
txt: str | None | object = _SENTINEL,
clear: bool = False,
) -> bool:
"""Update DuckDNS."""
params = {"domains": domain, "token": token}

Expand All @@ -91,7 +101,7 @@ async def _update_duckdns(session, domain, token, *, txt=_SENTINEL, clear=False)
params["txt"] = ""
clear = True
else:
params["txt"] = txt
params["txt"] = cast(str, txt)

if clear:
params["clear"] = "true"
Expand All @@ -111,11 +121,9 @@ async def _update_duckdns(session, domain, token, *, txt=_SENTINEL, clear=False)
def async_track_time_interval_backoff(
hass: HomeAssistant,
action: Callable[[datetime], Coroutine[Any, Any, bool]],
intervals,
intervals: Sequence[timedelta],
) -> CALLBACK_TYPE:
"""Add a listener that fires repetitively at every timedelta interval."""
if not isinstance(intervals, (list, tuple)):
intervals = (intervals,)
remove: CALLBACK_TYPE | None = None
failed = 0

Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.duckdns.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.dunehd.*]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down

0 comments on commit 16f1106

Please sign in to comment.