Overview
A config entry consists of:- Config Flow: Handles the setup process through the UI
- Config Entry: Stores the configuration data
- Options Flow: Allows users to modify settings after setup
Config Entry Basics
The ConfigEntry Object
AConfigEntry object stores configuration data and has several key properties:
Config Entry States
Config entries have different states:Implementing a Config Flow
The config flow is the UI wizard that guides users through setting up your integration.Basic Config Flow
config_flow.py
Config Flow Steps
Each step in the config flow is a method namedasync_step_<step_name>. Common steps include:
async_step_user: Initial user-initiated setupasync_step_import: Import from YAML configurationasync_step_discovery: Handle discovered devicesasync_step_zeroconf: Handle Zeroconf/mDNS discoveryasync_step_bluetooth: Handle Bluetooth discovery
Multi-Step Config Flows
For complex setups, you can chain multiple steps:Discovery Flows
Integrations can be automatically discovered through various methods:Zeroconf Discovery
manifest.json
Bluetooth Discovery
Options Flow
Options flows allow users to modify integration settings after initial setup:Handling Config Entry Updates
You can listen for config entry changes:__init__.py
Reauthentication Flow
If credentials expire, trigger a reauth flow:Reconfigure Flow
Allow users to reconfigure an existing entry:Translations
Provide translations for your config flow instrings.json:
strings.json
Best Practices
Use Unique IDs
Always set a unique ID to prevent duplicate entries:Validate Early
Validate user input as soon as possible to provide quick feedback.Handle Errors Gracefully
Provide clear error messages for common failure scenarios.Update Existing Entries
When rediscovering a device, update the existing entry:Store Minimal Data
Only store essential configuration indata. Use runtime_data for temporary data.