Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.entity_component.EntityComponent Class Reference
Inheritance diagram for homeassistant.helpers.entity_component.EntityComponent:
[legend]
Collaboration diagram for homeassistant.helpers.entity_component.EntityComponent:
[legend]

Public Member Functions

None __init__ (self, logging.Logger logger, str domain, HomeAssistant hass, timedelta scan_interval=DEFAULT_SCAN_INTERVAL)
 
list[_EntityTasync_extract_from_service (self, ServiceCall service_call, bool expand_group=True)
 
ConfigType|None async_prepare_reload (self, *bool skip_reset=False)
 
None async_register_entity_service (self, str name, VolDictType|VolSchemaType|None schema, str|Callable[..., Any] func, list[int]|None required_features=None, SupportsResponse supports_response=SupportsResponse.NONE)
 
None async_register_legacy_entity_service (self, str name, VolDictType|VolSchemaType schema, str|Callable[..., Any] func, list[int]|None required_features=None, SupportsResponse supports_response=SupportsResponse.NONE)
 
None async_remove_entity (self, str entity_id)
 
None async_setup (self, ConfigType config)
 
bool async_setup_entry (self, ConfigEntry config_entry)
 
None async_setup_platform (self, str platform_type, ConfigType platform_config, DiscoveryInfoType|None discovery_info=None)
 
bool async_unload_entry (self, ConfigEntry config_entry)
 
Iterable[_EntityTentities (self)
 
_EntityT|None get_entity (self, str entity_id)
 
None register_shutdown (self)
 
None setup (self, ConfigType config)
 

Public Attributes

 add_entities
 
 async_add_entities
 
 config
 
 domain
 
 hass
 
 logger
 
 scan_interval
 

Private Member Functions

None _async_component_platform_discovered (self, str platform, dict[str, Any]|None info)
 
EntityPlatform _async_init_entity_platform (self, str platform_type, ModuleType|None platform, timedelta|None scan_interval=None, str|None entity_namespace=None)
 
None _async_reset (self)
 
None _async_shutdown (self, Event event)
 

Private Attributes

 _platforms
 

Detailed Description

The EntityComponent manages platforms that manage entities.

An example of an entity component is 'light', which manages platforms such
as 'hue.light'.

This class has the following responsibilities:
 - Process the configuration and set up a platform based component, for example light.
 - Manage the platforms and their entities.
 - Help extract the entities from a service call.
 - Listen for discovery events for platforms related to the domain.

Definition at line 67 of file entity_component.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.helpers.entity_component.EntityComponent.__init__ (   self,
logging.Logger  logger,
str  domain,
HomeAssistant  hass,
timedelta   scan_interval = DEFAULT_SCAN_INTERVAL 
)
Initialize an entity component.

Definition at line 80 of file entity_component.py.

Member Function Documentation

◆ _async_component_platform_discovered()

None homeassistant.helpers.entity_component.EntityComponent._async_component_platform_discovered (   self,
str  platform,
dict[str, Any] | None   info 
)
private
Handle the loading of a platform.

Definition at line 162 of file entity_component.py.

◆ _async_init_entity_platform()

EntityPlatform homeassistant.helpers.entity_component.EntityComponent._async_init_entity_platform (   self,
str  platform_type,
ModuleType | None  platform,
timedelta | None   scan_interval = None,
str | None   entity_namespace = None 
)
private
Initialize an entity platform.

Definition at line 372 of file entity_component.py.

◆ _async_reset()

None homeassistant.helpers.entity_component.EntityComponent._async_reset (   self)
private
Remove entities and reset the entity component to initial values.

This method must be run in the event loop.

Definition at line 313 of file entity_component.py.

◆ _async_shutdown()

None homeassistant.helpers.entity_component.EntityComponent._async_shutdown (   self,
Event  event 
)
private
Call when Home Assistant is stopping.

Definition at line 396 of file entity_component.py.

◆ async_extract_from_service()

list[_EntityT] homeassistant.helpers.entity_component.EntityComponent.async_extract_from_service (   self,
ServiceCall  service_call,
bool   expand_group = True 
)
Extract all known and available entities from a service call.

Will return an empty list if entities specified but unknown.

This method must be run in the event loop.

Definition at line 209 of file entity_component.py.

◆ async_prepare_reload()

ConfigType | None homeassistant.helpers.entity_component.EntityComponent.async_prepare_reload (   self,
*bool   skip_reset = False 
)
Prepare reloading this entity component.

This method must be run in the event loop.

Definition at line 344 of file entity_component.py.

◆ async_register_entity_service()

None homeassistant.helpers.entity_component.EntityComponent.async_register_entity_service (   self,
str  name,
VolDictType | VolSchemaType | None  schema,
str | Callable[..., Any]  func,
list[int] | None   required_features = None,
SupportsResponse   supports_response = SupportsResponse.NONE 
)
Register an entity service.

Definition at line 260 of file entity_component.py.

◆ async_register_legacy_entity_service()

None homeassistant.helpers.entity_component.EntityComponent.async_register_legacy_entity_service (   self,
str  name,
VolDictType | VolSchemaType  schema,
str | Callable[..., Any]  func,
list[int] | None   required_features = None,
SupportsResponse   supports_response = SupportsResponse.NONE 
)
Register an entity service with a legacy response format.

Definition at line 223 of file entity_component.py.

◆ async_remove_entity()

None homeassistant.helpers.entity_component.EntityComponent.async_remove_entity (   self,
str  entity_id 
)
Remove an entity managed by one of the platforms.

Definition at line 332 of file entity_component.py.

◆ async_setup()

None homeassistant.helpers.entity_component.EntityComponent.async_setup (   self,
ConfigType  config 
)
Set up a full entity component.

Loads the platforms from the config and will listen for supported
discovered platforms.

This method must be run in the event loop.

Definition at line 135 of file entity_component.py.

◆ async_setup_entry()

bool homeassistant.helpers.entity_component.EntityComponent.async_setup_entry (   self,
ConfigEntry  config_entry 
)
Set up a config entry.

Definition at line 168 of file entity_component.py.

◆ async_setup_platform()

None homeassistant.helpers.entity_component.EntityComponent.async_setup_platform (   self,
str  platform_type,
ConfigType  platform_config,
DiscoveryInfoType | None   discovery_info = None 
)
Set up a platform for this component.

Definition at line 281 of file entity_component.py.

◆ async_unload_entry()

bool homeassistant.helpers.entity_component.EntityComponent.async_unload_entry (   self,
ConfigEntry  config_entry 
)
Unload a config entry.

Definition at line 199 of file entity_component.py.

◆ entities()

Iterable[_EntityT] homeassistant.helpers.entity_component.EntityComponent.entities (   self)
Return an iterable that returns all entities.

As the underlying dicts may change when async context is lost,
callers that iterate over this asynchronously should make a copy
using list() before iterating.

Definition at line 105 of file entity_component.py.

◆ get_entity()

_EntityT | None homeassistant.helpers.entity_component.EntityComponent.get_entity (   self,
str  entity_id 
)
Get an entity.

Definition at line 114 of file entity_component.py.

◆ register_shutdown()

None homeassistant.helpers.entity_component.EntityComponent.register_shutdown (   self)
Register shutdown on Home Assistant STOP event.

Note: this is only required if the integration never calls
`setup` or `async_setup`.

Definition at line 118 of file entity_component.py.

◆ setup()

None homeassistant.helpers.entity_component.EntityComponent.setup (   self,
ConfigType  config 
)
Set up a full entity component.

This doesn't block the executor to protect from deadlocks.

Definition at line 126 of file entity_component.py.

Member Data Documentation

◆ _platforms

homeassistant.helpers.entity_component.EntityComponent._platforms
private

Definition at line 329 of file entity_component.py.

◆ add_entities

homeassistant.helpers.entity_component.EntityComponent.add_entities

Definition at line 100 of file entity_component.py.

◆ async_add_entities

homeassistant.helpers.entity_component.EntityComponent.async_add_entities

Definition at line 99 of file entity_component.py.

◆ config

homeassistant.helpers.entity_component.EntityComponent.config

Definition at line 145 of file entity_component.py.

◆ domain

homeassistant.helpers.entity_component.EntityComponent.domain

Definition at line 90 of file entity_component.py.

◆ hass

homeassistant.helpers.entity_component.EntityComponent.hass

Definition at line 89 of file entity_component.py.

◆ logger

homeassistant.helpers.entity_component.EntityComponent.logger

Definition at line 88 of file entity_component.py.

◆ scan_interval

homeassistant.helpers.entity_component.EntityComponent.scan_interval

Definition at line 91 of file entity_component.py.


The documentation for this class was generated from the following file: