Coverage for src / bluetooth_sig / gatt / characteristics / database_hash.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-03 16:41 +0000

1"""Database Hash characteristic (0x2B2A).""" 

2 

3from __future__ import annotations 

4 

5from ..context import CharacteristicContext 

6from .base import BaseCharacteristic 

7 

8 

9class DatabaseHashCharacteristic(BaseCharacteristic[bytes]): 

10 """Database Hash characteristic (0x2B2A). 

11 

12 org.bluetooth.characteristic.database_hash 

13 

14 128-bit (16-byte) hash of the GATT database. 

15 """ 

16 

17 expected_length: int = 16 

18 

19 def _decode_value( 

20 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True 

21 ) -> bytes: 

22 return bytes(data[:16]) 

23 

24 def _encode_value(self, data: bytes) -> bytearray: 

25 return bytearray(data[:16].ljust(16, b"\x00"))