From 62e73a843325f8c90891b23565680f00688d6163 Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 13:51:10 -0500 Subject: [PATCH 1/9] Add sync agent + adapter interface --- sdbus_async/bluez/__init__.py | 3 +- sdbus_async/bluez/agent_api.py | 25 +++++ sdbus_block/bluez/__init__.py | 8 ++ sdbus_block/bluez/adapter_api.py | 156 +++++++++++++++++++++++++++++++ sdbus_block/bluez/agent_api.py | 58 ++++++++++++ 5 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 sdbus_block/bluez/adapter_api.py create mode 100644 sdbus_block/bluez/agent_api.py diff --git a/sdbus_async/bluez/__init__.py b/sdbus_async/bluez/__init__.py index d155dc9..1359ce4 100644 --- a/sdbus_async/bluez/__init__.py +++ b/sdbus_async/bluez/__init__.py @@ -20,7 +20,7 @@ from __future__ import annotations from .adapter_api import AdapterInterfaceAsync -from .agent_api import AgentManagerInterfaceAsync +from .agent_api import AgentInterfaceAsync, AgentManagerInterfaceAsync from .battery_api import BatteryInterfaceAsync from .device_api import DeviceInterfaceAsync from .gatt_api import ( @@ -35,6 +35,7 @@ __all__ = ( 'AdapterInterfaceAsync', + 'AgentInterfaceAsync', 'AgentManagerInterfaceAsync', 'BatteryInterfaceAsync', diff --git a/sdbus_async/bluez/agent_api.py b/sdbus_async/bluez/agent_api.py index 195d911..a3c39b7 100644 --- a/sdbus_async/bluez/agent_api.py +++ b/sdbus_async/bluez/agent_api.py @@ -54,3 +54,28 @@ async def request_default_agent( agent_path: str, ) -> None: raise NotImplementedError + + +class AgentInterfaceAsync( + DbusInterfaceCommonAsync, + interface_name='org.bluez.Agent1', +): + @dbus_method_async() + def cancel(self): + raise NotImplementedError + + @dbus_method_async() + def release(self): + raise NotImplementedError + + @dbus_method_async( + input_signature='os', + ) + def authorize_service(self, device: str, uuid: str): + raise NotImplementedError + + @dbus_method_async( + input_signature='o', + ) + def request_authorization(self, device: str): + raise NotImplementedError diff --git a/sdbus_block/bluez/__init__.py b/sdbus_block/bluez/__init__.py index 1a5330d..188ebd6 100644 --- a/sdbus_block/bluez/__init__.py +++ b/sdbus_block/bluez/__init__.py @@ -18,3 +18,11 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from __future__ import annotations + +from .adapter_api import AdapterInterface +from .agent_api import AgentManagerInterface + +__all__ = ( + 'AdapterInterface', + 'AgentManagerInterface', +) diff --git a/sdbus_block/bluez/adapter_api.py b/sdbus_block/bluez/adapter_api.py new file mode 100644 index 0000000..f135453 --- /dev/null +++ b/sdbus_block/bluez/adapter_api.py @@ -0,0 +1,156 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +# Copyright (C) 2022 igo95862 + +# This file is part of python-sdbus + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import annotations + +from typing import Any, Dict, List, Tuple + +from sdbus import ( + DbusInterfaceCommon, + dbus_method, + dbus_property, +) + + +class AdapterInterface( + DbusInterfaceCommon, + interface_name='org.bluez.Adapter1', +): + @dbus_method() + async def start_discovery( + self, + ) -> None: + raise NotImplementedError + + @dbus_method() + async def stop_discovery( + self, + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='o', + ) + async def remove_device( + self, + device_path: str, + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='a{sv}', + ) + async def set_discovery_filter( + self, + properties: Dict[str, Tuple[str, Any]], + ) -> None: + raise NotImplementedError + + @dbus_method( + result_signature='as', + ) + async def get_discovery_filters( + self, + ) -> List[str]: + raise NotImplementedError + + @dbus_property( + property_signature='s', + ) + def address(self) -> str: + raise NotImplementedError + + @dbus_property( + property_signature='s', + ) + def address_type(self) -> str: + raise NotImplementedError + + @dbus_property( + property_signature='s', + ) + def name(self) -> str: + raise NotImplementedError + + @dbus_property( + property_signature='s', + ) + def alias(self) -> str: + raise NotImplementedError + + @dbus_property(property_signature='u', property_name='Class') + def device_class(self) -> int: + raise NotImplementedError + + @dbus_property( + property_signature='b', + ) + def powered(self) -> bool: + raise NotImplementedError + + @dbus_property( + property_signature='b', + ) + def discoverable(self) -> bool: + raise NotImplementedError + + @dbus_property( + property_signature='b', + ) + def pairable(self) -> bool: + raise NotImplementedError + + @dbus_property( + property_signature='u', + ) + def pairable_timeout(self) -> int: + raise NotImplementedError + + @dbus_property( + property_signature='u', + ) + def discoverable_timeout(self) -> int: + raise NotImplementedError + + @dbus_property( + property_signature='b', + ) + def discovering(self) -> bool: + raise NotImplementedError + + @dbus_property( + property_signature='as', + property_name='UUIDs', + ) + def uuids(self) -> List[str]: + raise NotImplementedError + + @dbus_property( + property_signature='s', + ) + def modalias(self) -> str: + raise NotImplementedError + + @dbus_property(property_signature='as') + def roles(self) -> List[str]: + raise NotImplementedError + + @dbus_property(property_signature='as') + def experimental_features(self) -> List[str]: + raise NotImplementedError diff --git a/sdbus_block/bluez/agent_api.py b/sdbus_block/bluez/agent_api.py new file mode 100644 index 0000000..362e7a1 --- /dev/null +++ b/sdbus_block/bluez/agent_api.py @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +# Copyright (C) 2022 igo95862 + +# This file is part of python-sdbus + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import annotations + +from sdbus import ( + DbusInterfaceCommon, + dbus_method, +) + + +class AgentManagerInterface( + DbusInterfaceCommon, + interface_name='org.bluez.AgentManager1', +): + @dbus_method( + input_signature='os', + ) + async def register_agent( + self, + agent_path: str, + capability: str, + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='o', + ) + async def unregister_agent( + self, + agent_path: str, + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='o', + ) + async def request_default_agent( + self, + agent_path: str, + ) -> None: + raise NotImplementedError From a3d35e5c62c0215b88c28642f621f2622af3bbcf Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 13:53:59 -0500 Subject: [PATCH 2/9] Remove async from adapter --- sdbus_block/bluez/adapter_api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdbus_block/bluez/adapter_api.py b/sdbus_block/bluez/adapter_api.py index f135453..370848b 100644 --- a/sdbus_block/bluez/adapter_api.py +++ b/sdbus_block/bluez/adapter_api.py @@ -33,13 +33,13 @@ class AdapterInterface( interface_name='org.bluez.Adapter1', ): @dbus_method() - async def start_discovery( + def start_discovery( self, ) -> None: raise NotImplementedError @dbus_method() - async def stop_discovery( + def stop_discovery( self, ) -> None: raise NotImplementedError @@ -47,7 +47,7 @@ async def stop_discovery( @dbus_method( input_signature='o', ) - async def remove_device( + def remove_device( self, device_path: str, ) -> None: @@ -56,7 +56,7 @@ async def remove_device( @dbus_method( input_signature='a{sv}', ) - async def set_discovery_filter( + def set_discovery_filter( self, properties: Dict[str, Tuple[str, Any]], ) -> None: @@ -65,7 +65,7 @@ async def set_discovery_filter( @dbus_method( result_signature='as', ) - async def get_discovery_filters( + def get_discovery_filters( self, ) -> List[str]: raise NotImplementedError From a9f53db0a920e8571f0156793042703818b9814e Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 13:59:18 -0500 Subject: [PATCH 3/9] Bad at leaving in async --- sdbus_block/bluez/agent_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdbus_block/bluez/agent_api.py b/sdbus_block/bluez/agent_api.py index 362e7a1..4dd849b 100644 --- a/sdbus_block/bluez/agent_api.py +++ b/sdbus_block/bluez/agent_api.py @@ -32,7 +32,7 @@ class AgentManagerInterface( @dbus_method( input_signature='os', ) - async def register_agent( + def register_agent( self, agent_path: str, capability: str, @@ -42,7 +42,7 @@ async def register_agent( @dbus_method( input_signature='o', ) - async def unregister_agent( + def unregister_agent( self, agent_path: str, ) -> None: @@ -51,7 +51,7 @@ async def unregister_agent( @dbus_method( input_signature='o', ) - async def request_default_agent( + def request_default_agent( self, agent_path: str, ) -> None: From 84a2ccda3ef5ba2a66e1eccfb307212664d1437b Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 17:08:36 -0500 Subject: [PATCH 4/9] More interfaces --- sdbus_async/bluez/agent_api.py | 8 ++-- sdbus_block/bluez/profile_api.py | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 sdbus_block/bluez/profile_api.py diff --git a/sdbus_async/bluez/agent_api.py b/sdbus_async/bluez/agent_api.py index a3c39b7..75a24c6 100644 --- a/sdbus_async/bluez/agent_api.py +++ b/sdbus_async/bluez/agent_api.py @@ -61,21 +61,21 @@ class AgentInterfaceAsync( interface_name='org.bluez.Agent1', ): @dbus_method_async() - def cancel(self): + async def cancel(self): raise NotImplementedError @dbus_method_async() - def release(self): + async def release(self): raise NotImplementedError @dbus_method_async( input_signature='os', ) - def authorize_service(self, device: str, uuid: str): + async def authorize_service(self, device: str, uuid: str): raise NotImplementedError @dbus_method_async( input_signature='o', ) - def request_authorization(self, device: str): + async def request_authorization(self, device: str): raise NotImplementedError diff --git a/sdbus_block/bluez/profile_api.py b/sdbus_block/bluez/profile_api.py new file mode 100644 index 0000000..3bdeb22 --- /dev/null +++ b/sdbus_block/bluez/profile_api.py @@ -0,0 +1,82 @@ + +# SPDX-License-Identifier: LGPL-2.1-or-later + +# Copyright (C) 2022 igo95862 + +# This file is part of python-sdbus + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import annotations + +from typing import Any, Dict, Tuple + +from sdbus import DbusInterfaceCommonAsync, dbus_method + + +class ProfileManagerInterface( + DbusInterfaceCommonAsync, + interface_name='org.bluez.ProfileManager1', +): + + @dbus_method( + input_signature='osa{sv}', + ) + def register_profile( + self, + profile_path: str, + uuid: str, + options: Dict[str, Tuple[str, Any]], + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='o', + ) + def unregister_profile( + self, + profile_path: str, + ) -> None: + raise NotImplementedError + +class ProfileInterface( + DbusInterfaceCommonAsync, + interface_name='org.bluez.Profile1', +): + + @dbus_method() + def release( + self, + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='oha{sv}', + ) + def new_connection( + self, + device: str, + fd: int, + fd_properties: Dict[str, Tuple[str, Any]], + ) -> None: + raise NotImplementedError + + @dbus_method( + input_signature='o', + ) + def request_disconnection( + self, + device: str, + ) -> None: + raise NotImplementedError From e958dd5b657b59d39ed2d7b72d85a1fb73092e6b Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 17:12:46 -0500 Subject: [PATCH 5/9] export profileinterface async --- sdbus_async/bluez/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdbus_async/bluez/__init__.py b/sdbus_async/bluez/__init__.py index 1359ce4..2ac4035 100644 --- a/sdbus_async/bluez/__init__.py +++ b/sdbus_async/bluez/__init__.py @@ -30,7 +30,7 @@ ) from .media_api import MediaInterfaceAsync from .network_api import NetworkServerInterfaceAsync -from .profile_api import ProfileManagerInterfaceAsync +from .profile_api import ProfileInterfaceAsync, ProfileManagerInterfaceAsync __all__ = ( 'AdapterInterfaceAsync', @@ -50,5 +50,6 @@ 'NetworkServerInterfaceAsync', + 'ProfileInterfaceAsync', 'ProfileManagerInterfaceAsync', ) From eb234467b71eb912b27113938ca0d0816a1395c6 Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 17:14:38 -0500 Subject: [PATCH 6/9] Forgot some profile interfaces --- sdbus_block/bluez/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdbus_block/bluez/__init__.py b/sdbus_block/bluez/__init__.py index 188ebd6..591c254 100644 --- a/sdbus_block/bluez/__init__.py +++ b/sdbus_block/bluez/__init__.py @@ -21,8 +21,12 @@ from .adapter_api import AdapterInterface from .agent_api import AgentManagerInterface +from .profile_api import ProfileInterface, ProfileManagerInterface __all__ = ( 'AdapterInterface', 'AgentManagerInterface', + + 'ProfileInterface', + 'ProfileManagerInterface', ) From 66ff9a27672060ff7b076e320441de2479580ae2 Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 3 Mar 2025 17:16:13 -0500 Subject: [PATCH 7/9] Fix --- sdbus_block/bluez/profile_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdbus_block/bluez/profile_api.py b/sdbus_block/bluez/profile_api.py index 3bdeb22..ee1e737 100644 --- a/sdbus_block/bluez/profile_api.py +++ b/sdbus_block/bluez/profile_api.py @@ -22,11 +22,11 @@ from typing import Any, Dict, Tuple -from sdbus import DbusInterfaceCommonAsync, dbus_method +from sdbus import DbusInterfaceCommon, dbus_method class ProfileManagerInterface( - DbusInterfaceCommonAsync, + DbusInterfaceCommon, interface_name='org.bluez.ProfileManager1', ): @@ -51,7 +51,7 @@ def unregister_profile( raise NotImplementedError class ProfileInterface( - DbusInterfaceCommonAsync, + DbusInterfaceCommon, interface_name='org.bluez.Profile1', ): From 5db51995e0e533299ca674da195768f51cb014f3 Mon Sep 17 00:00:00 2001 From: jlucier Date: Fri, 4 Apr 2025 08:42:09 -0400 Subject: [PATCH 8/9] Fix formatting issues --- sdbus_async/bluez/agent_api.py | 2 +- sdbus_block/bluez/profile_api.py | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/sdbus_async/bluez/agent_api.py b/sdbus_async/bluez/agent_api.py index 75a24c6..8cd532c 100644 --- a/sdbus_async/bluez/agent_api.py +++ b/sdbus_async/bluez/agent_api.py @@ -61,7 +61,7 @@ class AgentInterfaceAsync( interface_name='org.bluez.Agent1', ): @dbus_method_async() - async def cancel(self): + async def cancel(self) -> None: raise NotImplementedError @dbus_method_async() diff --git a/sdbus_block/bluez/profile_api.py b/sdbus_block/bluez/profile_api.py index ee1e737..752a272 100644 --- a/sdbus_block/bluez/profile_api.py +++ b/sdbus_block/bluez/profile_api.py @@ -1,4 +1,3 @@ - # SPDX-License-Identifier: LGPL-2.1-or-later # Copyright (C) 2022 igo95862 @@ -56,19 +55,17 @@ class ProfileInterface( ): @dbus_method() - def release( - self, - ) -> None: + def release(self) -> None: raise NotImplementedError @dbus_method( input_signature='oha{sv}', ) def new_connection( - self, - device: str, - fd: int, - fd_properties: Dict[str, Tuple[str, Any]], + self, + device: str, + fd: int, + fd_properties: Dict[str, Tuple[str, Any]], ) -> None: raise NotImplementedError @@ -76,7 +73,7 @@ def new_connection( input_signature='o', ) def request_disconnection( - self, - device: str, + self, + device: str, ) -> None: raise NotImplementedError From 40b70d1c3b94504309b7be5b4e4e5464834d5c49 Mon Sep 17 00:00:00 2001 From: Jordan Lucier Date: Mon, 7 Apr 2025 15:14:21 -0400 Subject: [PATCH 9/9] More type hints --- sdbus_async/bluez/agent_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdbus_async/bluez/agent_api.py b/sdbus_async/bluez/agent_api.py index 8cd532c..2c45add 100644 --- a/sdbus_async/bluez/agent_api.py +++ b/sdbus_async/bluez/agent_api.py @@ -65,17 +65,17 @@ async def cancel(self) -> None: raise NotImplementedError @dbus_method_async() - async def release(self): + async def release(self) -> None: raise NotImplementedError @dbus_method_async( input_signature='os', ) - async def authorize_service(self, device: str, uuid: str): + async def authorize_service(self, device: str, uuid: str) -> None: raise NotImplementedError @dbus_method_async( input_signature='o', ) - async def request_authorization(self, device: str): + async def request_authorization(self, device: str) -> None: raise NotImplementedError