Add type hints to setup_scanner (#63825)
* Add type hints to setup_scanner * Fix aprs tests * Revert "Add type hints to setup_scanner" This reverts commitpull/63914/head3e8b295484
. * Revert "Fix aprs tests" This reverts commit854b37aee8
. * Add type hints to setup_scanner * Fix aprs tests Co-authored-by: epenet <epenet@users.noreply.github.com>
parent
4eae888546
commit
c6416955c6
homeassistant/components
fleetgo
google_maps
life360
tests/components/aprs
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue