Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/modem_callerid/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self) -> None:
"""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"]

Expand Down
21 changes: 20 additions & 1 deletion homeassistant/components/usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand All @@ -30,6 +31,17 @@
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,
Expand Down Expand Up @@ -193,7 +205,14 @@ def _async_process_discovered_usb_device(self, device: USBDevice) -> None:
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
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zwave_js/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ async def async_step_user(

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")
Expand All @@ -352,7 +352,7 @@ async def async_step_usb(self, discovery_info: dict[str, str]) -> FlowResult:
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()
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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__)
Expand Down Expand Up @@ -1386,10 +1387,10 @@ async def async_step_dhcp(
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
Expand Down