Add type hints to setup_scanner

This commit is contained in:
epenet 2022-01-10 14:29:55 +00:00
parent 9a312e7a7d
commit 3e8b295484
5 changed files with 56 additions and 18 deletions

View file

@ -1,5 +1,7 @@
"""Support for APRS device tracking."""
from __future__ import annotations
from collections.abc import Callable
import logging
import threading
@ -21,7 +23,9 @@ from homeassistant.const import (
CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import slugify
DOMAIN = "aprs"
@ -80,15 +84,20 @@ def gps_accuracy(gps, posambiguity: int) -> int:
return accuracy
def setup_scanner(hass, config, see, discovery_info=None):
def setup_scanner(
hass: HomeAssistant,
config: ConfigType,
see: Callable[..., None],
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the APRS tracker."""
callsigns = config.get(CONF_CALLSIGNS)
callsigns = config[CONF_CALLSIGNS]
server_filter = make_filter(callsigns)
callsign = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
host = config.get(CONF_HOST)
timeout = config.get(CONF_TIMEOUT)
callsign = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
host = config[CONF_HOST]
timeout = config[CONF_TIMEOUT]
aprs_listener = AprsListenerThread(callsign, password, host, server_filter, see)
def aprs_disconnect(event):
@ -107,7 +116,6 @@ def setup_scanner(hass, config, see, discovery_info=None):
return
_LOGGER.debug(aprs_listener.start_message)
return True
class AprsListenerThread(threading.Thread):

View file

@ -1,14 +1,21 @@
"""Demo platform for the Device tracker component."""
from __future__ import annotations
from collections.abc import Callable
import random
from homeassistant.core import ServiceCall
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN, SERVICE_RANDOMIZE_DEVICE_TRACKER_DATA
def setup_scanner(hass, config, see, discovery_info=None):
def setup_scanner(
hass: HomeAssistant,
config: ConfigType,
see: Callable[..., None],
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the demo tracker."""
def offset():

View file

@ -1,4 +1,7 @@
"""Support for FleetGO Platform."""
from __future__ import annotations
from collections.abc import Callable
import logging
import requests
@ -15,8 +18,10 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_utc_time_change
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__)
@ -31,13 +36,16 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def setup_scanner(hass, config: dict, see, discovery_info=None):
def setup_scanner(
hass: HomeAssistant,
config: ConfigType,
see: Callable[..., None],
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the DeviceScanner and check if login is valid."""
scanner = FleetGoDeviceScanner(config, see)
if not scanner.login(hass):
_LOGGER.error("FleetGO authentication failed")
return False
return True
class FleetGoDeviceScanner:

View file

@ -1,6 +1,7 @@
"""Support for Google Maps location sharing."""
from __future__ import annotations
from collections.abc import Callable
from datetime import timedelta
import logging
@ -19,9 +20,10 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import dt as dt_util, slugify
_LOGGER = logging.getLogger(__name__)
@ -45,10 +47,14 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA_BASE.extend(
)
def setup_scanner(hass, config: ConfigType, see, discovery_info=None):
def setup_scanner(
hass: HomeAssistant,
config: ConfigType,
see: Callable[..., None],
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Google Maps Location sharing scanner."""
scanner = GoogleMapsScanner(hass, config, see)
return scanner.success_init
GoogleMapsScanner(hass, config, see)
class GoogleMapsScanner:

View file

@ -1,4 +1,7 @@
"""Support for Life360 device tracking."""
from __future__ import annotations
from collections.abc import Callable
from datetime import timedelta
import logging
@ -20,8 +23,10 @@ from homeassistant.const import (
LENGTH_MILES,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.async_ import run_callback_threadsafe
from homeassistant.util.distance import convert
import homeassistant.util.dt as dt_util
@ -86,12 +91,16 @@ def _dump_filter(filter_dict, desc, func=lambda x: x):
)
def setup_scanner(hass, config, see, discovery_info=None):
def setup_scanner(
hass: HomeAssistant,
config: ConfigType,
see: Callable[..., None],
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up device scanner."""
config = hass.data[DOMAIN]["config"]
apis = hass.data[DOMAIN]["apis"]
Life360Scanner(hass, config, see, apis)
return True
def _utc_from_ts(val):