Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump bleak and dbus-fast versions #89906

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion homeassistant/components/bluetooth/base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _async_on_advertisement(
tx_power=NO_RSSI_VALUE if tx_power is None else tx_power,
platform_data=(),
)
device = BLEDevice( # type: ignore[no-untyped-call]
device = BLEDevice(
address=address,
name=local_name,
details=self._details | details,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/bluetooth/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
],
"quality_scale": "internal",
"requirements": [
"bleak==0.19.5",
"bleak==0.20.0",
"bleak-retry-connector==2.13.0",
"bluetooth-adapters==0.15.2",
"bluetooth-auto-recovery==1.0.3",
"bluetooth-data-tools==0.3.1",
"dbus-fast==1.84.1"
"dbus-fast==1.84.2"
]
}
6 changes: 4 additions & 2 deletions homeassistant/components/esphome/bluetooth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _async_esp_disconnected(self) -> None:
def _async_call_bleak_disconnected_callback(self) -> None:
"""Call the disconnected callback to inform the bleak consumer."""
if self._disconnected_callback:
self._disconnected_callback(self)
self._disconnected_callback()
self._disconnected_callback = None

@api_error_as_bleak_error
Expand Down Expand Up @@ -499,8 +499,10 @@ def _resolve_characteristic(
self, char_specifier: BleakGATTCharacteristic | int | str | uuid.UUID
) -> BleakGATTCharacteristic:
"""Resolve a characteristic specifier to a BleakGATTCharacteristic object."""
if (services := self.services) is None:
raise BleakError("Services have not been resolved")
if not isinstance(char_specifier, BleakGATTCharacteristic):
characteristic = self.services.get_characteristic(char_specifier)
characteristic = services.get_characteristic(char_specifier)
else:
characteristic = char_specifier
if not characteristic:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ attrs==22.2.0
awesomeversion==22.9.0
bcrypt==4.0.1
bleak-retry-connector==2.13.0
bleak==0.19.5
bleak==0.20.0
bluetooth-adapters==0.15.2
bluetooth-auto-recovery==1.0.3
bluetooth-data-tools==0.3.1
certifi>=2021.5.30
ciso8601==2.3.0
cryptography==39.0.1
dbus-fast==1.84.1
dbus-fast==1.84.2
fnvhash==0.1.0
hass-nabucasa==0.61.1
hassil==1.0.6
Expand Down
4 changes: 2 additions & 2 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ bizkaibus==0.1.1
bleak-retry-connector==2.13.0

# homeassistant.components.bluetooth
bleak==0.19.5
bleak==0.20.0

# homeassistant.components.blebox
blebox_uniapi==2.1.4
Expand Down Expand Up @@ -563,7 +563,7 @@ datadog==0.15.0
datapoint==0.9.8

# homeassistant.components.bluetooth
dbus-fast==1.84.1
dbus-fast==1.84.2

# homeassistant.components.debugpy
debugpy==1.6.6
Expand Down
4 changes: 2 additions & 2 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bimmer_connected==0.12.1
bleak-retry-connector==2.13.0

# homeassistant.components.bluetooth
bleak==0.19.5
bleak==0.20.0

# homeassistant.components.blebox
blebox_uniapi==2.1.4
Expand Down Expand Up @@ -449,7 +449,7 @@ datadog==0.15.0
datapoint==0.9.8

# homeassistant.components.bluetooth
dbus-fast==1.84.1
dbus-fast==1.84.2

# homeassistant.components.debugpy
debugpy==1.6.6
Expand Down
5 changes: 3 additions & 2 deletions tests/components/aranet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from time import time

from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData

from homeassistant.components.bluetooth import BluetoothServiceInfoBleak

from tests.components.bluetooth import generate_ble_device


def fake_service_info(name, service_uuid, manufacturer_data):
"""Return a BluetoothServiceInfoBleak for use in testing."""
Expand All @@ -20,7 +21,7 @@ def fake_service_info(name, service_uuid, manufacturer_data):
source="local",
connectable=False,
time=time(),
device=BLEDevice("aa:bb:cc:dd:ee:ff", name=name),
device=generate_ble_device("aa:bb:cc:dd:ee:ff", name=name),
advertisement=AdvertisementData(
local_name=name,
manufacturer_data=manufacturer_data,
Expand Down
33 changes: 31 additions & 2 deletions tests/components/bluetooth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"patch_all_discovered_devices",
"patch_discovered_devices",
"generate_advertisement_data",
"generate_ble_device",
"MockBleakClient",
)

Expand All @@ -46,6 +47,12 @@
"tx_power": -127,
}

BLE_DEVICE_DEFAULTS = {
"name": "",
"rssi": -127,
"details": None,
}


def generate_advertisement_data(**kwargs: Any) -> AdvertisementData:
"""Generate advertisement data with defaults."""
Expand All @@ -55,6 +62,28 @@ def generate_advertisement_data(**kwargs: Any) -> AdvertisementData:
return AdvertisementData(**new)


def generate_ble_device(
address: str | None = None,
name: str | None = None,
details: Any | None = None,
rssi: int | None = None,
**kwargs: Any,
) -> BLEDevice:
"""Generate a BLEDevice with defaults."""
new = kwargs.copy()
if address is not None:
new["address"] = address
if name is not None:
new["name"] = name
if details is not None:
new["details"] = details
if rssi is not None:
new["rssi"] = rssi
for key, value in BLE_DEVICE_DEFAULTS.items():
new.setdefault(key, value)
return BLEDevice(**new)


