Coverage for src / bluetooth_sig / utils / prewarm.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
1"""Registry pre-warming for eager YAML loading.
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"""
8from __future__ import annotations
10import logging
12from ..gatt.characteristics.registry import CharacteristicRegistry
13from ..gatt.services.registry import GattServiceRegistry
14from ..registry.company_identifiers import company_identifiers_registry
15from ..registry.core.ad_types import ad_types_registry
16from ..registry.uuids.units import units_registry
17from ..types.uuid import BluetoothUUID
19logger = logging.getLogger(__name__)
22def prewarm_registries() -> None:
23 """Eagerly load all bluetooth-sig YAML registries.
25 Triggers the lazy-load path for every registry so that subsequent
26 lookups are lock-free and allocation-free. This function performs
27 synchronous file I/O and should be called from an executor thread
28 when used inside an async framework.
30 Covers:
31 - Characteristic registry (all characteristic classes)
32 - Service registry (all service classes)
33 - Units registry (unit UUID → symbol mapping)
34 - Company identifiers registry (manufacturer ID → name)
35 - AD types registry (advertising data type codes)
36 """
37 CharacteristicRegistry.get_all_characteristics()
38 GattServiceRegistry.get_all_services()
40 # Trigger UUID-keyed lookups to populate reverse maps.
41 GattServiceRegistry.get_service_class_by_uuid(BluetoothUUID("0000"))
42 CharacteristicRegistry.get_characteristic_class_by_uuid(BluetoothUUID("0000"))
44 units_registry.ensure_loaded()
45 company_identifiers_registry.ensure_loaded()
46 ad_types_registry.ensure_loaded()
48 logger.debug("bluetooth-sig registries pre-warmed")