Replace led-ble util with bluetooth-data-tools (#81093)
This commit is contained in:
parent
9b0b8ae9c0
commit
b7533aff48
8 changed files with 12 additions and 54 deletions
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from bluetooth_data_tools import human_readable_name
|
||||
from led_ble import BLEAK_EXCEPTIONS, LEDBLE
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -16,7 +17,6 @@ from homeassistant.const import CONF_ADDRESS
|
|||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import DOMAIN, LOCAL_NAMES, UNSUPPORTED_SUB_MODEL
|
||||
from .util import human_readable_name
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "LED BLE",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/led_ble/",
|
||||
"requirements": ["led-ble==1.0.0"],
|
||||
"requirements": ["bluetooth-data-tools==0.2.0", "led-ble==1.0.0"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"bluetooth": [
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
"""The yalexs_ble integration models."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothScanningMode,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_discovered_service_info,
|
||||
async_process_advertisements,
|
||||
)
|
||||
from homeassistant.components.bluetooth.match import ADDRESS, BluetoothCallbackMatcher
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from .const import DEVICE_TIMEOUT
|
||||
|
||||
|
||||
@callback
|
||||
def async_find_existing_service_info(
|
||||
hass: HomeAssistant, local_name: str, address: str
|
||||
) -> BluetoothServiceInfoBleak | None:
|
||||
"""Return the service info for the given local_name and address."""
|
||||
for service_info in async_discovered_service_info(hass):
|
||||
device = service_info.device
|
||||
if device.address == address:
|
||||
return service_info
|
||||
return None
|
||||
|
||||
|
||||
async def async_get_service_info(
|
||||
hass: HomeAssistant, local_name: str, address: str
|
||||
) -> BluetoothServiceInfoBleak:
|
||||
"""Wait for the service info for the given local_name and address."""
|
||||
if service_info := async_find_existing_service_info(hass, local_name, address):
|
||||
return service_info
|
||||
return await async_process_advertisements(
|
||||
hass,
|
||||
lambda service_info: True,
|
||||
BluetoothCallbackMatcher({ADDRESS: address}),
|
||||
BluetoothScanningMode.ACTIVE,
|
||||
DEVICE_TIMEOUT,
|
||||
)
|
||||
|
||||
|
||||
def short_address(address: str) -> str:
|
||||
"""Convert a Bluetooth address to a short address."""
|
||||
split_address = address.replace("-", ":").split(":")
|
||||
return f"{split_address[-2].upper()}{split_address[-1].upper()}"[-4:]
|
||||
|
||||
|
||||
def human_readable_name(name: str | None, local_name: str, address: str) -> str:
|
||||
"""Return a human readable name for the given name, local_name, and address."""
|
||||
return f"{name or local_name} ({short_address(address)})"
|
Loading…
Add table
Add a link
Reference in a new issue