Open-source home automation platform running on Python 3.
69
Configuration loading, validation, and management system supporting both YAML files and UI-driven configuration flows. Handles integration discovery, dependency resolution, and configuration entry lifecycle management.
Core configuration file loading and processing functionality for YAML-based Home Assistant configuration.
def load_yaml_config_file(config_path: str) -> dict:
"""Load YAML configuration file.
Args:
config_path: Path to YAML configuration file
Returns:
Configuration dictionary
Raises:
HomeAssistantError: If configuration cannot be loaded
"""
async def async_process_ha_config_upgrade(hass: HomeAssistant) -> None:
"""Process Home Assistant configuration upgrade.
Args:
hass: Home Assistant instance
"""
async def async_check_ha_config_file(hass: HomeAssistant) -> str:
"""Check Home Assistant configuration file for errors.
Args:
hass: Home Assistant instance
Returns:
Configuration check result
"""
def find_config_file(config_dir: str) -> str:
"""Find configuration file in config directory.
Args:
config_dir: Configuration directory path
Returns:
Path to configuration file
Raises:
HomeAssistantError: If configuration file not found
"""
async def async_from_config_dict(config: dict, hass: HomeAssistant,
config_dir: str = None, enable_log: bool = True,
verbose: bool = False, skip_pip: bool = False,
log_rotate_days: int = None) -> HomeAssistant:
"""Create Home Assistant instance from configuration dictionary.
Args:
config: Configuration dictionary
hass: Home Assistant instance
config_dir: Configuration directory
enable_log: Enable logging
verbose: Verbose logging
skip_pip: Skip pip installs
log_rotate_days: Log rotation days
Returns:
Configured Home Assistant instance
"""UI-driven configuration system that allows integrations to be configured through the web interface with setup flows.
class ConfigEntry:
"""Configuration entry for an integration."""
def __init__(self, version: int, domain: str, title: str, data: dict,
options: dict = None, source: str = None,
connection_class: str = None, unique_id: str = None,
entry_id: str = None, state: str = None):
"""Initialize config entry.
Args:
version: Entry version
domain: Integration domain
title: Entry title
data: Entry data
options: Entry options
source: Entry source
connection_class: Connection class
unique_id: Unique ID
entry_id: Entry ID
state: Entry state
"""
@property
def entry_id(self) -> str:
"""Return entry ID."""
@property
def version(self) -> int:
"""Return entry version."""
@property
def domain(self) -> str:
"""Return integration domain."""
@property
def title(self) -> str:
"""Return entry title."""
@property
def data(self) -> dict:
"""Return entry data."""
@property
def options(self) -> dict:
"""Return entry options."""
@property
def source(self) -> str:
"""Return entry source."""
@property
def connection_class(self) -> str:
"""Return connection class."""
@property
def unique_id(self) -> str:
"""Return unique ID."""
@property
def state(self) -> str:
"""Return entry state."""
@property
def supports_options(self) -> bool:
"""Return True if entry supports options."""
@property
def supports_unload(self) -> bool:
"""Return True if entry supports unloading."""
@property
def supports_remove_device(self) -> bool:
"""Return True if entry supports device removal."""
async def async_setup(self, hass: HomeAssistant, *, integration: Integration = None) -> bool:
"""Set up config entry.
Args:
hass: Home Assistant instance
integration: Integration instance
Returns:
True if setup successful
"""
async def async_unload(self, hass: HomeAssistant) -> bool:
"""Unload config entry.
Args:
hass: Home Assistant instance
Returns:
True if unload successful
"""
def add_update_listener(self, listener: Callable) -> Callable:
"""Add update listener.
Args:
listener: Update listener function
Returns:
Function to remove listener
"""Base class for configuration flows that guide users through integration setup via the web interface.
class ConfigFlow:
"""Base class for config flows."""
VERSION = 1
CONNECTION_CLASS = None
def __init__(self):
"""Initialize config flow."""
@property
def source(self) -> str:
"""Return flow source."""
@property
def unique_id(self) -> str:
"""Return unique ID."""
async def async_step_user(self, user_input: dict = None) -> dict:
"""Handle user step.
Args:
user_input: User input data
Returns:
Flow result
"""
async def async_step_discovery(self, discovery_info: dict) -> dict:
"""Handle discovery step.
Args:
discovery_info: Discovery information
Returns:
Flow result
"""
async def async_step_import(self, import_config: dict) -> dict:
"""Handle import step.
Args:
import_config: Import configuration
Returns:
Flow result
"""
async def async_show_form(self, *, step_id: str, data_schema: dict = None,
errors: dict = None, description_placeholders: dict = None,
last_step: bool = None) -> dict:
"""Show configuration form.
Args:
step_id: Step ID
data_schema: Voluptuous schema for form
errors: Form validation errors
description_placeholders: Description placeholders
last_step: Whether this is the last step
Returns:
Flow result
"""
async def async_create_entry(self, *, title: str, data: dict,
description: str = None,
description_placeholders: dict = None) -> dict:
"""Create config entry.
Args:
title: Entry title
data: Entry data
description: Entry description
description_placeholders: Description placeholders
Returns:
Flow result
"""
async def async_abort(self, *, reason: str,
description_placeholders: dict = None) -> dict:
"""Abort config flow.
Args:
reason: Abort reason
description_placeholders: Description placeholders
Returns:
Flow result
"""
def async_set_unique_id(self, unique_id: str) -> None:
"""Set unique ID for flow.
Args:
unique_id: Unique ID
"""
async def async_set_unique_id_and_abort_if_exists(self, unique_id: str) -> None:
"""Set unique ID and abort if already exists.
Args:
unique_id: Unique ID
"""Central manager for configuration entries that handles registration, loading, and lifecycle management.
class ConfigEntries:
"""Configuration entries manager."""
def __init__(self, hass: HomeAssistant, store: Store):
"""Initialize config entries manager.
Args:
hass: Home Assistant instance
store: Storage for config entries
"""
async def async_add(self, entry: ConfigEntry) -> ConfigEntry:
"""Add config entry.
Args:
entry: Config entry to add
Returns:
Added config entry
"""
async def async_remove(self, entry_id: str) -> dict:
"""Remove config entry.
Args:
entry_id: Entry ID to remove
Returns:
Removal result
"""
async def async_update_entry(self, entry: ConfigEntry, *, title: str = None,
data: dict = None, options: dict = None) -> ConfigEntry:
"""Update config entry.
Args:
entry: Config entry to update
title: New title
data: New data
options: New options
Returns:
Updated config entry
"""
async def async_reload(self, entry_id: str) -> bool:
"""Reload config entry.
Args:
entry_id: Entry ID to reload
Returns:
True if reload successful
"""
async def async_setup(self, entry_id: str) -> bool:
"""Set up config entry.
Args:
entry_id: Entry ID to set up
Returns:
True if setup successful
"""
async def async_unload(self, entry_id: str) -> bool:
"""Unload config entry.
Args:
entry_id: Entry ID to unload
Returns:
True if unload successful
"""
async def async_forward_entry_setup(self, entry: ConfigEntry, domain: str) -> bool:
"""Forward config entry setup to domain.
Args:
entry: Config entry
domain: Target domain
Returns:
True if setup successful
"""
async def async_forward_entry_unload(self, entry: ConfigEntry, domain: str) -> bool:
"""Forward config entry unload to domain.
Args:
entry: Config entry
domain: Target domain
Returns:
True if unload successful
"""
def get_entry(self, entry_id: str) -> ConfigEntry:
"""Get config entry by ID.
Args:
entry_id: Entry ID
Returns:
Config entry or None
"""
@property
def async_entries(self) -> list[ConfigEntry]:
"""Return all config entries."""Base class for options flows that allow users to modify integration configuration after initial setup.
class OptionsFlow:
"""Base class for options flows."""
def __init__(self, config_entry: ConfigEntry):
"""Initialize options flow.
Args:
config_entry: Config entry for options
"""
async def async_step_init(self, user_input: dict = None) -> dict:
"""Handle options flow initialization.
Args:
user_input: User input data
Returns:
Flow result
"""
async def async_create_entry(self, *, title: str = None, data: dict) -> dict:
"""Create options entry.
Args:
title: Entry title
data: Options data
Returns:
Flow result
"""# Config entry states
ENTRY_STATE_LOADED = "loaded"
ENTRY_STATE_SETUP_ERROR = "setup_error"
ENTRY_STATE_SETUP_RETRY = "setup_retry"
ENTRY_STATE_SETUP_IN_PROGRESS = "setup_in_progress"
ENTRY_STATE_NOT_LOADED = "not_loaded"
ENTRY_STATE_FAILED_UNLOAD = "failed_unload"
# Config sources
SOURCE_USER = "user"
SOURCE_DISCOVERY = "discovery"
SOURCE_IMPORT = "import"
SOURCE_SYSTEM = "system"
SOURCE_ZEROCONF = "zeroconf"
SOURCE_SSDP = "ssdp"
SOURCE_HOMEKIT = "homekit"
# Connection classes
CONN_CLASS_CLOUD_POLLING = "cloud_polling"
CONN_CLASS_CLOUD_PUSH = "cloud_push"
CONN_CLASS_LOCAL_POLLING = "local_polling"
CONN_CLASS_LOCAL_PUSH = "local_push"
CONN_CLASS_ASSUMED = "assumed"
# Flow result types
RESULT_TYPE_FORM = "form"
RESULT_TYPE_CREATE_ENTRY = "create_entry"
RESULT_TYPE_ABORT = "abort"
RESULT_TYPE_EXTERNAL_STEP = "external"
RESULT_TYPE_EXTERNAL_STEP_DONE = "external_done"
RESULT_TYPE_SHOW_PROGRESS = "progress"
RESULT_TYPE_SHOW_PROGRESS_DONE = "progress_done"
RESULT_TYPE_MENU = "menu"from typing import Any, Callable, Dict, List, Optional, Union
from enum import Enum
# Config entry types
ConfigType = Dict[str, Any]
ConfigEntryDataType = Dict[str, Any]
ConfigEntryOptionsType = Dict[str, Any]
# Flow types
FlowResultType = Dict[str, Any]
FlowHandlerType = Callable[..., FlowResultType]
UserInputType = Dict[str, Any]
# Schema types
import voluptuous as vol
SchemaType = vol.Schema
ValidatorType = Callable[[Any], Any]Install with Tessl CLI
npx tessl i tessl/pypi-homeassistantdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10