Add type hints to get_scanner/async_get_scanner (#63836)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-10 23:42:39 +01:00 committed by GitHub
parent d76d9f9e42
commit caff3e0630
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 116 additions and 24 deletions

View file

@ -10,7 +10,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
DEFAULT_HOST = "192.168.178.1"
@ -22,7 +24,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return the Arris device scanner."""
conf = config[DOMAIN]
url = f"http://{conf[CONF_HOST]}"

View file

@ -1,4 +1,6 @@
"""Support for Aruba Access Points."""
from __future__ import annotations
import logging
import re
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -30,7 +34,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Aruba scanner."""
scanner = ArubaDeviceScanner(config[DOMAIN])

View file

@ -14,7 +14,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import Throttle
import homeassistant.util.dt as dt_util
@ -29,7 +31,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Bbox scanner."""
scanner = BboxDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for BT Home Hub 5."""
from __future__ import annotations
import logging
import bthomehub5_devicelist
@ -10,7 +12,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -21,7 +25,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return a BT Home Hub 5 scanner if successful."""
scanner = BTHomeHub5DeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for BT Smart Hub (Sometimes referred to as BT Home Hub 6)."""
from __future__ import annotations
from collections import namedtuple
import logging
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -26,7 +30,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return a BT Smart Hub scanner if successful."""
info = config[DOMAIN]
smarthub_client = BTSmartHub(

View file

@ -1,4 +1,6 @@
"""Support for Cisco IOS Routers."""
from __future__ import annotations
import logging
import re
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -27,7 +31,7 @@ PLATFORM_SCHEMA = vol.All(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Cisco scanner."""
scanner = CiscoDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Cisco Mobility Express."""
from __future__ import annotations
import logging
from ciscomobilityexpress.ciscome import CiscoMobilityExpress
@ -16,7 +18,9 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -34,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Cisco ME scanner."""
config = config[DOMAIN]

View file

@ -1,4 +1,6 @@
"""Support for ClearPass Policy Manager."""
from __future__ import annotations
from datetime import timedelta
import logging
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_API_KEY, CONF_CLIENT_ID, CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
SCAN_INTERVAL = timedelta(seconds=120)
@ -28,7 +32,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
_LOGGER = logging.getLogger(__name__)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Initialize Scanner."""
data = {

View file

@ -1,4 +1,6 @@
"""Support for DD-WRT routers."""
from __future__ import annotations
from http import HTTPStatus
import logging
import re
@ -18,7 +20,9 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -42,7 +46,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a DD-WRT scanner."""
try:
return DdWrtDeviceScanner(config[DOMAIN])

View file

@ -3,6 +3,8 @@ Support to use FortiOS device like FortiGate as device tracker.
This component is part of the device_tracker platform.
"""
from __future__ import annotations
import logging
from awesomeversion import AwesomeVersion
@ -15,7 +17,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_TOKEN, CONF_VERIFY_SSL
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
DEFAULT_VERIFY_SSL = False
@ -30,7 +34,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a FortiOSDeviceScanner."""
host = config[DOMAIN][CONF_HOST]
verify_ssl = config[DOMAIN][CONF_VERIFY_SSL]

View file

@ -1,4 +1,6 @@
"""Support for the Hitron CODA-4582U, provided by Rogers."""
from __future__ import annotations
from collections import namedtuple
from http import HTTPStatus
import logging
@ -12,7 +14,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_TYPE, CONF_USERNAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -28,7 +32,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(_hass, config):
def get_scanner(_hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Hitron CODA-4582U scanner."""
scanner = HitronCODADeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Linksys Smart Wifi routers."""
from __future__ import annotations
from http import HTTPStatus
import logging
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
DEFAULT_TIMEOUT = 10
@ -20,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Linksys AP scanner."""
try:
return LinksysSmartWifiDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for OpenWRT (luci) routers."""
from __future__ import annotations
import logging
from openwrt_luci_rpc import OpenWrtRpc
@ -16,7 +18,9 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -34,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Luci scanner."""
scanner = LuciDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Verizon FiOS Quantum Gateways."""
from __future__ import annotations
import logging
from quantum_gateway import QuantumGatewayScanner
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SSL
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -26,7 +30,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Quantum Gateway scanner."""
scanner = QuantumGatewayDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Sky Hub."""
from __future__ import annotations
import logging
from pyskyqhub.skyq_hub import SkyQHub
@ -10,15 +12,19 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})
async def async_get_scanner(hass, config):
async def async_get_scanner(
hass: HomeAssistant, config: ConfigType
) -> DeviceScanner | None:
"""Return a Sky Hub scanner if successful."""
host = config[DOMAIN].get(CONF_HOST, "192.168.1.254")
websession = async_get_clientsession(hass)

View file

@ -1,4 +1,6 @@
"""Support for fetching WiFi associations through SNMP."""
from __future__ import annotations
import binascii
import logging
@ -12,7 +14,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import (
CONF_AUTH_KEY,
@ -35,7 +39,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return an SNMP scanner."""
scanner = SnmpScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Swisscom routers (Internet-Box)."""
from __future__ import annotations
from contextlib import suppress
import logging
@ -12,7 +14,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -23,7 +27,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return the Swisscom device scanner."""
scanner = SwisscomDeviceScanner(config[DOMAIN])

View file

@ -19,7 +19,9 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -68,7 +70,7 @@ ATTRIBUTE_ALIAS = {
}
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return Synology SRM scanner."""
scanner = SynologySrmDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Tado Smart device trackers."""
from __future__ import annotations
import asyncio
from collections import namedtuple
from datetime import timedelta
@ -15,8 +17,10 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__)
@ -34,7 +38,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return a Tado scanner."""
scanner = TadoDeviceScanner(hass, config[DOMAIN])
return scanner if scanner.success_init else None

View file

@ -1,4 +1,6 @@
"""Support for THOMSON routers."""
from __future__ import annotations
import logging
import re
import telnetlib
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -34,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a THOMSON scanner."""
scanner = ThomsonDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Tomato routers."""
from __future__ import annotations
from http import HTTPStatus
import json
import logging
@ -20,7 +22,9 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
CONF_HTTP_ID = "http_id"
@ -39,7 +43,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and returns a Tomato scanner."""
return TomatoDeviceScanner(config[DOMAIN])

View file

@ -13,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -27,7 +29,9 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
async def async_get_scanner(hass, config):
async def async_get_scanner(
hass: HomeAssistant, config: ConfigType
) -> DeviceScanner | None:
"""Return the UPC device scanner."""
conf = config[DOMAIN]
session = hass.helpers.aiohttp_client.async_get_clientsession()

View file

@ -1,4 +1,6 @@
"""Support for Xiaomi Mi routers."""
from __future__ import annotations
from http import HTTPStatus
import logging
@ -11,7 +13,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -24,7 +28,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Validate the configuration and return a Xiaomi Device Scanner."""
scanner = XiaomiDeviceScanner(config[DOMAIN])

View file

@ -1,4 +1,6 @@
"""Support for Xiaomi Mi WiFi Repeater 2."""
from __future__ import annotations
import logging
from miio import DeviceException, WifiRepeater
@ -10,7 +12,9 @@ from homeassistant.components.device_tracker import (
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_TOKEN
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -22,7 +26,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def get_scanner(hass, config):
def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None:
"""Return a Xiaomi MiIO device scanner."""
scanner = None
host = config[DOMAIN][CONF_HOST]