Coverage for src/bluetooth_sig/utils/prewarm.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-06-28 01:26 +0000

1"""Registry pre-warming for eager YAML loading. 

2 

3Consumers that run inside an event loop (e.g. Home Assistant) should call 

4:func:`prewarm_registries` in an executor thread during setup to avoid 

5blocking I/O on first access. 

6""" 

7 

8from __future__ import annotations 

9 

10import logging 

11 

12from .prewarm_catalog import get_prewarm_loaders 

13 

14logger = logging.getLogger(__name__) 

15 

16 

17def prewarm_registries() -> None: 

18 """Eagerly load all bluetooth-sig YAML registries. 

19 

20 Triggers the lazy-load path for every registry so that subsequent 

21 lookups are lock-free and allocation-free. This function performs 

22 synchronous file I/O and should be called from an executor thread 

23 when used inside an async framework. 

24 

25 Covers: 

26 - Characteristic registry (all characteristic classes) 

27 - Service registry (all service classes) 

28 - Units registry (unit UUID → symbol mapping) 

29 - Company identifiers registry (manufacturer ID → name) 

30 - AD types registry (advertising data type codes) 

31 - Appearance values registry (appearance code → device type) 

32 - Class of device registry (CoD bitfield → device type) 

33 - Coding format registry (LE Audio codec identifiers) 

34 - Format types registry (characteristic data format codes) 

35 - Namespace description registry (CPF description field values) 

36 - URI schemes registry (beacon URI scheme codes) 

37 - Permitted characteristics registry (profile characteristic constraints) 

38 - Profile lookup registry (profile parameter tables) 

39 - Service discovery attribute registry (SDP attribute identifiers) 

40 - Browse groups registry (SDP browse group UUIDs) 

41 - Declarations registry (GATT declaration UUIDs) 

42 - Members registry (Bluetooth member organisation UUIDs) 

43 - Mesh profiles registry (mesh profile UUIDs) 

44 - Object types registry (OTS object type UUIDs) 

45 - Protocol identifiers registry (protocol UUID identifiers) 

46 - SDO UUIDs registry (standards body UUIDs) 

47 - Service classes registry (service class UUIDs) 

48 - UUID registry (service/characteristic/descriptor metadata hub) 

49 """ 

50 for loader_name, loader in get_prewarm_loaders(): 

51 loader() 

52 logger.debug("pre-warmed %s", loader_name) 

53 

54 logger.debug("bluetooth-sig registries pre-warmed")