Adjust async_step_usb signature for strict typing (#59773)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-16 19:03:50 +01:00 committed by GitHub
parent f0b3fbc5a7
commit 0dcfd55c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class PhoneModemFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Set up flow instance."""
self._device: str | None = None
async def async_step_usb(self, discovery_info: dict[str, str]) -> FlowResult:
async def async_step_usb(self, discovery_info: usb.UsbServiceInfo) -> FlowResult:
"""Handle USB Discovery."""
device = discovery_info["device"]

View File

@ -6,6 +6,7 @@ import fnmatch
import logging
import os
import sys
from typing import TypedDict
from serial.tools.list_ports import comports
from serial.tools.list_ports_common import ListPortInfo
@ -30,6 +31,17 @@ _LOGGER = logging.getLogger(__name__)
REQUEST_SCAN_COOLDOWN = 60 # 1 minute cooldown
class UsbServiceInfo(TypedDict):
"""Prepared info from usb entries."""
device: str
vid: str
pid: str
serial_number: str | None
manufacturer: str | None
description: str | None
def human_readable_device_name(
device: str,
serial_number: str | None,
@ -193,7 +205,14 @@ class USBDiscovery:
self.hass,
matcher["domain"],
{"source": config_entries.SOURCE_USB},
dataclasses.asdict(device),
UsbServiceInfo(
device=device.device,
vid=device.vid,
pid=device.pid,
serial_number=device.serial_number,
manufacturer=device.manufacturer,
description=device.description,
),
)
@callback

View File

@ -336,7 +336,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
return await self.async_step_manual()
async def async_step_usb(self, discovery_info: dict[str, str]) -> FlowResult:
async def async_step_usb(self, discovery_info: usb.UsbServiceInfo) -> FlowResult:
"""Handle USB Discovery."""
if not is_hassio(self.hass):
return self.async_abort(reason="discovery_requires_supervisor")
@ -352,7 +352,7 @@ class ConfigFlow(BaseZwaveJSFlow, config_entries.ConfigFlow, domain=DOMAIN):
manufacturer = discovery_info["manufacturer"]
description = discovery_info["description"]
# Zooz uses this vid/pid, but so do 2652 sticks
if vid == "10C4" and pid == "EA60" and "2652" in description:
if vid == "10C4" and pid == "EA60" and description and "2652" in description:
return self.async_abort(reason="not_zwave_device")
addon_info = await self._async_get_addon_info()

View File

@ -34,6 +34,7 @@ import homeassistant.util.uuid as uuid_util
if TYPE_CHECKING:
from homeassistant.components.dhcp import DhcpServiceInfo
from homeassistant.components.mqtt.discovery import MqttServiceInfo
from homeassistant.components.usb import UsbServiceInfo
from homeassistant.components.zeroconf import ZeroconfServiceInfo
_LOGGER = logging.getLogger(__name__)
@ -1386,10 +1387,10 @@ class ConfigFlow(data_entry_flow.FlowHandler):
return await self.async_step_discovery(cast(dict, discovery_info))
async def async_step_usb(
self, discovery_info: DiscoveryInfoType
self, discovery_info: UsbServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle a flow initialized by USB discovery."""
return await self.async_step_discovery(discovery_info)
return await self.async_step_discovery(cast(dict, discovery_info))
@callback
def async_create_entry( # pylint: disable=arguments-differ