11from uuid import UUID
2- from typing import Mapping , Union , cast , TYPE_CHECKING
2+ from typing import Mapping , Optional , Union , cast , TYPE_CHECKING
33
44from bleak .backends .service import BleakGATTService # type: ignore
55from bless .backends .bluezdbus .dbus .service import BlueZGattService
@@ -17,16 +17,20 @@ class BlessGATTServiceBlueZDBus(BaseBlessGATTService, BleakGATTService):
1717 GATT service implementation for the BlueZ backend
1818 """
1919
20- def __init__ (self , uuid : Union [str , UUID ]):
20+ def __init__ (self , uuid : Union [str , UUID ], primary : Optional [ bool ] = None ):
2121 """
2222 Initialize the Bless GATT Service
2323
2424 Parameters
2525 ----------
2626 uuid : Union[str, UUID]
2727 The UUID to assign to the service
28+ primary : Optional[bool]
29+ True if this is a primary service, False otherwise. If None,
30+ default behavior of the backend is used which is only the first
31+ service added is primary.
2832 """
29- BaseBlessGATTService .__init__ (self , uuid )
33+ BaseBlessGATTService .__init__ (self , uuid , primary )
3034 self ._characteristics : Mapping [int , BlessGATTCharacteristic ] = (
3135 {} # type: ignore[assignment]
3236 )
@@ -43,7 +47,9 @@ async def init(self, server: "BaseBlessServer"):
4347 The server to assign the service to
4448 """
4549 bluez_server : "BlessServerBlueZDBus" = cast ("BlessServerBlueZDBus" , server )
46- gatt_service : BlueZGattService = await bluez_server .app .add_service (self ._uuid )
50+ gatt_service : BlueZGattService = await bluez_server .app .add_service (
51+ self ._uuid , primary = self ._primary
52+ )
4753
4854 # Store the BlueZ GATT service
4955 self .gatt = gatt_service
0 commit comments