Fix invalid type hint in discovery async_listen (#63987)

* Fix invalid type hint in discovery async_listen

* Add setup type hints to sabnzbd

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-13 02:43:43 +01:00 committed by GitHub
parent ea08e0d62d
commit 128256a3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -23,12 +23,13 @@ from homeassistant.const import (
DATA_RATE_MEGABYTES_PER_SECOND,
Platform,
)
from homeassistant.core import ServiceCall, callback
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import discovery
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.json import load_json, save_json
_LOGGER = logging.getLogger(__name__)
@ -197,11 +198,13 @@ async def async_configure_sabnzbd(
async_request_configuration(hass, config, base_url, web_root)
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the SABnzbd component."""
async def sabnzbd_discovered(service, info):
async def sabnzbd_discovered(service: str, info: DiscoveryInfoType | None) -> None:
"""Handle service discovery."""
if not info:
return
ssl = info.get("properties", {}).get("https", "0") == "1"
await async_configure_sabnzbd(hass, info, ssl)

View File

@ -7,12 +7,11 @@ There are two different types of discoveries that can be fired/listened for.
"""
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Awaitable, Callable
from typing import Any, TypedDict
from homeassistant import core, setup
from homeassistant.const import Platform
from homeassistant.core import CALLBACK_TYPE
from homeassistant.loader import bind_hass
from .dispatcher import async_dispatcher_connect, async_dispatcher_send
@ -37,7 +36,7 @@ class DiscoveryDict(TypedDict):
def async_listen(
hass: core.HomeAssistant,
service: str,
callback: CALLBACK_TYPE,
callback: Callable[[str, DiscoveryInfoType | None], Awaitable[None] | None],
) -> None:
"""Set up listener for discovery of specific service.