$ show kormax/apple-home-key-reader
This repository implements an Apple Home Key Reader application that enables NFC-based authentication for Apple HomeKit smart locks. The system acts as a bridge between NFC-enabled devices (iPhones/Apple Watches with Home Keys) and HomeKit accessory control, allowing users to unlock locks by tapping their devices on an NFC reader. The architecture follows a modular design with clear separation: main.py coordinates initialization, accessory.py handles HomeKit Accessory Protocol interfaces, service.py implements core NFC authentication logic, homekey.py manages Apple-specific NFC protocols, and repository.py handles persistent state management. The application relies on external dependencies including pyhap for HomeKit, nfcpy for NFC communication, and cryptography for security operations.
The LLM identified 3 files worth highlighting for reuse:
Implements a robust BER-TLV (Basic Encoding Rules Tag-Length-Value) parser and encoder used throughout the codebase for processing NFC protocol data. Handles constructed and primitive TLVs, long format lengths, and provides array unpacking functionality. Demonstrates non-obvious skill in correctly implementing a complex standard with proper error handling. The module is highly isolated (only depends on util.generic helpers) and could be extracted for use in any application needing TLV parsing with minimal modification.
Provides generic data serialization utilities including packing/unpacking of various data types (integers, bytes, strings, enums) and base64 encoding/decoding. Used extensively throughout the codebase for message serialization in NFC and HAP communications. The implementation correctly handles edge cases and different data types with zero external dependencies beyond the standard library. This component solves a common problem in protocol implementation and could be easily reused in other projects requiring binary data serialization.
Implements a reusable threading pattern for background services with automatic exception handling and recovery logic. The runner function provides continuous execution with configurable delay and exception recovery, used in service.py for the main NFC polling loop. Demonstrates proper patterns for long-running services including exception logging and configurable retry delays. The module has no external dependencies and could be extracted for use in any application requiring resilient background processing.