strict compliance check

This commit is contained in:
Gilles Boccon-Gibod
2024-08-12 08:20:36 -07:00
parent ab6e595bcb
commit 9dd814f32e

View File

@@ -20,12 +20,12 @@
import enum import enum
import logging import logging
import struct import struct
from typing import Optional
from bumble.gatt import ( from bumble.gatt import (
TemplateService, TemplateService,
Characteristic, Characteristic,
DelegatedCharacteristicAdapter, DelegatedCharacteristicAdapter,
InvalidServiceError,
GATT_TELEPHONY_AND_MEDIA_AUDIO_SERVICE, GATT_TELEPHONY_AND_MEDIA_AUDIO_SERVICE,
GATT_TMAP_ROLE_CHARACTERISTIC, GATT_TMAP_ROLE_CHARACTERISTIC,
) )
@@ -69,19 +69,21 @@ class TelephonyAndMediaAudioService(TemplateService):
class TelephonyAndMediaAudioServiceProxy(ProfileServiceProxy): class TelephonyAndMediaAudioServiceProxy(ProfileServiceProxy):
SERVICE_CLASS = TelephonyAndMediaAudioService SERVICE_CLASS = TelephonyAndMediaAudioService
role: Optional[DelegatedCharacteristicAdapter] role: DelegatedCharacteristicAdapter
def __init__(self, service_proxy: ServiceProxy): def __init__(self, service_proxy: ServiceProxy):
self.service_proxy = service_proxy self.service_proxy = service_proxy
if characteristics := service_proxy.get_characteristics_by_uuid( if not (
GATT_TMAP_ROLE_CHARACTERISTIC characteristics := service_proxy.get_characteristics_by_uuid(
): GATT_TMAP_ROLE_CHARACTERISTIC
self.role = DelegatedCharacteristicAdapter(
characteristics[0],
decode=lambda value: Role(
struct.unpack_from('<H', value, 0)[0],
),
) )
else: ):
self.role = None raise InvalidServiceError('TMAP Role characteristic not found')
self.role = DelegatedCharacteristicAdapter(
characteristics[0],
decode=lambda value: Role(
struct.unpack_from('<H', value, 0)[0],
),
)