Add support for USB discovery (#54904)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
J. Nick Koston 2021-08-20 14:04:18 -05:00 committed by GitHub
parent 11c6a33594
commit dc74a52f58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 718 additions and 0 deletions

View file

@ -26,6 +26,7 @@ from awesomeversion import (
from homeassistant.generated.dhcp import DHCP
from homeassistant.generated.mqtt import MQTT
from homeassistant.generated.ssdp import SSDP
from homeassistant.generated.usb import USB
from homeassistant.generated.zeroconf import HOMEKIT, ZEROCONF
from homeassistant.util.async_ import gather_with_concurrency
@ -81,6 +82,7 @@ class Manifest(TypedDict, total=False):
ssdp: list[dict[str, str]]
zeroconf: list[str | dict[str, str]]
dhcp: list[dict[str, str]]
usb: list[dict[str, str]]
homekit: dict[str, list[str]]
is_built_in: bool
version: str
@ -219,6 +221,20 @@ async def async_get_dhcp(hass: HomeAssistant) -> list[dict[str, str]]:
return dhcp
async def async_get_usb(hass: HomeAssistant) -> list[dict[str, str]]:
"""Return cached list of usb types."""
usb: list[dict[str, str]] = USB.copy()
integrations = await async_get_custom_components(hass)
for integration in integrations.values():
if not integration.usb:
continue
for entry in integration.usb:
usb.append({"domain": integration.domain, **entry})
return usb
async def async_get_homekit(hass: HomeAssistant) -> dict[str, str]:
"""Return cached list of homekit models."""
@ -423,6 +439,11 @@ class Integration:
"""Return Integration dhcp entries."""
return self.manifest.get("dhcp")
@property
def usb(self) -> list[dict[str, str]] | None:
"""Return Integration usb entries."""
return self.manifest.get("usb")
@property
def homekit(self) -> dict[str, list[str]] | None:
"""Return Integration homekit entries."""