Add type hints to setup_scanner ()

* Add type hints to setup_scanner

* Fix aprs tests

* Revert "Add type hints to setup_scanner"

This reverts commit 3e8b295484.

* Revert "Fix aprs tests"

This reverts commit 854b37aee8.

* Add type hints to setup_scanner

* Fix aprs tests

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63914/head
epenet 2022-01-11 17:29:04 +01:00 committed by GitHub
parent 4eae888546
commit c6416955c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 14 deletions
homeassistant/components
tests/components/aprs

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,
) -> bool:
"""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):
@ -100,11 +109,11 @@ def setup_scanner(hass, config, see, discovery_info=None):
if not aprs_listener.start_event.wait(timeout):
_LOGGER.error("Timeout waiting for APRS to connect")
return
return False
if not aprs_listener.start_success:
_LOGGER.error(aprs_listener.start_message)
return
return False
_LOGGER.debug(aprs_listener.start_message)
return True

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,
) -> bool:
"""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,7 +36,12 @@ 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,
) -> bool:
"""Set up the DeviceScanner and check if login is valid."""
scanner = FleetGoDeviceScanner(config, see)
if not scanner.login(hass):

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,7 +47,12 @@ 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,
) -> bool:
"""Set up the Google Maps Location sharing scanner."""
scanner = GoogleMapsScanner(hass, config, see)
return scanner.success_init

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,7 +91,12 @@ 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,
) -> bool:
"""Set up device scanner."""
config = hass.data[DOMAIN]["config"]
apis = hass.data[DOMAIN]["apis"]

View File

@ -312,6 +312,7 @@ def test_setup_scanner():
"password": TEST_PASSWORD,
"host": TEST_HOST,
"callsigns": ["XX0FOO*", "YY0BAR-1"],
"timeout": device_tracker.DEFAULT_TIMEOUT,
}
see = Mock()