From b7533aff486e6902feda1febf30f775f6fbb8ec2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 8 Nov 2022 07:26:16 -0600 Subject: [PATCH] Replace led-ble util with bluetooth-data-tools (#81093) --- .coveragerc | 1 - .../components/bluetooth/manifest.json | 1 + .../components/led_ble/config_flow.py | 2 +- .../components/led_ble/manifest.json | 2 +- homeassistant/components/led_ble/util.py | 51 ------------------- homeassistant/package_constraints.txt | 1 + requirements_all.txt | 4 ++ requirements_test_all.txt | 4 ++ 8 files changed, 12 insertions(+), 54 deletions(-) delete mode 100644 homeassistant/components/led_ble/util.py diff --git a/.coveragerc b/.coveragerc index 84f061fbd35..1a8bfb462d8 100644 --- a/.coveragerc +++ b/.coveragerc @@ -678,7 +678,6 @@ omit = homeassistant/components/lcn/services.py homeassistant/components/led_ble/__init__.py homeassistant/components/led_ble/light.py - homeassistant/components/led_ble/util.py homeassistant/components/lg_netcast/media_player.py homeassistant/components/lg_soundbar/media_player.py homeassistant/components/lidarr/__init__.py diff --git a/homeassistant/components/bluetooth/manifest.json b/homeassistant/components/bluetooth/manifest.json index 923ab248a2d..cc7237d4585 100644 --- a/homeassistant/components/bluetooth/manifest.json +++ b/homeassistant/components/bluetooth/manifest.json @@ -10,6 +10,7 @@ "bleak-retry-connector==2.8.3", "bluetooth-adapters==0.7.0", "bluetooth-auto-recovery==0.3.6", + "bluetooth-data-tools==0.2.0", "dbus-fast==1.72.0" ], "codeowners": ["@bdraco"], diff --git a/homeassistant/components/led_ble/config_flow.py b/homeassistant/components/led_ble/config_flow.py index 19be92f6647..d757b5021af 100644 --- a/homeassistant/components/led_ble/config_flow.py +++ b/homeassistant/components/led_ble/config_flow.py @@ -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__) diff --git a/homeassistant/components/led_ble/manifest.json b/homeassistant/components/led_ble/manifest.json index 6802eea9bc7..d59570c6257 100644 --- a/homeassistant/components/led_ble/manifest.json +++ b/homeassistant/components/led_ble/manifest.json @@ -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": [ diff --git a/homeassistant/components/led_ble/util.py b/homeassistant/components/led_ble/util.py deleted file mode 100644 index e43655e2905..00000000000 --- a/homeassistant/components/led_ble/util.py +++ /dev/null @@ -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)})" diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 2aa2179a890..4a6b8b076f7 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -14,6 +14,7 @@ bleak-retry-connector==2.8.3 bleak==0.19.2 bluetooth-adapters==0.7.0 bluetooth-auto-recovery==0.3.6 +bluetooth-data-tools==0.2.0 certifi>=2021.5.30 ciso8601==2.2.0 cryptography==38.0.3 diff --git a/requirements_all.txt b/requirements_all.txt index 71c41035267..512c366f5dc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -452,6 +452,10 @@ bluetooth-adapters==0.7.0 # homeassistant.components.bluetooth bluetooth-auto-recovery==0.3.6 +# homeassistant.components.bluetooth +# homeassistant.components.led_ble +bluetooth-data-tools==0.2.0 + # homeassistant.components.bond bond-async==0.1.22 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 0fa8d9274cd..bc44c0c0b6b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -366,6 +366,10 @@ bluetooth-adapters==0.7.0 # homeassistant.components.bluetooth bluetooth-auto-recovery==0.3.6 +# homeassistant.components.bluetooth +# homeassistant.components.led_ble +bluetooth-data-tools==0.2.0 + # homeassistant.components.bond bond-async==0.1.22