mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Use shared bluetooth models for BluetoothServiceInfo (#75322)
This commit is contained in:
parent
79a0940932
commit
ba8a530d19
@ -1,60 +1,4 @@
|
|||||||
"""The bluetooth integration service info."""
|
"""The bluetooth integration service info."""
|
||||||
from __future__ import annotations
|
from home_assistant_bluetooth import ( # pylint: disable=unused-import # noqa: F401
|
||||||
|
BluetoothServiceInfo,
|
||||||
import dataclasses
|
)
|
||||||
from functools import cached_property
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from bleak.backends.device import BLEDevice
|
|
||||||
from bleak.backends.scanner import AdvertisementData
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
|
||||||
class BluetoothServiceInfo(BaseServiceInfo):
|
|
||||||
"""Prepared info from bluetooth entries."""
|
|
||||||
|
|
||||||
name: str
|
|
||||||
address: str
|
|
||||||
rssi: int
|
|
||||||
manufacturer_data: dict[int, bytes]
|
|
||||||
service_data: dict[str, bytes]
|
|
||||||
service_uuids: list[str]
|
|
||||||
source: str
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_advertisement(
|
|
||||||
cls, device: BLEDevice, advertisement_data: AdvertisementData, source: str
|
|
||||||
) -> BluetoothServiceInfo:
|
|
||||||
"""Create a BluetoothServiceInfo from an advertisement."""
|
|
||||||
return cls(
|
|
||||||
name=advertisement_data.local_name or device.name or device.address,
|
|
||||||
address=device.address,
|
|
||||||
rssi=device.rssi,
|
|
||||||
manufacturer_data=advertisement_data.manufacturer_data,
|
|
||||||
service_data=advertisement_data.service_data,
|
|
||||||
service_uuids=advertisement_data.service_uuids,
|
|
||||||
source=source,
|
|
||||||
)
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def manufacturer(self) -> str | None:
|
|
||||||
"""Convert manufacturer data to a string."""
|
|
||||||
from bleak.backends.device import ( # pylint: disable=import-outside-toplevel
|
|
||||||
MANUFACTURERS,
|
|
||||||
)
|
|
||||||
|
|
||||||
for manufacturer in self.manufacturer_data:
|
|
||||||
if manufacturer in MANUFACTURERS:
|
|
||||||
name: str = MANUFACTURERS[manufacturer]
|
|
||||||
return name
|
|
||||||
return None
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def manufacturer_id(self) -> int | None:
|
|
||||||
"""Get the first manufacturer id."""
|
|
||||||
for manufacturer in self.manufacturer_data:
|
|
||||||
return manufacturer
|
|
||||||
return None
|
|
||||||
|
@ -15,6 +15,7 @@ ciso8601==2.2.0
|
|||||||
cryptography==36.0.2
|
cryptography==36.0.2
|
||||||
fnvhash==0.1.0
|
fnvhash==0.1.0
|
||||||
hass-nabucasa==0.54.1
|
hass-nabucasa==0.54.1
|
||||||
|
home-assistant-bluetooth==1.3.0
|
||||||
home-assistant-frontend==20220707.1
|
home-assistant-frontend==20220707.1
|
||||||
httpx==0.23.0
|
httpx==0.23.0
|
||||||
ifaddr==0.1.7
|
ifaddr==0.1.7
|
||||||
|
@ -36,6 +36,7 @@ dependencies = [
|
|||||||
# When bumping httpx, please check the version pins of
|
# When bumping httpx, please check the version pins of
|
||||||
# httpcore, anyio, and h11 in gen_requirements_all
|
# httpcore, anyio, and h11 in gen_requirements_all
|
||||||
"httpx==0.23.0",
|
"httpx==0.23.0",
|
||||||
|
"home-assistant-bluetooth==1.3.0",
|
||||||
"ifaddr==0.1.7",
|
"ifaddr==0.1.7",
|
||||||
"jinja2==3.1.2",
|
"jinja2==3.1.2",
|
||||||
"lru-dict==1.1.8",
|
"lru-dict==1.1.8",
|
||||||
|
@ -11,6 +11,7 @@ bcrypt==3.1.7
|
|||||||
certifi>=2021.5.30
|
certifi>=2021.5.30
|
||||||
ciso8601==2.2.0
|
ciso8601==2.2.0
|
||||||
httpx==0.23.0
|
httpx==0.23.0
|
||||||
|
home-assistant-bluetooth==1.3.0
|
||||||
ifaddr==0.1.7
|
ifaddr==0.1.7
|
||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
lru-dict==1.1.8
|
lru-dict==1.1.8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user