mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 12:45:28 +02:00
Add type hints to setup_scanner
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"""Support for APRS device tracking."""
|
"""Support for APRS device tracking."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@@ -21,7 +23,9 @@ from homeassistant.const import (
|
|||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
DOMAIN = "aprs"
|
DOMAIN = "aprs"
|
||||||
@@ -80,15 +84,20 @@ def gps_accuracy(gps, posambiguity: int) -> int:
|
|||||||
return accuracy
|
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."""
|
"""Set up the APRS tracker."""
|
||||||
callsigns = config.get(CONF_CALLSIGNS)
|
callsigns = config[CONF_CALLSIGNS]
|
||||||
server_filter = make_filter(callsigns)
|
server_filter = make_filter(callsigns)
|
||||||
|
|
||||||
callsign = config.get(CONF_USERNAME)
|
callsign = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config[CONF_TIMEOUT]
|
||||||
aprs_listener = AprsListenerThread(callsign, password, host, server_filter, see)
|
aprs_listener = AprsListenerThread(callsign, password, host, server_filter, see)
|
||||||
|
|
||||||
def aprs_disconnect(event):
|
def aprs_disconnect(event):
|
||||||
@@ -107,7 +116,6 @@ def setup_scanner(hass, config, see, discovery_info=None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.debug(aprs_listener.start_message)
|
_LOGGER.debug(aprs_listener.start_message)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class AprsListenerThread(threading.Thread):
|
class AprsListenerThread(threading.Thread):
|
||||||
|
@@ -1,14 +1,21 @@
|
|||||||
"""Demo platform for the Device tracker component."""
|
"""Demo platform for the Device tracker component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import random
|
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
|
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."""
|
"""Set up the demo tracker."""
|
||||||
|
|
||||||
def offset():
|
def offset():
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
"""Support for FleetGO Platform."""
|
"""Support for FleetGO Platform."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -15,8 +18,10 @@ from homeassistant.const import (
|
|||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import track_utc_time_change
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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."""
|
"""Set up the DeviceScanner and check if login is valid."""
|
||||||
scanner = FleetGoDeviceScanner(config, see)
|
scanner = FleetGoDeviceScanner(config, see)
|
||||||
if not scanner.login(hass):
|
if not scanner.login(hass):
|
||||||
_LOGGER.error("FleetGO authentication failed")
|
_LOGGER.error("FleetGO authentication failed")
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class FleetGoDeviceScanner:
|
class FleetGoDeviceScanner:
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
"""Support for Google Maps location sharing."""
|
"""Support for Google Maps location sharing."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -19,9 +20,10 @@ from homeassistant.const import (
|
|||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import track_time_interval
|
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
|
from homeassistant.util import dt as dt_util, slugify
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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."""
|
"""Set up the Google Maps Location sharing scanner."""
|
||||||
scanner = GoogleMapsScanner(hass, config, see)
|
GoogleMapsScanner(hass, config, see)
|
||||||
return scanner.success_init
|
|
||||||
|
|
||||||
|
|
||||||
class GoogleMapsScanner:
|
class GoogleMapsScanner:
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
"""Support for Life360 device tracking."""
|
"""Support for Life360 device tracking."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -20,8 +23,10 @@ from homeassistant.const import (
|
|||||||
LENGTH_MILES,
|
LENGTH_MILES,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import track_time_interval
|
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.async_ import run_callback_threadsafe
|
||||||
from homeassistant.util.distance import convert
|
from homeassistant.util.distance import convert
|
||||||
import homeassistant.util.dt as dt_util
|
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."""
|
"""Set up device scanner."""
|
||||||
config = hass.data[DOMAIN]["config"]
|
config = hass.data[DOMAIN]["config"]
|
||||||
apis = hass.data[DOMAIN]["apis"]
|
apis = hass.data[DOMAIN]["apis"]
|
||||||
Life360Scanner(hass, config, see, apis)
|
Life360Scanner(hass, config, see, apis)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def _utc_from_ts(val):
|
def _utc_from_ts(val):
|
||||||
|
Reference in New Issue
Block a user