diff --git a/bleak/backends/bluezdbus/characteristic.py b/bleak/backends/bluezdbus/characteristic.py index 5208d19b..3b41147b 100644 --- a/bleak/backends/bluezdbus/characteristic.py +++ b/bleak/backends/bluezdbus/characteristic.py @@ -94,7 +94,7 @@ def get_descriptor( except StopIteration: return None - def add_descriptor(self, descriptor: BleakGATTDescriptor): + def add_descriptor(self, descriptor: BleakGATTDescriptor) -> None: """Add a :py:class:`~BleakGATTDescriptor` to the characteristic. Should not be used by end user, but rather by `bleak` itself. diff --git a/bleak/backends/bluezdbus/manager.py b/bleak/backends/bluezdbus/manager.py index d869e899..d3612284 100644 --- a/bleak/backends/bluezdbus/manager.py +++ b/bleak/backends/bluezdbus/manager.py @@ -238,7 +238,7 @@ def _get_device_property( return value - async def async_init(self): + async def async_init(self) -> None: """ Connects to the D-Bus message bus and begins monitoring signals. @@ -552,7 +552,7 @@ async def passive_scan( # won't use the monitor self._bus.export(monitor_path, monitor) - async def stop(): + async def stop() -> None: # need to remove callbacks first, otherwise we get TxPower # and RSSI properties removed during stop which causes # incorrect advertisement data callbacks @@ -868,7 +868,7 @@ def _wait_condition_callback(new_value: Optional[Any]) -> None: if not device_callbacks: del condition_callbacks[device_path] - def _parse_msg(self, message: Message): + def _parse_msg(self, message: Message) -> None: """ Handles callbacks from dbus_fast. """ diff --git a/bleak/backends/bluezdbus/service.py b/bleak/backends/bluezdbus/service.py index a6563782..a1a8d3c2 100644 --- a/bleak/backends/bluezdbus/service.py +++ b/bleak/backends/bluezdbus/service.py @@ -1,4 +1,4 @@ -from typing import List +from typing import Any, List from ..service import BleakGATTService from .characteristic import BleakGATTCharacteristicBlueZDBus @@ -8,7 +8,7 @@ class BleakGATTServiceBlueZDBus(BleakGATTService): """GATT Service implementation for the BlueZ DBus backend""" - def __init__(self, obj, path): + def __init__(self, obj: Any, path: str): super().__init__(obj) self.__characteristics = [] self.__path = path @@ -29,7 +29,9 @@ def characteristics(self) -> List[BleakGATTCharacteristicBlueZDBus]: """List of characteristics for this service""" return self.__characteristics - def add_characteristic(self, characteristic: BleakGATTCharacteristicBlueZDBus): + def add_characteristic( + self, characteristic: BleakGATTCharacteristicBlueZDBus + ) -> None: """Add a :py:class:`~BleakGATTCharacteristicBlueZDBus` to the service. Should not be used by end user, but rather by `bleak` itself. @@ -37,6 +39,6 @@ def add_characteristic(self, characteristic: BleakGATTCharacteristicBlueZDBus): self.__characteristics.append(characteristic) @property - def path(self): + def path(self) -> str: """The DBus path. Mostly needed by `bleak`, not by end user""" return self.__path diff --git a/bleak/backends/bluezdbus/signals.py b/bleak/backends/bluezdbus/signals.py index 059b65ad..6a2ce353 100644 --- a/bleak/backends/bluezdbus/signals.py +++ b/bleak/backends/bluezdbus/signals.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import annotations import re from typing import Any, Coroutine, Dict, Optional @@ -19,7 +20,7 @@ class InvalidMessageTypeError(TypeError): - def __init__(self, type): + def __init__(self, type: str): super().__init__(f"invalid message type: {type}") @@ -37,7 +38,7 @@ def is_message_type_valid(type: str) -> bool: return type in _message_types -def assert_bus_name_valid(type: str): +def assert_bus_name_valid(type: str) -> None: """Raise an error if this is not a valid message type. .. seealso:: https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing-match-rules @@ -136,7 +137,7 @@ def __init__( self.args = None @staticmethod - def parse(rules: str): + def parse(rules: str) -> MatchRules: return MatchRules(**dict(r.split("=") for r in rules.split(","))) def __str__(self) -> str: diff --git a/bleak/backends/bluezdbus/utils.py b/bleak/backends/bluezdbus/utils.py index 76933790..8dd25d58 100644 --- a/bleak/backends/bluezdbus/utils.py +++ b/bleak/backends/bluezdbus/utils.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import os +from typing import Optional from dbus_fast.auth import AuthExternal from dbus_fast.constants import MessageType @@ -8,7 +9,7 @@ from ...exc import BleakError, BleakDBusError -def assert_reply(reply: Message): +def assert_reply(reply: Message) -> None: """Checks that a D-Bus message is a valid reply. Raises: @@ -20,7 +21,7 @@ def assert_reply(reply: Message): assert reply.message_type == MessageType.METHOD_RETURN -def extract_service_handle_from_path(path): +def extract_service_handle_from_path(path: str) -> int: try: return int(path[-4:], 16) except Exception as e: @@ -54,7 +55,7 @@ def device_path_from_characteristic_path(characteristic_path: str) -> str: return characteristic_path[:37] -def get_dbus_authenticator(): +def get_dbus_authenticator() -> Optional[AuthExternal]: uid = None try: uid = int(os.environ.get("BLEAK_DBUS_AUTH_UID", "")) diff --git a/bleak/backends/bluezdbus/version.py b/bleak/backends/bluezdbus/version.py index 3e3c616d..40842cb9 100644 --- a/bleak/backends/bluezdbus/version.py +++ b/bleak/backends/bluezdbus/version.py @@ -7,7 +7,7 @@ logger = logging.getLogger(__name__) -async def _get_bluetoothctl_version(): +async def _get_bluetoothctl_version() -> Optional[re.Match]: """Get the version of bluetoothctl.""" with contextlib.suppress(Exception): proc = await asyncio.create_subprocess_exec(