def _get_manager() -> BluetoothManager:
"""Return the bluetooth manager."""
return models.MANAGER
Expand Down Expand Up @@ -126,7 +155,7 @@ def inject_bluetooth_service_info_bleak(
service_uuids=info.service_uuids,
rssi=info.rssi,
)
device = BLEDevice( # type: ignore[no-untyped-call]
device = generate_ble_device( # type: ignore[no-untyped-call]
address=info.address,
name=info.name,
details={},
Expand All @@ -152,7 +181,7 @@ def inject_bluetooth_service_info(
service_uuids=info.service_uuids,
rssi=info.rssi,
)
device = BLEDevice( # type: ignore[no-untyped-call]
device = generate_ble_device( # type: ignore[no-untyped-call]
address=info.address,
name=info.name,
details={},
Expand Down
16 changes: 8 additions & 8 deletions tests/components/bluetooth/test_advertisement_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
from unittest.mock import patch

from bleak.backends.scanner import BLEDevice
import pytest

from homeassistant.components.bluetooth import (
Expand All @@ -24,6 +23,7 @@
from . import (
FakeScanner,
generate_advertisement_data,
generate_ble_device,
inject_advertisement_with_time_and_source,
inject_advertisement_with_time_and_source_connectable,
)
Expand All @@ -41,7 +41,7 @@ async def test_advertisment_interval_shorter_than_adapter_stack_timeout(
) -> None:
"""Test we can determine the advertisement interval."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:12", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:12", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand", service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]
)
Expand Down Expand Up @@ -88,7 +88,7 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_connectab
) -> None:
"""Test device with a long advertisement interval."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:18", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:18", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand", service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]
)
Expand Down Expand Up @@ -137,7 +137,7 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
) -> None:
"""Test device with a long advertisement interval with an adapter change."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:45", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:45", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand", service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]
)
Expand Down Expand Up @@ -195,7 +195,7 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_not_conne
) -> None:
"""Test device with a long advertisement interval that is not connectable not reaching the advertising interval."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:45", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:45", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand", service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]
)
Expand Down Expand Up @@ -247,7 +247,7 @@ async def test_advertisment_interval_shorter_than_adapter_stack_timeout_adapter_
) -> None:
"""Test device with a short advertisement interval with an adapter change that is not connectable."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:5C", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:5C", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand",
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
Expand Down Expand Up @@ -315,7 +315,7 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
) -> None:
"""Test device with a long advertisement interval with an adapter change that is not connectable."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:45", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:45", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand",
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
Expand Down Expand Up @@ -416,7 +416,7 @@ async def test_advertisment_interval_longer_increasing_than_adapter_stack_timeou
) -> None:
"""Test device with a increasing advertisement interval with an adapter change that is not connectable."""
start_monotonic_time = time.monotonic()
switchbot_device = BLEDevice("44:44:33:11:23:45", "wohand")
switchbot_device = generate_ble_device("44:44:33:11:23:45", "wohand")
switchbot_adv = generate_advertisement_data(
local_name="wohand", service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]
)
Expand Down
12 changes: 9 additions & 3 deletions tests/components/bluetooth/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
)
from homeassistant.core import HomeAssistant

from . import FakeScanner, MockBleakClient, _get_manager, generate_advertisement_data
from . import (
FakeScanner,
MockBleakClient,
_get_manager,
generate_advertisement_data,
generate_ble_device,
)


async def test_scanner_by_source(hass: HomeAssistant, enable_bluetooth: None) -> None:
Expand Down Expand Up @@ -56,7 +62,7 @@ def inject_advertisement(
)
unsetup = scanner.async_setup()
cancel = manager.async_register_scanner(scanner, True)
switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand Down Expand Up @@ -89,7 +95,7 @@ async def test_async_scanner_devices_by_address_non_connectable(
) -> None:
"""Test getting scanner devices by address with non-connectable devices."""
manager = _get_manager()
switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand Down
19 changes: 12 additions & 7 deletions tests/components/bluetooth/test_base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
import homeassistant.util.dt as dt_util
from homeassistant.util.json import json_loads

from . import MockBleakClient, _get_manager, generate_advertisement_data
from . import (
MockBleakClient,
_get_manager,
generate_advertisement_data,
generate_ble_device,
)

from tests.common import async_fire_time_changed, load_fixture

Expand All @@ -38,7 +43,7 @@ async def test_remote_scanner(hass: HomeAssistant, enable_bluetooth: None) -> No
"""Test the remote scanner base class merges advertisement_data."""
manager = _get_manager()

switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand All @@ -51,7 +56,7 @@ async def test_remote_scanner(hass: HomeAssistant, enable_bluetooth: None) -> No
manufacturer_data={1: b"\x01"},
rssi=-100,
)
switchbot_device_2 = BLEDevice(
switchbot_device_2 = generate_ble_device(
"44:44:33:11:23:45",
"w",
{},
Expand Down Expand Up @@ -126,7 +131,7 @@ async def test_remote_scanner_expires_connectable(
"""Test the remote scanner expires stale connectable data."""
manager = _get_manager()

switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand Down Expand Up @@ -200,7 +205,7 @@ async def test_remote_scanner_expires_non_connectable(
"""Test the remote scanner expires stale non connectable data."""
manager = _get_manager()

switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand Down Expand Up @@ -297,7 +302,7 @@ async def test_base_scanner_connecting_behavior(
"""Test that the default behavior is to mark the scanner as not scanning when connecting."""
manager = _get_manager()

switchbot_device = BLEDevice(
switchbot_device = generate_ble_device(
"44:44:33:11:23:45",
"wohand",
{},
Expand Down Expand Up @@ -420,7 +425,7 @@ async def test_device_with_ten_minute_advertising_interval(
"""Test a device with a 10 minute advertising interval."""
manager = _get_manager()

bparasite_device = BLEDevice(
bparasite_device = generate_ble_device(
"44:44:33:11:23:45",
"bparasite",
{},
Expand Down
Loading