python3Packages.pyzerproc: fix compat with bleak 1.0.0

Changed files
+84 -21
pkgs
development
python-modules
+76
pkgs/development/python-modules/pyzerproc/bleak-compat.patch
···
···
+
diff --git a/pyzerproc/discovery.py b/pyzerproc/discovery.py
+
index e383996..1810bbe 100644
+
--- a/pyzerproc/discovery.py
+
+++ b/pyzerproc/discovery.py
+
@@ -4,6 +4,9 @@ import logging
+
from .light import Light
+
from .exceptions import ZerprocException
+
+
+from bleak import BLEDevice, BleakScanner, AdvertisementData
+
+from bleak.exc import BleakError
+
+
+
_LOGGER = logging.getLogger(__name__)
+
+
EXPECTED_SERVICES = [
+
@@ -13,27 +16,25 @@ EXPECTED_SERVICES = [
+
]
+
+
+
-def is_valid_device(device):
+
+def is_valid_device(device: BLEDevice, advertisement_data: AdvertisementData):
+
"""Returns true if the given device is a Zerproc light."""
+
for service in EXPECTED_SERVICES:
+
- if service not in device.metadata['uuids']:
+
+ if service not in advertisement_data.service_uuids:
+
return False
+
return True
+
+
+
async def discover(timeout=10):
+
"""Returns nearby discovered lights."""
+
- import bleak
+
-
+
_LOGGER.info("Starting scan for local devices")
+
+
lights = []
+
try:
+
- devices = await bleak.BleakScanner.discover(timeout=timeout)
+
- except bleak.exc.BleakError as ex:
+
+ devices = await BleakScanner.discover(timeout=timeout, return_adv=True)
+
+ except BleakError as ex:
+
raise ZerprocException() from ex
+
- for device in devices:
+
- if is_valid_device(device):
+
+ for device, advertisement_data in devices:
+
+ if is_valid_device(device, advertisement_data):
+
lights.append(Light(device.address, device.name))
+
+
_LOGGER.info("Scan complete")
+
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
+
index 7a1442d..6b271b8 100644
+
--- a/tests/test_discovery.py
+
+++ b/tests/test_discovery.py
+
@@ -16,7 +16,6 @@ async def test_discover_devices(scanner, client_class):
+
'AA:BB:CC:11:22:33',
+
'LEDBlue-CC112233',
+
{},
+
- 0,
+
uuids=[
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
+
"0000ffe5-0000-1000-8000-00805f9b34fb",
+
@@ -27,7 +26,6 @@ async def test_discover_devices(scanner, client_class):
+
'AA:BB:CC:44:55:66',
+
'LEDBlue-CC445566',
+
{},
+
- 0,
+
uuids=[
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
+
"0000ffe5-0000-1000-8000-00805f9b34fb",
+
@@ -38,7 +36,6 @@ async def test_discover_devices(scanner, client_class):
+
'DD:EE:FF:11:22:33',
+
'Other',
+
{},
+
- 0,
+
uuids=[
+
"0000fe9f-0000-1000-8000-00805f9b34fb",
+
],
+8 -21
pkgs/development/python-modules/pyzerproc/default.nix
···
click,
buildPythonPackage,
fetchFromGitHub,
-
pytest-asyncio,
-
pytest-mock,
-
pythonAtLeast,
-
pytest-cov-stub,
-
pytestCheckHook,
-
pythonOlder,
}:
buildPythonPackage rec {
pname = "pyzerproc";
version = "0.4.12";
-
format = "setuptools";
-
-
disabled = pythonOlder "3.9";
src = fetchFromGitHub {
owner = "emlove";
···
hash = "sha256-vS0sk/KjDhWispZvCuGlmVLLfeFymHqxwNzNqNRhg6k=";
};
-
propagatedBuildInputs = [
bleak
click
];
-
nativeCheckInputs = [
-
pytest-asyncio
-
pytest-mock
-
pytest-cov-stub
-
pytestCheckHook
-
];
-
-
disabledTestPaths = lib.optionals (pythonAtLeast "3.11") [
-
# unittest.mock.InvalidSpecError: Cannot spec a Mock object.
-
"tests/test_light.py"
-
];
pythonImportsCheck = [ "pyzerproc" ];
···
click,
buildPythonPackage,
fetchFromGitHub,
+
setuptools,
}:
buildPythonPackage rec {
pname = "pyzerproc";
version = "0.4.12";
+
pyproject = true;
src = fetchFromGitHub {
owner = "emlove";
···
hash = "sha256-vS0sk/KjDhWispZvCuGlmVLLfeFymHqxwNzNqNRhg6k=";
};
+
patches = [ ./bleak-compat.patch ];
+
+
build-system = [ setuptools ];
+
+
dependencies = [
bleak
click
];
+
doCheck = false; # tries to access dbus, which leads to FileNotFoundError
pythonImportsCheck = [ "pyzerproc" ];