Common Patterns¶
This directory contains proven implementation patterns for common adapter scenarios.
Each pattern is documented in a separate file for easy navigation and reference.
Pattern Index¶
Core Patterns¶
| Pattern | Description | File |
|---|---|---|
| 1. Access Synchronization | Offline access control with address allocation | 01-access-synchronization.md |
| 2. Event Translation | Device events → PQ events mapping | 02-event-translation.md |
| 3. Connection Management | IDeviceConnection, retry, monitoring | 03-connection-management.md |
| 4. Command Handling | Typed commands, signature-based detection | 04-command-handling.md |
Advanced Patterns¶
| Pattern | Description | File |
|---|---|---|
| 5. Custom Functions | Device-specific capabilities | 05-custom-functions.md |
| 6. Shared Resources | SDK processes, connection pools | 06-shared-resources.md |
| 7. Address Resolution | Map protocol addresses to Things, IThingQuery for hierarchy queries | 07-address-resolution.md |
| 8. Biometric Enrollment | Template capture and storage | 08-biometric-enrollment.md |
Best Practices¶
| Pattern | Description | File |
|---|---|---|
| 9. Event Publishing | Function methods vs PqEvent classes | 09-event-publishing.md |
| 10. Error Handling | Retry, circuit breaker, degradation | 10-error-handling.md |
| 11. Testing Without Hardware | Mock SDK for development | 11-testing-without-hardware.md |
| 12. Status Polling | Poll device state with StatusBatch | 12-status-polling.md |
| 13. Optimistic Commands | Instant UI feedback with async device confirmation | 13-optimistic-commands.md |
| 14. Device Configuration Import | Root-driven discovery and import of child subtree into PQ | 14-device-config-import.md |
| 15. Enrollment Process | Shared process for card and biometric enrollment | 15-enrollment-process.md |
| 16. Video Event Mapping | PQ video event taxonomy, stale analytics, NVR vs channel routing | 16-video-events.md |
| 17. Event Replay Deduplication | Replay cursor for at-least-once vendor event streams | 17-event-replay-deduplication.md |
| 18. Multi-Step Protocol Sequences | Exclusive request→ACK→repeat drains via channel sequence policies | 18-protocol-sequences.md |
| 19. Stream Registration & Reconciliation | CCTV alias register/teardown lifecycle, RTSP-URL strategy, server-owned idle sweep | 19-stream-registration.md |
Guides¶
| Guide | Description | File |
|---|---|---|
| Event Mapping | Systematic vendor event -> PQ event mapping process | event-mapping-guide.md |
Quick Reference¶
Most Common Patterns¶
If you're implementing a typical access control adapter, you'll need:
- Pattern 4: Command Handling - Handle open/lock commands
- Pattern 2: Event Translation - Translate access events
- Pattern 7: Address Resolution - Route events to correct Things
- Pattern 3: Connection Management - Connect to device
- Pattern 9: Event Publishing - Publish events correctly
Optional Patterns¶
Depending on device capabilities:
- Offline access? → Pattern 1: Access Synchronization
- Biometrics? → Pattern 8: Biometric Enrollment
- Any enrollment flow? → Pattern 15: Enrollment Process
- Custom protocol (gRPC/serial)? → Pattern 6: Shared Resources
- Device-specific features? → Pattern 5: Custom Functions
- Poll-only devices / stale state? → Pattern 12: Status Polling
- Responsive command UI? → Pattern 13: Optimistic Commands
- Device exposes its own topology? → Pattern 14: Device Configuration Import
- CCTV / video surveillance? → Pattern 16: Video Event Mapping + CCTV Archetype
- Mandatory ACK + repeat-until-done exchange (log/history drain)? → Pattern 18: Multi-Step Protocol Sequences
Development Patterns¶
Always useful:
- Pattern 11: Testing - Mock SDK for fast iteration
- Pattern 10: Error Handling - Robust error handling
- Pattern 12: Status Polling - Fill unknown states via polling
Pattern Dependencies¶
Some patterns build on others:
Pattern 2 (Event Translation)
↓ requires
Pattern 7 (Address Resolution) ← find Things by protocol address
↓ uses
Pattern 9 (Event Publishing) ← publish events from resolved Things
Pattern 1 (Access Sync)
↓ uses
Pattern 7 (Address Resolution) ← allocate protocol addresses
Pattern 3 (Connection Management)
↓ uses
Pattern 10 (Error Handling)
Pattern 13 (Optimistic Commands)
↓ extends
Pattern 4 (Command Handling) ← adds optimistic UI layer
Pattern 14 (Device Configuration Import)
↓ extends
Pattern 4 (Command Handling) ← adds explicit root import command surface
↓ uses
Pattern 3 (Connection Management) ← temporary root connection for discovery
How to Use This Guide¶
For First-Time Adapter Developers¶
- Start with 01-step-by-step.md (not this file)
- Come back here when you need specific patterns
- Read patterns in order: 4 → 2 → 3 → 9 (most common)
- Add other patterns as needed
For Experienced Developers¶
- Use as quick reference
- Jump directly to pattern you need
- Copy code examples and adapt to your SDK
For Troubleshooting¶
- Check 03-troubleshooting.md first
- Then consult relevant pattern for best practices
Contributing Patterns¶
Found a new pattern worth documenting?
- Create new file:
patterns/XX-pattern-name.md - Follow existing structure:
- Clear use case
- Code examples
- Best practices
- See Also links
- Add to this index
- Update README.md
See Also¶
- 00-overview.md - Architecture and concepts
- 01-step-by-step.md - Implementation guide
- 03-troubleshooting.md - Debug guide
Note: These patterns cover most adapter implementation scenarios. When a scenario is still unclear, extend this documentation set with a new generalized pattern or archetype rather than relying on external adapter implementations.