-
Notifications
You must be signed in to change notification settings - Fork 11
Development Guide
This guide covers development topics for Lock Code Manager, including how to add support for new lock integrations.
Lock Code Manager uses a provider pattern to abstract lock-specific implementations.
Each supported lock integration (Z-Wave JS, Virtual, etc.) has a corresponding provider
class that inherits from BaseLock.
┌─────────────────────────────────────────────────────────────────────────────┐
│ Lock Code Manager │
├─────────────────────────────────────────────────────────────────────────────┤
│ Config Entry │
│ ├── Entities (switches, sensors, text inputs) │
│ └── Provider instances (one per configured lock) │
│ └── LockUsercodeUpdateCoordinator │
│ └── Manages usercode state and entity updates │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ inherits from
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ BaseLock │
├─────────────────────────────────────────────────────────────────────────────┤
│ Abstract base class defining the provider interface │
│ • Data fetching (poll, push, drift detection) │
│ • Usercode operations (get, set, clear) │
│ • Connection management │
│ • Event handling │
└─────────────────────────────────────────────────────────────────────────────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ ZWaveJS │ │ Virtual │ │ YourLock │
│ Lock │ │ Lock │ │ Provider │
└───────────┘ └───────────┘ └───────────┘
The provider is responsible for:
- Reading usercodes from the lock device
- Writing usercodes to the lock device
- Monitoring connection state to the lock
- Subscribing to events for real-time updates (optional)
- Firing events when codes are used
See Provider-State-Management for details on update modes.
The coordinator manages the state of usercodes and notifies entities when data changes. It:
- Calls the provider's
get_usercodes()method to fetch current state - Receives push updates from providers that support real-time events
- Runs periodic drift detection to catch out-of-band changes
- Handles connection state and retry logic
Lock Code Manager creates entities for each configured slot:
| Entity Type | Purpose |
|---|---|
switch |
Enable/disable the code slot |
text |
Name for the code slot |
text |
PIN value for the code slot |
binary_sensor |
Whether the code is active (enabled + conditions met) |
binary_sensor |
Per-lock sync status |
sensor |
Current code on the lock |
number |
Number of uses remaining (if configured) |
event |
PIN usage events |
- Adding-a-Provider - Step-by-step tutorial on adding support for a new lock integration
- Provider-State-Management - Details on poll vs push modes, drift detection, and the update lifecycle
custom_components/lock_code_manager/
├── providers/
│ ├── __init__.py # Provider registry
│ ├── _base.py # BaseLock abstract class
│ ├── const.py # Provider constants
│ ├── virtual.py # Virtual lock provider
│ └── zwave_js.py # Z-Wave JS provider
├── coordinator.py # LockUsercodeUpdateCoordinator
├── exceptions.py # LCM-specific exceptions
└── ...
This project uses a VS Code Dev Container for development, which provides a consistent development environment with all necessary dependencies pre-installed. The container includes a debug-enabled Home Assistant instance with Lock Code Manager integration for testing and development purposes.
- Clone the repository to your local machine
- Open the project in Visual Studio Code
- When prompted, click "Reopen in Container" or select
Dev Containers: Open in Containerfrom the Command Palette (F1) - Wait for the container to build and initialize (this may take a few minutes on first run)
- Once ready, open the Run and Debug panel (Ctrl+Shift+D) and select "Debug Home Assistant"
- Complete the initial Home Assistant setup wizard
- Navigate to Home Assistant Settings > Devices & services
- Add the Virtual Components integration:
- Click "Add Integration"
- Search for and select "Virtual Components"
- Accept the default settings when prompted
- Add the Lock Code Manager integration:
- Click "Add Integration" again
- Search for and select "Lock Code Manager"
- Enter a configuration name
- Select the "Test Lock" from the Virtual Components
- Click "Next" to proceed to code slot configuration
Providers should include tests for:
-
Usercode operations:
set_usercode,clear_usercode,get_usercodes -
Connection handling:
is_connection_up, disconnection recovery - Push updates (if supported): Event subscription and unsubscription
- Error handling: Proper exception types raised
See the Adding-a-Provider guide for testing examples.