Skip to content

Device extensions#144

Merged
RonanB96 merged 8 commits intomainfrom
device_extensions
Nov 16, 2025
Merged

Device extensions#144
RonanB96 merged 8 commits intomainfrom
device_extensions

Conversation

@RonanB96
Copy link
Owner

@RonanB96 RonanB96 commented Nov 16, 2025

This pull request primarily improves documentation and usage clarity for the Bluetooth SIG Python library, focusing on making BLE integration and characteristic parsing easier to understand for users. It introduces simulated data examples across guides and API docs, clarifies best practices and prohibited implementation patterns, and simplifies async usage by consolidating the API to a single BluetoothSIGTranslator class for both sync and async methods. The changes also enhance explanations around UUID handling and parsing, making it clear that users do not need to know characteristic meanings in advance.

Documentation and Usage Example Improvements:

  • Updated all guides and API documentation to use simulated data examples (SIMULATED_BATTERY_DATA, etc.), making it clear how to replace these with actual BLE reads in real-world scenarios. This change affects README.md, docs/api/core.md, docs/api/gatt.md, and async usage guides. [1] [2] [3] [4] [5] [6]
  • Clarified that the BLE library provides UUIDs and that bluetooth-sig automatically identifies and parses them, removing the need for users to understand UUID meanings.

Async API Simplification:

  • Deprecated the separate AsyncBluetoothSIGTranslator class, consolidating all async and sync methods into BluetoothSIGTranslator for a simpler, unified API. All async usage examples and migration notes have been updated accordingly. [1] [2] [3]

Python Implementation Guidelines Update:

  • Moved and expanded the "Prohibited Practices" section, making it more prominent and explicit in .github/instructions/python-implementation.instructions.md. This section now includes additional forbidden patterns and clarifies type safety requirements. [1] [2]

Linting and Quality Gate Clarifications:

  • Added instructions to .github/copilot-instructions.md prohibiting the use of grep/tail on linter output for performance reasons, and clarified linting workflow expectations.

Minor Documentation Corrections:

  • Adjusted incomplete example code and clarified usage of timestamp parsing in characteristic examples.

Copilot AI and others added 7 commits November 16, 2025 17:13
Implement Nordic Thingy:52 support with vendor characteristic adapters

Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
- Create thingy52_bluepy.py with full BluePy integration
- Implement Thingy52 class for device connection and reading
- Add CLI with flexible sensor selection and continuous reading
- Fix bot review comments (duplicate comment, long line formatting)
- Update README with BluePy usage instructions

Addresses user feedback: now supports real device connection, not just mock data

Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
- Create custom characteristic classes extending CustomBaseCharacteristic
- Register with CharacteristicRegistry using translator.register_custom_characteristic_class()
- Implement ConnectionManagerProtocol for BluePy integration
- Use Device class for unified SIG + vendor characteristic access
- Add comprehensive tests (26 tests, all passing)
- Demonstrates proper library extension, not bypassing it

Files:
- examples/thingy52_characteristics.py: 8 custom characteristic classes
- examples/thingy52_example.py: Real device example using Device class
- tests/integration/test_thingy52_characteristics.py: Comprehensive tests

Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
…ec.Struct, reusable BluePy adapter

Major improvements addressing all feedback:
1. Use templates: Sint8Template, Uint8Template, Uint16Template, Uint32Template instead of struct.unpack
2. Use DataParser.parse_int32() instead of struct.unpack for heading
3. Use proper exceptions: InsufficientDataError, ValueRangeError from bluetooth_sig.gatt.exceptions
4. Use msgspec.Struct: ThingyGasData, ThingyColorData for structured returns (no raw dict)
5. Create reusable BluePy adapter: examples/connection_managers/bluepy.py (follows bleak/simpleble pattern)
6. Address all 27 bot review comments: proper exceptions, msgspec structs, correct docstrings

Files:
- examples/connection_managers/bluepy.py: Reusable BluePy connection manager (NEW)
- examples/thingy52_characteristics.py: 8 characteristics using templates & proper patterns
- examples/thingy52_example.py: Real device example using reusable BluePy adapter
- tests/integration/test_thingy52_characteristics.py: 26 tests, all passing

Quality gates: ✅ ALL PASSING (ruff, pylint, mypy, shellcheck, pydocstyle, 26 tests)

Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
…classes

BREAKING CHANGE: CharacteristicData moved from types to gatt.characteristics.base

Major Changes:
- Move CharacteristicData to gatt.characteristics.base with back-reference to characteristic
- Remove properties field from CharacteristicInfo (now runtime attribute on BaseCharacteristic)
- Extract CustomBaseCharacteristic to gatt.characteristics.custom module
- Extract UnknownCharacteristic to gatt.characteristics.unknown module
- Add CustomBaseGattService in gatt.services.custom module
- Add UnknownService in gatt.services.unknown module
- Create descriptor_utils.py module with helper functions
- Add location.py types module for PositionStatus enum
- Add last_parsed attribute to BaseCharacteristic for result caching
- Remove descriptor_data parameter from CharacteristicData constructor

Architecture:
- CharacteristicData now stores characteristic reference instead of CharacteristicInfo
- Properties are discovered at runtime from actual devices, not YAML specs
- Cleaner separation between SIG characteristics, custom, and unknown types
- Descriptor utilities extracted for reusability
- Registry validation skips base classes via _is_base_class flag

API Changes:
- CharacteristicDataProtocol updated with property accessors
- DeviceService.characteristics now stores BaseCharacteristic instances
- parse_characteristic no longer accepts descriptor_data parameter
- Custom characteristics support auto_register parameter (defaults True)

Testing:
- Update all imports from types.CharacteristicData to gatt.characteristics.base
- Fix test mocks to use UnknownCharacteristic for test data
- Remove properties from CharacteristicInfo in test fixtures
- Update examples and integration tests

Benefits:
- Single source of truth: characteristic owns its last parsed result
- Type safety: CharacteristicData always linked to parsing characteristic
- Cleaner module organization with focused responsibilities
- Better support for runtime device discovery patterns
- Simplified descriptor access through utility functions
@RonanB96 RonanB96 self-assigned this Nov 16, 2025
@RonanB96 RonanB96 force-pushed the device_extensions branch 3 times, most recently from bfaa01f to 69a54f9 Compare November 16, 2025 20:20
…ED_* variables and UUIDs; add code block tests for docs; improve enum-based workflows and test coverage; clarify standards compliance in examples
@RonanB96 RonanB96 merged commit c4fe7f6 into main Nov 16, 2025
11 checks passed
@RonanB96 RonanB96 deleted the device_extensions branch November 16, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants