Conversation
|
@copilot no legacy or backward compatibility code, just get the arch in line with how the chars are done. This means removing the dataclasses for the services, follow best practices. The overall code should follow a very similar if not the same arch to be maintainable and understandable |
Done! I've removed all @DataClass decorators from service classes and aligned the architecture exactly with how characteristics work: Key Changes:
All 805 tests pass, formatting and linting are clean. The service architecture now mirrors the characteristic architecture exactly. |
- Remove @DataClass from BaseGattService and all concrete services - Add SIGServiceResolver for consistent resolution pattern - Add ServiceValidationConfig for validation parameters - Add __init__ and __post_init__ methods to BaseGattService - Make _info the single source of truth for uuid, name, summary - Add get_class_uuid() class method for resolution without instantiation - Refactor CustomBaseGattService with __init_subclass__ hook - Add class-level _info attribute support with SIG override validation - Add UnknownService class in base.py - Update device.py UnknownService to work with new architecture - Add is_sig_service() method to BluetoothUUID class - All 805 tests pass, formatting and linting clean Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR refactors all service classes to align with the established characteristic architecture pattern, removing legacy dataclass patterns and implementing a clean, maintainable design following established best practices.
Key Changes:
- Removed
@dataclassdecorators from all service classes and implemented proper__init__methods for BaseGattService - Added SIGServiceResolver class for centralized service resolution logic mirroring the characteristic pattern
- Created CustomBaseGattService enhancements with
__init_subclass__hooks and class-level_infoattribute support
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/bluetooth_sig/types/uuid.py | Added is_sig_service() method and SIG service UUID range constants |
| src/bluetooth_sig/gatt/services/base.py | Major refactor: removed @DataClass, added SIGServiceResolver, new init patterns, CustomBaseGattService enhancements |
| src/bluetooth_sig/gatt/services/*.py | Removed @DataClass decorators from all concrete service implementations |
| src/bluetooth_sig/device/device.py | Updated UnknownService class to work with new service architecture |
- Reorder service name resolution by hit rate: space-separated (64%) first, without-suffix (14%) second - Remove unnecessary Progressive API Level comments - Replace hasattr/getattr pattern with direct __dict__ check for _info attribute - Relax timing test threshold from 1s to 2s to avoid flakiness - All 805 tests pass, formatting and linting clean Co-authored-by: RonanB96 <22995167+RonanB96@users.noreply.github.com>
Addressed all review comments:
All 805 tests pass, formatting and linting clean. |
SIGServiceResolverclass with resolution logicServiceValidationConfigdataclassis_sig_service()method to UUID class__init__(info, validation)method__post_init__()for SIG resolution_infoget_class_uuid()class method__init_subclass__hook withallow_sig_override_infoattribute support_configured_infoclass attribute__post_init__()for custom info managementUnknownServiceclassOriginal prompt
This section details on the original issue you should resolve
<issue_title># Service Class Refactoring</issue_title>
<issue_description># Service Class Refactoring - Executive Summary
Created: 2025-10-06
Full Guide:
docs/SERVICE_CLASS_REFACTORING_GUIDE.mdStatus: Architecture Specification Ready
Quick Overview
This document summarizes the architectural refactoring needed to align
BaseGattServiceandCustomBaseGattServicewith the proven patterns fromBaseCharacteristicandCustomBaseCharacteristic.Key Changes Required
1. Single Source of Truth Pattern
_info: ServiceInfoas the single source for all service metadatauuid,name,summary) read from_info2. Resolver Pattern
SIGServiceResolverclass (parallel toSIGCharacteristicResolver)3. Constructor Refactoring
@dataclassdecorator fromBaseGattService__init__(info: ServiceInfo | None, validation: ServiceValidationConfig | None)__post_init__()method for resolution4. Custom Service Enhancement
__init_subclass__hook toCustomBaseGattService_infoattribute (Progressive API Level 2)allow_sig_overrideparameter for intentional SIG UUID reuseUnknownServiceclass for dynamic discovery5. Class-Level Resolution
get_class_uuid()class method for registry lookupsProgressive API Levels
Level 1: Manual Info (Legacy)
Level 2: Class-Level Info (Recommended)
Level 3: Automatic SIG Resolution
Implementation Phases
Phase 1: Foundation ✅
SIGServiceResolverServiceValidationConfigServiceSpecto YAML systemis_sig_service()to UUID classPhase 2: Internal Refactoring ⏳
BaseGattService.__init__()_infoPhase 3: Custom Services ⏳
__init_subclass__toCustomBaseGattServiceUnknownServiceclassPhase 4: Testing ⏳
Phase 5: Documentation ⏳
Critical Benefits
Key Patterns to Follow
✅ DO: Use
_infoas single source of truth✅ DO: Put resolution logic in
SIGServiceResolver✅ DO: Support class-level
_infofor custom services✅ DO: Validate SIG UUID overrides in
__init_subclass__❌ DON'T: Put resolution logic in properties
❌ DON'T: Use SIG UUIDs in custom services without permission
❌ DON'T: Mix instance creation with class-level resolution
❌ DON'T: Skip
__post_init__for info resolutionTesting Requirements
Must Test:
_infoExample Migration
Before:
After:
Next Steps
docs/SERVICE_CLASS_REFACTORING_GUIDE.mdQuestions & Clar...
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.