mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Use dataclass for UsbServiceInfo (#60140)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
77dfeb062f
commit
cbbf22db52
@ -6,7 +6,7 @@ import fnmatch
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import TypedDict
|
from typing import Any
|
||||||
|
|
||||||
from serial.tools.list_ports import comports
|
from serial.tools.list_ports import comports
|
||||||
from serial.tools.list_ports_common import ListPortInfo
|
from serial.tools.list_ports_common import ListPortInfo
|
||||||
@ -17,8 +17,10 @@ from homeassistant.components import websocket_api
|
|||||||
from homeassistant.components.websocket_api.connection import ActiveConnection
|
from homeassistant.components.websocket_api.connection import ActiveConnection
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
|
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||||
from homeassistant.helpers import discovery_flow, system_info
|
from homeassistant.helpers import discovery_flow, system_info
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
|
from homeassistant.helpers.frame import report
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import async_get_usb
|
from homeassistant.loader import async_get_usb
|
||||||
|
|
||||||
@ -31,7 +33,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
REQUEST_SCAN_COOLDOWN = 60 # 1 minute cooldown
|
REQUEST_SCAN_COOLDOWN = 60 # 1 minute cooldown
|
||||||
|
|
||||||
|
|
||||||
class UsbServiceInfo(TypedDict):
|
@dataclasses.dataclass
|
||||||
|
class UsbServiceInfo(BaseServiceInfo):
|
||||||
"""Prepared info from usb entries."""
|
"""Prepared info from usb entries."""
|
||||||
|
|
||||||
device: str
|
device: str
|
||||||
@ -41,6 +44,25 @@ class UsbServiceInfo(TypedDict):
|
|||||||
manufacturer: str | None
|
manufacturer: str | None
|
||||||
description: str | None
|
description: str | None
|
||||||
|
|
||||||
|
# Used to prevent log flooding. To be removed in 2022.6
|
||||||
|
_warning_logged: bool = False
|
||||||
|
|
||||||
|
def __getitem__(self, name: str) -> Any:
|
||||||
|
"""
|
||||||
|
Allow property access by name for compatibility reason.
|
||||||
|
|
||||||
|
Deprecated, and will be removed in version 2022.6.
|
||||||
|
"""
|
||||||
|
if not self._warning_logged:
|
||||||
|
report(
|
||||||
|
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; this will fail in version 2022.6",
|
||||||
|
exclude_integrations={"usb"},
|
||||||
|
error_if_core=False,
|
||||||
|
level=logging.DEBUG,
|
||||||
|
)
|
||||||
|
self._warning_logged = True
|
||||||
|
return getattr(self, name)
|
||||||
|
|
||||||
|
|
||||||
def human_readable_device_name(
|
def human_readable_device_name(
|
||||||
device: str,
|
device: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user