Fix bluetooth service_info typing (#75477)

* Fix bluetooth service_info typing

* Remove additional type ignores

* Remove pylint disable
This commit is contained in:
Marc Mueller 2022-07-20 05:46:18 +02:00 committed by GitHub
parent 8a48d54951
commit 51ed9ee59d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -43,7 +43,7 @@ SOURCE_LOCAL: Final = "local"
@dataclass
class BluetoothServiceInfoBleak(BluetoothServiceInfo): # type: ignore[misc]
class BluetoothServiceInfoBleak(BluetoothServiceInfo):
"""BluetoothServiceInfo with bleak data.
Integrations may need BLEDevice and AdvertisementData
@ -58,7 +58,7 @@ class BluetoothServiceInfoBleak(BluetoothServiceInfo): # type: ignore[misc]
@classmethod
def from_advertisement(
cls, device: BLEDevice, advertisement_data: AdvertisementData, source: str
) -> BluetoothServiceInfo:
) -> BluetoothServiceInfoBleak:
"""Create a BluetoothServiceInfoBleak from an advertisement."""
return cls(
name=advertisement_data.local_name or device.name or device.address,
@ -377,7 +377,7 @@ class BluetoothManager:
)
@hass_callback
def async_discovered_service_info(self) -> list[BluetoothServiceInfo]:
def async_discovered_service_info(self) -> list[BluetoothServiceInfoBleak]:
"""Return if the address is present."""
if models.HA_BLEAK_SCANNER:
discovered = models.HA_BLEAK_SCANNER.discovered_devices

View File

@ -61,7 +61,7 @@ def is_bluetooth_device(device: Device) -> bool:
def discover_devices(device_id: int) -> list[tuple[str, str]]:
"""Discover Bluetooth devices."""
try:
result = bluetooth.discover_devices( # type: ignore[attr-defined]
result = bluetooth.discover_devices(
duration=8,
lookup_names=True,
flush_cache=True,
@ -124,7 +124,7 @@ async def get_tracking_devices(hass: HomeAssistant) -> tuple[set[str], set[str]]
def lookup_name(mac: str) -> str | None:
"""Lookup a Bluetooth device name."""
_LOGGER.debug("Scanning %s", mac)
return bluetooth.lookup_name(mac, timeout=5) # type: ignore[attr-defined,no-any-return]
return bluetooth.lookup_name(mac, timeout=5) # type: ignore[no-any-return]
async def async_setup_scanner(
@ -180,7 +180,7 @@ async def async_setup_scanner(
if tasks:
await asyncio.wait(tasks)
except bluetooth.BluetoothError: # type: ignore[attr-defined]
except bluetooth.BluetoothError:
_LOGGER.exception("Error looking up Bluetooth device")
async def update_bluetooth(now: datetime | None = None) -> None:

View File

@ -0,0 +1 @@
"""Service info helpers."""

View File

@ -1,4 +1,4 @@
"""The bluetooth integration service info."""
from home_assistant_bluetooth import ( # pylint: disable=unused-import # noqa: F401
BluetoothServiceInfo,
)
from home_assistant_bluetooth import BluetoothServiceInfo
__all__ = ["BluetoothServiceInfo"]