Add type hints to async_setup_scanner (#63826)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
896885a2c3
commit
c6aaa24027
6 changed files with 63 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Support for tracking for iCloud devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
|
||||
|
@ -10,6 +11,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .account import IcloudAccount, IcloudDevice
|
||||
from .const import (
|
||||
|
@ -20,7 +22,12 @@ from .const import (
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_scanner(hass: HomeAssistant, config, see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Old way of setting up the iCloud tracker."""
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
"""Support for the Meraki CMX location service."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
import logging
|
||||
|
@ -10,8 +13,9 @@ from homeassistant.components.device_tracker import (
|
|||
SOURCE_TYPE_ROUTER,
|
||||
)
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
CONF_VALIDATOR = "validator"
|
||||
CONF_SECRET = "secret"
|
||||
|
@ -27,12 +31,15 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up an endpoint for the Meraki tracker."""
|
||||
hass.http.register_view(MerakiView(config, async_see))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class MerakiView(HomeAssistantView):
|
||||
"""View to handle Meraki requests."""
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
"""Support for GPS tracking MQTT enabled devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
import json
|
||||
import logging
|
||||
|
||||
|
@ -16,8 +19,9 @@ from homeassistant.const import (
|
|||
ATTR_LONGITUDE,
|
||||
CONF_DEVICES,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -36,7 +40,12 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(mqtt.SCHEMA_BASE).extend(
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the MQTT JSON tracker."""
|
||||
devices = config[CONF_DEVICES]
|
||||
qos = config[CONF_QOS]
|
||||
|
@ -64,8 +73,6 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
|||
|
||||
await mqtt.async_subscribe(hass, topic, async_message_received, qos)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _parse_see_args(dev_id, data):
|
||||
"""Parse the payload location parameters, into the format see expects."""
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
"""Tracks devices by sending a ICMP echo request (ping)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Awaitable, Callable
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import subprocess
|
||||
|
@ -15,8 +18,10 @@ from homeassistant.components.device_tracker.const import (
|
|||
SCAN_INTERVAL,
|
||||
SOURCE_TYPE_ROUTER,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.async_ import gather_with_concurrency
|
||||
from homeassistant.util.process import kill_subprocess
|
||||
|
||||
|
@ -77,7 +82,12 @@ class HostSubProcess:
|
|||
return False
|
||||
|
||||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Host objects and return the update function."""
|
||||
|
||||
privileged = hass.data[DOMAIN][PING_PRIVS]
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
"""Support for Traccar device tracking."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
|
@ -31,6 +34,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import DOMAIN, TRACKER_UPDATE
|
||||
|
@ -159,7 +163,12 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Validate the configuration and return a Traccar scanner."""
|
||||
|
||||
session = async_get_clientsession(hass, config[CONF_VERIFY_SSL])
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
"""Support for tracking a Volvo."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
|
||||
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import DATA_KEY, SIGNAL_STATE_UPDATED
|
||||
|
||||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
async def async_setup_scanner(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_see: Callable[..., Awaitable[None]],
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Volvo tracker."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -28,5 +39,3 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
|||
)
|
||||
|
||||
async_dispatcher_connect(hass, SIGNAL_STATE_UPDATED, see_vehicle)
|
||||
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue