homeassistant.helpers.entity module provides the Entity base class and related utilities for creating entities in Home Assistant.
Entity Class
TheEntity class is an abstract base class that all Home Assistant entities must inherit from.
Key Properties
Unique identifier for the entity (format:
domain.object_id)Name of the entity
Current state of the entity
Whether the entity is available
Unique identifier for the entity across restarts
Information about the device this entity belongs to
Icon to use in the frontend (format:
mdi:icon-name)URL of picture to use in the frontend
True if unable to access real state of the entity
True if entity has to be polled for state, False if entity pushes its state
Flag of features supported by the entity
Device class of the entity from component DEVICE_CLASSES
Unit of measurement for the entity’s value
Category of the entity (config, diagnostic)
Key Methods
async_write_ha_state
Write the state to the state machine.async_update_ha_state
Update Home Assistant with current state of entity.If True, update entity before setting state
async_schedule_update_ha_state
Schedule an update ha state change task.If True, force entity refresh
async_on_remove
Add a function to call when entity is removed or not added.Callback function to call on removal
Helper Functions
generate_entity_id
Generate a unique entity ID based on given entity IDs or used IDs.Format string for entity ID (e.g.,
"light.{}")Name to use for generating the entity ID
List of currently used entity IDs
Home Assistant instance (required if current_ids is None)
Generated unique entity ID
get_capability
Get a capability attribute of an entity.Home Assistant instance
Entity ID to get capability from
Name of capability to retrieve
Capability value or None if not found
get_device_class
Get device class of an entity.Home Assistant instance
Entity ID
Device class or None
get_supported_features
Get supported features for an entity.Home Assistant instance
Entity ID
Bitfield of supported features (0 if none)
get_unit_of_measurement
Get unit of measurement of an entity.Home Assistant instance
Entity ID
Unit of measurement or None
EntityDescription
Dataclass that describes Home Assistant entities.Key identifier for this entity
Device class
Category of entity
Whether entity should be enabled when first added
Whether entity should be visible when first added
Force state update even if value hasn’t changed
Icon for the entity
Whether the name describes only the entity itself
Name of the entity
Translation key for the entity name
Unit of measurement
Constants
SLOW_UPDATE_WARNING = 10- Seconds before warning about slow updatesFLOAT_PRECISION- Precision for float state representationCAPABILITIES_UPDATE_LIMIT = 100- Max capability updates per hour before warning