From f71313ee1e7fd1a34360a8f5d6e847b15fde0489 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 7 Sep 2022 10:58:54 +0200 Subject: [PATCH] Adjust get_scanner pylint checks (#77944) --- homeassistant/components/actiontec/device_tracker.py | 4 +++- homeassistant/components/arris_tg2492lg/device_tracker.py | 2 +- homeassistant/components/aruba/device_tracker.py | 2 +- homeassistant/components/bbox/device_tracker.py | 2 +- homeassistant/components/bt_home_hub_5/device_tracker.py | 4 +++- homeassistant/components/bt_smarthub/device_tracker.py | 2 +- homeassistant/components/cisco_ios/device_tracker.py | 2 +- .../components/cisco_mobility_express/device_tracker.py | 2 +- homeassistant/components/cppm_tracker/device_tracker.py | 2 +- homeassistant/components/ddwrt/device_tracker.py | 2 +- homeassistant/components/fortios/device_tracker.py | 2 +- homeassistant/components/hitron_coda/device_tracker.py | 4 +++- homeassistant/components/linksys_smart/device_tracker.py | 4 +++- homeassistant/components/luci/device_tracker.py | 2 +- homeassistant/components/opnsense/device_tracker.py | 6 +++++- homeassistant/components/quantum_gateway/device_tracker.py | 4 +++- homeassistant/components/sky_hub/device_tracker.py | 5 ++--- homeassistant/components/snmp/device_tracker.py | 2 +- homeassistant/components/swisscom/device_tracker.py | 4 +++- homeassistant/components/synology_srm/device_tracker.py | 4 +++- homeassistant/components/tado/device_tracker.py | 2 +- homeassistant/components/thomson/device_tracker.py | 2 +- homeassistant/components/tomato/device_tracker.py | 2 +- homeassistant/components/unifi_direct/device_tracker.py | 2 +- homeassistant/components/upc_connect/device_tracker.py | 2 +- homeassistant/components/xiaomi/device_tracker.py | 2 +- homeassistant/components/xiaomi_miio/device_tracker.py | 4 +++- pylint/plugins/hass_enforce_type_hints.py | 3 ++- 28 files changed, 50 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/actiontec/device_tracker.py b/homeassistant/components/actiontec/device_tracker.py index cc26c191c8c..9c18e2ba907 100644 --- a/homeassistant/components/actiontec/device_tracker.py +++ b/homeassistant/components/actiontec/device_tracker.py @@ -31,7 +31,9 @@ PLATFORM_SCHEMA: Final = BASE_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> ActiontecDeviceScanner | None: """Validate the configuration and return an Actiontec scanner.""" scanner = ActiontecDeviceScanner(config[DOMAIN]) return scanner if scanner.success_init else None diff --git a/homeassistant/components/arris_tg2492lg/device_tracker.py b/homeassistant/components/arris_tg2492lg/device_tracker.py index 5bc157cbb6b..b456aa3f703 100644 --- a/homeassistant/components/arris_tg2492lg/device_tracker.py +++ b/homeassistant/components/arris_tg2492lg/device_tracker.py @@ -24,7 +24,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> ArrisDeviceScanner: """Return the Arris device scanner.""" conf = config[DOMAIN] url = f"http://{conf[CONF_HOST]}" diff --git a/homeassistant/components/aruba/device_tracker.py b/homeassistant/components/aruba/device_tracker.py index dc2d2fee8e9..d0794553b42 100644 --- a/homeassistant/components/aruba/device_tracker.py +++ b/homeassistant/components/aruba/device_tracker.py @@ -34,7 +34,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> ArubaDeviceScanner | None: """Validate the configuration and return a Aruba scanner.""" scanner = ArubaDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/bbox/device_tracker.py b/homeassistant/components/bbox/device_tracker.py index ab8e7a72441..a9b0312673b 100644 --- a/homeassistant/components/bbox/device_tracker.py +++ b/homeassistant/components/bbox/device_tracker.py @@ -31,7 +31,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> BboxDeviceScanner | None: """Validate the configuration and return a Bbox scanner.""" scanner = BboxDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/bt_home_hub_5/device_tracker.py b/homeassistant/components/bt_home_hub_5/device_tracker.py index 2cef6e9ba41..4d89c851245 100644 --- a/homeassistant/components/bt_home_hub_5/device_tracker.py +++ b/homeassistant/components/bt_home_hub_5/device_tracker.py @@ -25,7 +25,9 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> BTHomeHub5DeviceScanner | None: """Return a BT Home Hub 5 scanner if successful.""" scanner = BTHomeHub5DeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index 0d50b09affa..48475bbeac9 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -30,7 +30,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> BTSmartHubScanner | None: """Return a BT Smart Hub scanner if successful.""" info = config[DOMAIN] smarthub_client = BTSmartHub( diff --git a/homeassistant/components/cisco_ios/device_tracker.py b/homeassistant/components/cisco_ios/device_tracker.py index dc9fe07aa53..b8a4d4cd53d 100644 --- a/homeassistant/components/cisco_ios/device_tracker.py +++ b/homeassistant/components/cisco_ios/device_tracker.py @@ -31,7 +31,7 @@ PLATFORM_SCHEMA = vol.All( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> CiscoDeviceScanner | None: """Validate the configuration and return a Cisco scanner.""" scanner = CiscoDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/cisco_mobility_express/device_tracker.py b/homeassistant/components/cisco_mobility_express/device_tracker.py index d207922f6a5..a4dff37705b 100644 --- a/homeassistant/components/cisco_mobility_express/device_tracker.py +++ b/homeassistant/components/cisco_mobility_express/device_tracker.py @@ -38,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> CiscoMEDeviceScanner | None: """Validate the configuration and return a Cisco ME scanner.""" config = config[DOMAIN] diff --git a/homeassistant/components/cppm_tracker/device_tracker.py b/homeassistant/components/cppm_tracker/device_tracker.py index 8984da6beed..0c7acd33f23 100644 --- a/homeassistant/components/cppm_tracker/device_tracker.py +++ b/homeassistant/components/cppm_tracker/device_tracker.py @@ -32,7 +32,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( _LOGGER = logging.getLogger(__name__) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> CPPMDeviceScanner | None: """Initialize Scanner.""" data = { diff --git a/homeassistant/components/ddwrt/device_tracker.py b/homeassistant/components/ddwrt/device_tracker.py index 0947b755470..ba34ec48e0f 100644 --- a/homeassistant/components/ddwrt/device_tracker.py +++ b/homeassistant/components/ddwrt/device_tracker.py @@ -46,7 +46,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> DdWrtDeviceScanner | None: """Validate the configuration and return a DD-WRT scanner.""" try: return DdWrtDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/fortios/device_tracker.py b/homeassistant/components/fortios/device_tracker.py index d6992d8c045..d0c08a06441 100644 --- a/homeassistant/components/fortios/device_tracker.py +++ b/homeassistant/components/fortios/device_tracker.py @@ -35,7 +35,7 @@ PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> FortiOSDeviceScanner | None: """Validate the configuration and return a FortiOSDeviceScanner.""" host = config[DOMAIN][CONF_HOST] verify_ssl = config[DOMAIN][CONF_VERIFY_SSL] diff --git a/homeassistant/components/hitron_coda/device_tracker.py b/homeassistant/components/hitron_coda/device_tracker.py index 749347e82fe..c9ee93634b2 100644 --- a/homeassistant/components/hitron_coda/device_tracker.py +++ b/homeassistant/components/hitron_coda/device_tracker.py @@ -32,7 +32,9 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(_hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + _hass: HomeAssistant, config: ConfigType +) -> HitronCODADeviceScanner | None: """Validate the configuration and return a Hitron CODA-4582U scanner.""" scanner = HitronCODADeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/linksys_smart/device_tracker.py b/homeassistant/components/linksys_smart/device_tracker.py index 8b296404532..3b0aeffaa6d 100644 --- a/homeassistant/components/linksys_smart/device_tracker.py +++ b/homeassistant/components/linksys_smart/device_tracker.py @@ -24,7 +24,9 @@ _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string}) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> LinksysSmartWifiDeviceScanner | None: """Validate the configuration and return a Linksys AP scanner.""" try: return LinksysSmartWifiDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/luci/device_tracker.py b/homeassistant/components/luci/device_tracker.py index c57e235a8d2..82fc51ba5cd 100644 --- a/homeassistant/components/luci/device_tracker.py +++ b/homeassistant/components/luci/device_tracker.py @@ -38,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> LuciDeviceScanner | None: """Validate the configuration and return a Luci scanner.""" scanner = LuciDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/opnsense/device_tracker.py b/homeassistant/components/opnsense/device_tracker.py index e726a0484f9..b5c75f1cc21 100644 --- a/homeassistant/components/opnsense/device_tracker.py +++ b/homeassistant/components/opnsense/device_tracker.py @@ -1,4 +1,6 @@ """Device tracker support for OPNSense routers.""" +from __future__ import annotations + from homeassistant.components.device_tracker import DeviceScanner from homeassistant.core import HomeAssistant from homeassistant.helpers.typing import ConfigType @@ -6,7 +8,9 @@ from homeassistant.helpers.typing import ConfigType from . import CONF_TRACKER_INTERFACE, OPNSENSE_DATA -async def async_get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner: +async def async_get_scanner( + hass: HomeAssistant, config: ConfigType +) -> OPNSenseDeviceScanner: """Configure the OPNSense device_tracker.""" interface_client = hass.data[OPNSENSE_DATA]["interfaces"] scanner = OPNSenseDeviceScanner( diff --git a/homeassistant/components/quantum_gateway/device_tracker.py b/homeassistant/components/quantum_gateway/device_tracker.py index b9be96ecaea..076c1d2722b 100644 --- a/homeassistant/components/quantum_gateway/device_tracker.py +++ b/homeassistant/components/quantum_gateway/device_tracker.py @@ -30,7 +30,9 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> QuantumGatewayDeviceScanner | None: """Validate the configuration and return a Quantum Gateway scanner.""" scanner = QuantumGatewayDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/sky_hub/device_tracker.py b/homeassistant/components/sky_hub/device_tracker.py index 731baddcdb4..65d806a9bca 100644 --- a/homeassistant/components/sky_hub/device_tracker.py +++ b/homeassistant/components/sky_hub/device_tracker.py @@ -24,7 +24,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.str async def async_get_scanner( hass: HomeAssistant, config: ConfigType -) -> DeviceScanner | None: +) -> SkyHubDeviceScanner | None: """Return a Sky Hub scanner if successful.""" host = config[DOMAIN].get(CONF_HOST, "192.168.1.254") websession = async_get_clientsession(hass) @@ -33,8 +33,7 @@ async def async_get_scanner( _LOGGER.debug("Initialising Sky Hub") await hub.async_connect() if hub.success_init: - scanner = SkyHubDeviceScanner(hub) - return scanner + return SkyHubDeviceScanner(hub) return None diff --git a/homeassistant/components/snmp/device_tracker.py b/homeassistant/components/snmp/device_tracker.py index c20dd58a752..696b079fd5e 100644 --- a/homeassistant/components/snmp/device_tracker.py +++ b/homeassistant/components/snmp/device_tracker.py @@ -39,7 +39,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> SnmpScanner | None: """Validate the configuration and return an SNMP scanner.""" scanner = SnmpScanner(config[DOMAIN]) diff --git a/homeassistant/components/swisscom/device_tracker.py b/homeassistant/components/swisscom/device_tracker.py index d95067e6b33..29da03b262e 100644 --- a/homeassistant/components/swisscom/device_tracker.py +++ b/homeassistant/components/swisscom/device_tracker.py @@ -26,7 +26,9 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> SwisscomDeviceScanner | None: """Return the Swisscom device scanner.""" scanner = SwisscomDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/synology_srm/device_tracker.py b/homeassistant/components/synology_srm/device_tracker.py index 49369741218..15c61ff0a3c 100644 --- a/homeassistant/components/synology_srm/device_tracker.py +++ b/homeassistant/components/synology_srm/device_tracker.py @@ -70,7 +70,9 @@ ATTRIBUTE_ALIAS = { } -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> SynologySrmDeviceScanner | None: """Validate the configuration and return Synology SRM scanner.""" scanner = SynologySrmDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index ec917877042..6d6a17b2b16 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -38,7 +38,7 @@ PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> TadoDeviceScanner | None: """Return a Tado scanner.""" scanner = TadoDeviceScanner(hass, config[DOMAIN]) return scanner if scanner.success_init else None diff --git a/homeassistant/components/thomson/device_tracker.py b/homeassistant/components/thomson/device_tracker.py index c04636e622a..4af21ec8e16 100644 --- a/homeassistant/components/thomson/device_tracker.py +++ b/homeassistant/components/thomson/device_tracker.py @@ -38,7 +38,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> ThomsonDeviceScanner | None: """Validate the configuration and return a THOMSON scanner.""" scanner = ThomsonDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/tomato/device_tracker.py b/homeassistant/components/tomato/device_tracker.py index 2d51bb51b53..c99a44120e5 100644 --- a/homeassistant/components/tomato/device_tracker.py +++ b/homeassistant/components/tomato/device_tracker.py @@ -43,7 +43,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> TomatoDeviceScanner: """Validate the configuration and returns a Tomato scanner.""" return TomatoDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/unifi_direct/device_tracker.py b/homeassistant/components/unifi_direct/device_tracker.py index 7a81975c0ba..d0ac37f312c 100644 --- a/homeassistant/components/unifi_direct/device_tracker.py +++ b/homeassistant/components/unifi_direct/device_tracker.py @@ -34,7 +34,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> UnifiDeviceScanner | None: """Validate the configuration and return a Unifi direct scanner.""" scanner = UnifiDeviceScanner(config[DOMAIN]) if not scanner.connected: diff --git a/homeassistant/components/upc_connect/device_tracker.py b/homeassistant/components/upc_connect/device_tracker.py index 35960dcf706..3025ea746d0 100644 --- a/homeassistant/components/upc_connect/device_tracker.py +++ b/homeassistant/components/upc_connect/device_tracker.py @@ -32,7 +32,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( async def async_get_scanner( hass: HomeAssistant, config: ConfigType -) -> DeviceScanner | None: +) -> UPCDeviceScanner | None: """Return the UPC device scanner.""" conf = config[DOMAIN] session = async_get_clientsession(hass) diff --git a/homeassistant/components/xiaomi/device_tracker.py b/homeassistant/components/xiaomi/device_tracker.py index f941dba2d01..b8cf5f005c4 100644 --- a/homeassistant/components/xiaomi/device_tracker.py +++ b/homeassistant/components/xiaomi/device_tracker.py @@ -28,7 +28,7 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner(hass: HomeAssistant, config: ConfigType) -> XiaomiDeviceScanner | None: """Validate the configuration and return a Xiaomi Device Scanner.""" scanner = XiaomiDeviceScanner(config[DOMAIN]) diff --git a/homeassistant/components/xiaomi_miio/device_tracker.py b/homeassistant/components/xiaomi_miio/device_tracker.py index 1ec914fc647..e4bebdd0e62 100644 --- a/homeassistant/components/xiaomi_miio/device_tracker.py +++ b/homeassistant/components/xiaomi_miio/device_tracker.py @@ -26,7 +26,9 @@ PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA.extend( ) -def get_scanner(hass: HomeAssistant, config: ConfigType) -> DeviceScanner | None: +def get_scanner( + hass: HomeAssistant, config: ConfigType +) -> XiaomiMiioDeviceScanner | None: """Return a Xiaomi MiIO device scanner.""" scanner = None host = config[DOMAIN][CONF_HOST] diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 717534626af..23578630b7e 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -327,7 +327,8 @@ _FUNCTION_MATCH: dict[str, list[TypeHintMatch]] = { 0: "HomeAssistant", 1: "ConfigType", }, - return_type=["DeviceScanner", "DeviceScanner | None"], + return_type=["DeviceScanner", None], + check_return_type_inheritance=True, has_async_counterpart=True, ), ],