Update pylint plugin to validate `_async_has_devices` (#66512)

pull/66522/head
Marc Mueller 2022-02-14 18:10:50 +01:00 committed by GitHub
parent 8456c6416e
commit ab67ba20f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 28 additions and 10 deletions

View File

@ -102,7 +102,7 @@ components: &components
# Testing related files that affect the whole test/linting suite
tests: &tests
- codecov.yaml
- pylint/*
- pylint/**
- requirements_test_pre_commit.txt
- requirements_test.txt
- tests/auth/**

View File

@ -9,6 +9,7 @@ from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
from fjaraskupan import UUID_SERVICE, device_filter
from homeassistant.core import HomeAssistant
from homeassistant.helpers.config_entry_flow import register_discovery_flow
from .const import DOMAIN
@ -16,7 +17,7 @@ from .const import DOMAIN
CONST_WAIT_TIME = 5.0
async def _async_has_devices(hass) -> bool:
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
event = asyncio.Event()

View File

@ -1,12 +1,13 @@
"""Config flow for Gree."""
from greeclimate.discovery import Discovery
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_flow
from .const import DISCOVERY_TIMEOUT, DOMAIN
async def _async_has_devices(hass) -> bool:
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
gree_discovery = Discovery(DISCOVERY_TIMEOUT)
devices = await gree_discovery.scan(wait_for=DISCOVERY_TIMEOUT)

View File

@ -1,12 +1,13 @@
"""Config flow for Hisense AEH-W4A1 integration."""
from pyaehw4a1.aehw4a1 import AehW4a1
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_flow
from .const import DOMAIN
async def _async_has_devices(hass):
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
aehw4a1_ip_addresses = await AehW4a1().discovery()
return len(aehw4a1_ip_addresses) > 0

View File

@ -3,4 +3,6 @@ from homeassistant.helpers import config_entry_flow
from .const import DOMAIN
config_entry_flow.register_discovery_flow(DOMAIN, "Home Assistant iOS", lambda *_: True)
config_entry_flow.register_discovery_flow(
DOMAIN, "Home Assistant iOS", lambda hass: True
)

View File

@ -6,7 +6,7 @@ import logging
from async_timeout import timeout
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_entry_flow
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -16,7 +16,7 @@ from .discovery import async_start_discovery_service, async_stop_discovery_servi
_LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass):
async def _async_has_devices(hass: HomeAssistant) -> bool:
controller_ready = asyncio.Event()

View File

@ -3,6 +3,7 @@ import logging
import pykulersky
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_flow
from .const import DOMAIN
@ -10,7 +11,7 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass) -> bool:
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
# Check if there are any devices that can be discovered in the network.
try:

View File

@ -1,12 +1,13 @@
"""Config flow flow LIFX."""
import aiolifx
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_flow
from .const import DOMAIN
async def _async_has_devices(hass):
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
lifx_ip_addresses = await aiolifx.LifxScan(hass.loop).scan()
return len(lifx_ip_addresses) > 0

View File

@ -3,6 +3,7 @@ import logging
import pyzerproc
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_flow
from .const import DOMAIN
@ -10,7 +11,7 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass) -> bool:
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
try:
devices = await pyzerproc.discover()

View File

@ -44,6 +44,8 @@ _MODULE_FILTERS: dict[str, re.Pattern] = {
"device_tracker": re.compile(r"^homeassistant\.components\.\w+\.(device_tracker)$"),
# diagnostics matches only in the package root (diagnostics.py)
"diagnostics": re.compile(r"^homeassistant\.components\.\w+\.(diagnostics)$"),
# config_flow matches only in the package root (config_flow.py)
"config_flow": re.compile(r"^homeassistant\.components\.\w+\.(config_flow)$")
}
_METHOD_MATCH: list[TypeHintMatch] = [
@ -192,6 +194,14 @@ _METHOD_MATCH: list[TypeHintMatch] = [
},
return_type=UNDEFINED,
),
TypeHintMatch(
module_filter=_MODULE_FILTERS["config_flow"],
function_name="_async_has_devices",
arg_types={
0: "HomeAssistant",
},
return_type="bool",
),
]