Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.entity_platform.EntityPlatform Class Reference

Public Member Functions

None __init__ (self, *HomeAssistant hass, Logger logger, str domain, str platform_name, EntityPlatformModule|None platform, timedelta scan_interval, str|None entity_namespace)
 
str __repr__ (self)
 
None add_entities (self, Iterable[Entity] new_entities, bool update_before_add=False)
 
None async_add_entities (self, Iterable[Entity] new_entities, bool update_before_add=False)
 
None async_cancel_retry_setup (self)
 
None async_destroy (self)
 
list[Entityasync_extract_from_service (self, ServiceCall service_call, bool expand_group=True)
 
None async_load_translations (self)
 
None async_prepare (self)
 
None async_register_entity_service (self, str name, VolDictType|VolSchemaType|None schema, str|Callable[..., Any] func, Iterable[int]|None required_features=None, SupportsResponse supports_response=SupportsResponse.NONE)
 
None async_remove_entity (self, str entity_id)
 
None async_reset (self)
 
None async_setup (self, ConfigType platform_config, DiscoveryInfoType|None discovery_info=None)
 
bool async_setup_entry (self, config_entries.ConfigEntry config_entry)
 
None async_shutdown (self)
 
None async_unsub_polling (self)
 

Public Attributes

 component_translations
 
 config_entry
 
 default_language_platform_translations
 
 domain
 
 domain_entities
 
 domain_platform_entities
 
 entity_namespace
 
 hass
 
 logger
 
 object_id_component_translations
 
 object_id_platform_translations
 
 parallel_updates
 
 parallel_updates_created
 
 platform
 
 platform_name
 
 platform_translations
 
 scan_interval
 
 scan_interval_seconds
 

Static Public Attributes

 default
 

Private Member Functions

None _async_add_and_update_entities (self, list[Coroutine[Any, Any, None]] coros, list[Entity] entities, float timeout)
 
None _async_add_entities (self, list[Coroutine[Any, Any, None]] coros, list[Entity] entities, float timeout)
 
None _async_add_entity (self, Entity entity, bool update_before_add, EntityRegistry entity_registry)
 
dict[str, str] _async_get_translations (self, str language, str category, str integration)
 
None _async_handle_interval_callback (self)
 
None _async_schedule_add_entities (self, Iterable[Entity] new_entities, bool update_before_add=False)
 
None _async_schedule_add_entities_for_entry (self, Iterable[Entity] new_entities, bool update_before_add=False)
 
bool _async_setup_platform (self, Callable[[], Awaitable[None]] async_create_setup_awaitable, int tries=0)
 
None _async_update_entity_states (self)
 
tuple[bool, bool] _entity_id_already_exists (self, str entity_id)
 
asyncio.Semaphore|None _get_parallel_updates_semaphore (self, bool entity_has_sync_update)
 
None _schedule_add_entities (self, Iterable[Entity] new_entities, bool update_before_add=False)
 

Private Attributes

 _async_cancel_retry_setup
 
 _async_polling_timer
 
 _process_updates
 
 _setup_complete
 
 _update_in_sequence
 

Detailed Description

Manage the entities for a single platform.

An example of an entity platform is 'hue.light', which is managed by
the entity component 'light'.

Definition at line 113 of file entity_platform.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.helpers.entity_platform.EntityPlatform.__init__ (   self,
*HomeAssistant  hass,
Logger  logger,
str  domain,
str  platform_name,
EntityPlatformModule | None  platform,
timedelta  scan_interval,
str | None  entity_namespace 
)
Manage the entities for a single platform.

An example of an entity platform is 'hue.light', which is managed by
the entity component 'light'.
Initialize the entity platform.

Definition at line 120 of file entity_platform.py.

Member Function Documentation

◆ __repr__()

str homeassistant.helpers.entity_platform.EntityPlatform.__repr__ (   self)
Represent an EntityPlatform.

Definition at line 182 of file entity_platform.py.

◆ _async_add_and_update_entities()

None homeassistant.helpers.entity_platform.EntityPlatform._async_add_and_update_entities (   self,
list[Coroutine[Any, Any, None]]  coros,
list[Entity entities,
float  timeout 
)
private
Add entities for a single platform and update them.

Since we are updating the entities before adding them, we need to
schedule the coroutines as tasks so we can await them in the event
loop. This is because the update is likely to yield control to the
event loop and will finish faster if we run them concurrently.

Definition at line 549 of file entity_platform.py.

◆ _async_add_entities()

None homeassistant.helpers.entity_platform.EntityPlatform._async_add_entities (   self,
list[Coroutine[Any, Any, None]]  coros,
list[Entity entities,
float  timeout 
)
private
Add entities for a single platform without updating.

In this case we are not updating the entities before adding them
which means it is likely that we will not have to yield control
to the event loop so we can await the coros directly without
scheduling them as tasks.

Definition at line 591 of file entity_platform.py.

◆ _async_add_entity()

None homeassistant.helpers.entity_platform.EntityPlatform._async_add_entity (   self,
Entity  entity,
bool  update_before_add,
EntityRegistry  entity_registry 
)
private
Add an entity to the platform.

Definition at line 717 of file entity_platform.py.

◆ _async_get_translations()

dict[str, str] homeassistant.helpers.entity_platform.EntityPlatform._async_get_translations (   self,
str  language,
str  category,
str   integration 
)
private
Get translations for a language, category, and integration.

Definition at line 443 of file entity_platform.py.

◆ _async_handle_interval_callback()

None homeassistant.helpers.entity_platform.EntityPlatform._async_handle_interval_callback (   self)
private
Update all the entity states in a single platform.

Definition at line 681 of file entity_platform.py.

◆ _async_schedule_add_entities()

None homeassistant.helpers.entity_platform.EntityPlatform._async_schedule_add_entities (   self,
Iterable[Entity new_entities,
bool   update_before_add = False 
)
private
Schedule adding entities for a single platform async.

Definition at line 504 of file entity_platform.py.

◆ _async_schedule_add_entities_for_entry()

None homeassistant.helpers.entity_platform.EntityPlatform._async_schedule_add_entities_for_entry (   self,
Iterable[Entity new_entities,
bool   update_before_add = False 
)
private
Schedule adding entities for a single platform async and track the task.

Definition at line 518 of file entity_platform.py.

◆ _async_setup_platform()

bool homeassistant.helpers.entity_platform.EntityPlatform._async_setup_platform (   self,
Callable[[], Awaitable[None]]  async_create_setup_awaitable,
int   tries = 0 
)
private
Set up a platform via config file or config entry.

async_create_setup_awaitable creates an awaitable that sets up platform.

Definition at line 335 of file entity_platform.py.

◆ _async_update_entity_states()

None homeassistant.helpers.entity_platform.EntityPlatform._async_update_entity_states (   self)
private
Update the states of all the polling entities.

To protect from flooding the executor, we will update async entities
in parallel and other entities sequential.

This method must be run in the event loop.

Definition at line 1027 of file entity_platform.py.

◆ _entity_id_already_exists()

tuple[bool, bool] homeassistant.helpers.entity_platform.EntityPlatform._entity_id_already_exists (   self,
str  entity_id 
)
private
Check if an entity_id already exists.

Returns a tuple [already_exists, restored]

Definition at line 701 of file entity_platform.py.

◆ _get_parallel_updates_semaphore()

asyncio.Semaphore | None homeassistant.helpers.entity_platform.EntityPlatform._get_parallel_updates_semaphore (   self,
bool   entity_has_sync_update 
)
private
Get or create a semaphore for parallel updates.

Semaphore will be created on demand because we base it off if update
method is async or not.

- If parallel updates is set to 0, we skip the semaphore.
- If parallel updates is set to a number, we initialize the semaphore
  to that number.

The default value for parallel requests is decided based on the first
entity of the platform which is added to Home Assistant. It's 1 if the
entity implements the update method, else it's 0.

Definition at line 192 of file entity_platform.py.

◆ _schedule_add_entities()

None homeassistant.helpers.entity_platform.EntityPlatform._schedule_add_entities (   self,
Iterable[Entity new_entities,
bool   update_before_add = False 
)
private
Schedule adding entities for a single platform, synchronously.

Definition at line 493 of file entity_platform.py.

◆ add_entities()

None homeassistant.helpers.entity_platform.EntityPlatform.add_entities (   self,
Iterable[Entity new_entities,
bool   update_before_add = False 
)
Add entities for a single platform.

Definition at line 533 of file entity_platform.py.

◆ async_add_entities()

None homeassistant.helpers.entity_platform.EntityPlatform.async_add_entities (   self,
Iterable[Entity new_entities,
bool   update_before_add = False 
)
Add entities for a single platform async.

This method must be run in the event loop.

Definition at line 626 of file entity_platform.py.

◆ async_cancel_retry_setup()

None homeassistant.helpers.entity_platform.EntityPlatform.async_cancel_retry_setup (   self)
Cancel retry setup.

Definition at line 312 of file entity_platform.py.

◆ async_destroy()

None homeassistant.helpers.entity_platform.EntityPlatform.async_destroy (   self)
Destroy an entity platform.

Call before discarding the object.

Definition at line 968 of file entity_platform.py.

◆ async_extract_from_service()

list[Entity] homeassistant.helpers.entity_platform.EntityPlatform.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 986 of file entity_platform.py.

◆ async_load_translations()

None homeassistant.helpers.entity_platform.EntityPlatform.async_load_translations (   self)
Load translations.

Definition at line 459 of file entity_platform.py.

◆ async_prepare()

None homeassistant.helpers.entity_platform.EntityPlatform.async_prepare (   self)
Register the entity platform in DATA_ENTITY_PLATFORM.

Definition at line 962 of file entity_platform.py.

◆ async_register_entity_service()

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

Services will automatically be shared by all platforms of the same domain.

Definition at line 1000 of file entity_platform.py.

◆ async_remove_entity()

None homeassistant.helpers.entity_platform.EntityPlatform.async_remove_entity (   self,
str  entity_id 
)
Remove entity id from platform.

Definition at line 976 of file entity_platform.py.

◆ async_reset()

None homeassistant.helpers.entity_platform.EntityPlatform.async_reset (   self)
Remove all entities and reset data.

This method must be run in the event loop.

Definition at line 929 of file entity_platform.py.

◆ async_setup()

None homeassistant.helpers.entity_platform.EntityPlatform.async_setup (   self,
ConfigType  platform_config,
DiscoveryInfoType | None   discovery_info = None 
)
Set up the platform from a config file.

Definition at line 227 of file entity_platform.py.

◆ async_setup_entry()

bool homeassistant.helpers.entity_platform.EntityPlatform.async_setup_entry (   self,
config_entries.ConfigEntry  config_entry 
)
Set up the platform from a config entry.

Definition at line 318 of file entity_platform.py.

◆ async_shutdown()

None homeassistant.helpers.entity_platform.EntityPlatform.async_shutdown (   self)
Call when Home Assistant is stopping.

Definition at line 306 of file entity_platform.py.

◆ async_unsub_polling()

None homeassistant.helpers.entity_platform.EntityPlatform.async_unsub_polling (   self)
Stop polling.

Definition at line 955 of file entity_platform.py.

Member Data Documentation

◆ _async_cancel_retry_setup

homeassistant.helpers.entity_platform.EntityPlatform._async_cancel_retry_setup
private

Definition at line 316 of file entity_platform.py.

◆ _async_polling_timer

homeassistant.helpers.entity_platform.EntityPlatform._async_polling_timer
private

Definition at line 675 of file entity_platform.py.

◆ _process_updates

homeassistant.helpers.entity_platform.EntityPlatform._process_updates
private

Definition at line 1036 of file entity_platform.py.

◆ _setup_complete

homeassistant.helpers.entity_platform.EntityPlatform._setup_complete
private

Definition at line 151 of file entity_platform.py.

◆ _update_in_sequence

homeassistant.helpers.entity_platform.EntityPlatform._update_in_sequence
private

Definition at line 223 of file entity_platform.py.

◆ component_translations

homeassistant.helpers.entity_platform.EntityPlatform.component_translations

Definition at line 468 of file entity_platform.py.

◆ config_entry

homeassistant.helpers.entity_platform.EntityPlatform.config_entry

Definition at line 321 of file entity_platform.py.

◆ default

homeassistant.helpers.entity_platform.EntityPlatform.default
static

Definition at line 1069 of file entity_platform.py.

◆ default_language_platform_translations

homeassistant.helpers.entity_platform.EntityPlatform.default_language_platform_translations

Definition at line 485 of file entity_platform.py.

◆ domain

homeassistant.helpers.entity_platform.EntityPlatform.domain

Definition at line 134 of file entity_platform.py.

◆ domain_entities

homeassistant.helpers.entity_platform.EntityPlatform.domain_entities

Definition at line 169 of file entity_platform.py.

◆ domain_platform_entities

homeassistant.helpers.entity_platform.EntityPlatform.domain_platform_entities

Definition at line 178 of file entity_platform.py.

◆ entity_namespace

homeassistant.helpers.entity_platform.EntityPlatform.entity_namespace

Definition at line 139 of file entity_platform.py.

◆ hass

homeassistant.helpers.entity_platform.EntityPlatform.hass

Definition at line 132 of file entity_platform.py.

◆ logger

homeassistant.helpers.entity_platform.EntityPlatform.logger

Definition at line 133 of file entity_platform.py.

◆ object_id_component_translations

homeassistant.helpers.entity_platform.EntityPlatform.object_id_component_translations

Definition at line 475 of file entity_platform.py.

◆ object_id_platform_translations

homeassistant.helpers.entity_platform.EntityPlatform.object_id_platform_translations

Definition at line 476 of file entity_platform.py.

◆ parallel_updates

homeassistant.helpers.entity_platform.EntityPlatform.parallel_updates

Definition at line 222 of file entity_platform.py.

◆ parallel_updates_created

homeassistant.helpers.entity_platform.EntityPlatform.parallel_updates_created

Definition at line 163 of file entity_platform.py.

◆ platform

homeassistant.helpers.entity_platform.EntityPlatform.platform

Definition at line 136 of file entity_platform.py.

◆ platform_name

homeassistant.helpers.entity_platform.EntityPlatform.platform_name

Definition at line 135 of file entity_platform.py.

◆ platform_translations

homeassistant.helpers.entity_platform.EntityPlatform.platform_translations

Definition at line 471 of file entity_platform.py.

◆ scan_interval

homeassistant.helpers.entity_platform.EntityPlatform.scan_interval

Definition at line 137 of file entity_platform.py.

◆ scan_interval_seconds

homeassistant.helpers.entity_platform.EntityPlatform.scan_interval_seconds

Definition at line 138 of file entity_platform.py.


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