mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Adjust async_step_usb signature for strict typing (#59773)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
f0b3fbc5a7
commit
0dcfd55c84
@ -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"]
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user