developers.home-assistant/website/versioned_docs/version-0.72/config_entries_index.md

2.4 KiB

title sidebar_label id original_id
Config Entries Introduction version-0.72-config_entries_index config_entries_index

Config Entries are configuration data that are persistently stored by Home Assistant. A config entry is created by a user via the UI. The UI flow is powered by a config flow handler as defined by the component.

Setting up an entry

During startup, Home Assistant first call the normal component setup, and then call the method async_setup_entry(hass, entry) for each entry. If a new Config Entry is created at runtime, Home Assistant will also call async_setup_entry(hass, entry) (example).

For platforms

If a component includes platforms, it will need to forward the Config Entry to the platform. This can be done by calling the forward function on the config entry manager (example):

# Use `hass.async_add_job` to avoid a circular dependency between the platform and the component
hass.async_add_job(hass.config_entries.async_forward_entry_setup(config_entry, 'light'))

For a platform to support config entries, it will need to add a setup entry method (example):

async def async_setup_entry(hass, config_entry, async_add_devices):

Unloading entries

Components can optionally support unloading a config entry. When unloading an entry, the component needs to clean up all entities, unsubscribe any event listener and close all connections. To implement this, add async_unload_entry(hass, entry) to your component (example).

Platforms will not need to add any logic for unloading a config entry. The entity component will take care of this. If you need to clean up resources used for an entity, implement the async_will_remove_from_hass method on the Entity (example).