Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.template.template_entity.TemplateEntity Class Reference
Inheritance diagram for homeassistant.components.template.template_entity.TemplateEntity:
[legend]
Collaboration diagram for homeassistant.components.template.template_entity.TemplateEntity:
[legend]

Public Member Functions

None __init__ (self, HomeAssistant hass, *Template|None availability_template=None, Template|None icon_template=None, Template|None entity_picture_template=None, dict[str, Template]|None attribute_templates=None, ConfigType|None config=None, str|None fallback_name=None, str|None unique_id=None)
 
None add_template_attribute (self, str attribute, Template template, Callable[[Any], Any]|None validator=None, Callable[[Any], None]|None on_update=None, bool none_on_template_error=False)
 
None async_added_to_hass (self)
 
None async_run_script (self, Script script, *_VarsType|None run_variables=None, Context|None context=None)
 
CALLBACK_TYPE async_start_preview (self, Callable[[str|None, Mapping[str, Any]|None, dict[str, bool|set[str]]|None, str|None,], None,] preview_callback)
 
None async_update (self)
 
str|None referenced_blueprint (self)
 
- Public Member Functions inherited from homeassistant.helpers.entity.Entity
None __init_subclass__ (cls, **Any kwargs)
 
str __repr__ (self)
 
None add_to_platform_abort (self)
 
None add_to_platform_finish (self)
 
None add_to_platform_start (self, HomeAssistant hass, EntityPlatform platform, asyncio.Semaphore|None parallel_updates)
 
bool assumed_state (self)
 
None async_device_update (self, bool warning=True)
 
None async_internal_added_to_hass (self)
 
None async_internal_will_remove_from_hass (self)
 
None async_on_remove (self, CALLBACK_TYPE func)
 
None async_registry_entry_updated (self)
 
None async_remove (self, *bool force_remove=False)
 
None async_removed_from_registry (self)
 
None async_schedule_update_ha_state (self, bool force_refresh=False)
 
None async_set_context (self, Context context)
 
None async_update_ha_state (self, bool force_refresh=False)
 
None async_will_remove_from_hass (self)
 
None async_write_ha_state (self)
 
str|None attribution (self)
 
bool available (self)
 
dict[str, Any]|None capability_attributes (self)
 
str|None device_class (self)
 
DeviceInfo|None device_info (self)
 
bool enabled (self)
 
EntityCategory|None entity_category (self)
 
str|None entity_picture (self)
 
bool entity_registry_enabled_default (self)
 
bool entity_registry_visible_default (self)
 
Mapping[str, Any]|None extra_state_attributes (self)
 
bool force_update (self)
 
HassJobType get_hassjob_type (self, str function_name)
 
er.EntityOptionsType|None get_initial_entity_options (self)
 
bool has_entity_name (self)
 
str|None icon (self)
 
str|UndefinedType|None name (self)
 
None schedule_update_ha_state (self, bool force_refresh=False)
 
bool should_poll (self)
 
StateType state (self)
 
dict[str, Any]|None state_attributes (self)
 
str|None suggested_object_id (self)
 
int|None supported_features (self)
 
str|None translation_key (self)
 
Mapping[str, strtranslation_placeholders (self)
 
str|None unique_id (self)
 
str|None unit_of_measurement (self)
 
bool use_device_name (self)
 
- Public Member Functions inherited from homeassistant.helpers.entity.CachedProperties
None __init__ (cls, str name, tuple[type,...] bases, dict[Any, Any] namespace, **Any kwargs)
 
Any __new__ (mcs, str name, tuple[type,...] bases, dict[Any, Any] namespace, set[str]|None cached_properties=None, **Any kwargs)
 

Public Attributes

 entity_id
 
- Public Attributes inherited from homeassistant.helpers.entity.Entity
 device_entry
 
 entity_id
 
 hass
 
 parallel_updates
 
 platform
 
 registry_entry
 

Private Member Functions

None _add_attribute_template (self, str attribute_key, Template attribute_template)
 
None _async_setup_templates (self)
 
None _async_template_startup (self, HomeAssistant|None _hass, Callable[[int, str], None]|None log_fn=None)
 
None _handle_results (self, Event[EventStateChangedData]|None event, list[TrackTemplateResult] updates)
 
dict _render_variables (self)
 
None _update_available (self, str|TemplateError result)
 
None _update_state (self, str|TemplateError result)
 

Private Attributes

 _attr_available
 
 _attr_extra_state_attributes
 
 _attr_name
 
 _attr_unique_id
 
 _attribute_templates
 
 _availability_template
 
 _blueprint_inputs
 
 _entity_picture_template
 
 _friendly_name_template
 
 _icon_template
 
 _preview_callback
 
 _run_variables
 
 _self_ref_update_count
 
 _template_result_info
 

Static Private Attributes

bool _attr_available = True
 
 _attr_entity_picture = None
 
 _attr_icon = None
 

Additional Inherited Members

- Static Public Attributes inherited from homeassistant.helpers.entity.Entity
 bool
 
 EntityPlatform
 
 HomeAssistant
 
 None
 
 StateInfo
 
 StateType
 
 str
 

Detailed Description

Entity that uses templates to calculate attributes.

Definition at line 251 of file template_entity.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.template.template_entity.TemplateEntity.__init__ (   self,
HomeAssistant  hass,
*Template | None   availability_template = None,
Template | None   icon_template = None,
Template | None   entity_picture_template = None,
dict[str, Template] | None   attribute_templates = None,
ConfigType | None   config = None,
str | None   fallback_name = None,
str | None   unique_id = None 
)
Template Entity.

Definition at line 258 of file template_entity.py.

Member Function Documentation

◆ _add_attribute_template()

None homeassistant.components.template.template_entity.TemplateEntity._add_attribute_template (   self,
str  attribute_key,
Template   attribute_template 
)
private
Create a template tracker for the attribute.

Definition at line 370 of file template_entity.py.

◆ _async_setup_templates()

◆ _async_template_startup()

None homeassistant.components.template.template_entity.TemplateEntity._async_template_startup (   self,
HomeAssistant | None  _hass,
Callable[[int, str], None] | None   log_fn = None 
)
private

Definition at line 481 of file template_entity.py.

◆ _handle_results()

None homeassistant.components.template.template_entity.TemplateEntity._handle_results (   self,
Event[EventStateChangedData] | None  event,
list[TrackTemplateResult updates 
)
private
Call back the results to the attributes.

Definition at line 428 of file template_entity.py.

◆ _render_variables()

dict homeassistant.components.template.template_entity.TemplateEntity._render_variables (   self)
private

Definition at line 343 of file template_entity.py.

◆ _update_available()

None homeassistant.components.template.template_entity.TemplateEntity._update_available (   self,
str | TemplateError  result 
)
private

Definition at line 355 of file template_entity.py.

◆ _update_state()

None homeassistant.components.template.template_entity.TemplateEntity._update_state (   self,
str | TemplateError  result 
)
private

Definition at line 363 of file template_entity.py.

◆ add_template_attribute()

None homeassistant.components.template.template_entity.TemplateEntity.add_template_attribute (   self,
str  attribute,
Template  template,
Callable[[Any], Any] | None   validator = None,
Callable[[Any], None] | None   on_update = None,
bool   none_on_template_error = False 
)
Call in the constructor to add a template linked to a attribute.

Parameters
----------
attribute
    The name of the attribute to link to. This attribute must exist
    unless a custom on_update method is supplied.
template
    The template to calculate.
validator
    Validator function to parse the result and ensure it's valid.
on_update
    Called to store the template result rather than storing it
    the supplied attribute. Passed the result of the validator, or None
    if the template or validator resulted in an error.
none_on_template_error
    If True, the attribute will be set to None if the template errors.

Definition at line 390 of file template_entity.py.

◆ async_added_to_hass()

None homeassistant.components.template.template_entity.TemplateEntity.async_added_to_hass (   self)

◆ async_run_script()

None homeassistant.components.template.template_entity.TemplateEntity.async_run_script (   self,
Script  script,
*_VarsType | None   run_variables = None,
Context | None   context = None 
)
Run an action script.

Definition at line 585 of file template_entity.py.

◆ async_start_preview()

CALLBACK_TYPE homeassistant.components.template.template_entity.TemplateEntity.async_start_preview (   self,
Callable[ [ str | None, Mapping[str, Any] | None, dict[str, bool | set[str]] | None, str | None, ], None, ]  preview_callback 
)
Render a preview.

Definition at line 549 of file template_entity.py.

◆ async_update()

None homeassistant.components.template.template_entity.TemplateEntity.async_update (   self)
Call for forced update.

Definition at line 580 of file template_entity.py.

◆ referenced_blueprint()

str | None homeassistant.components.template.template_entity.TemplateEntity.referenced_blueprint (   self)
Return referenced blueprint or None.

Definition at line 384 of file template_entity.py.

Member Data Documentation

◆ _attr_available [1/2]

bool homeassistant.components.template.template_entity.TemplateEntity._attr_available = True
staticprivate

Definition at line 254 of file template_entity.py.

◆ _attr_available [2/2]

homeassistant.components.template.template_entity.TemplateEntity._attr_available
private

Definition at line 357 of file template_entity.py.

◆ _attr_entity_picture

homeassistant.components.template.template_entity.TemplateEntity._attr_entity_picture = None
staticprivate

Definition at line 255 of file template_entity.py.

◆ _attr_extra_state_attributes

homeassistant.components.template.template_entity.TemplateEntity._attr_extra_state_attributes
private

Definition at line 273 of file template_entity.py.

◆ _attr_icon

homeassistant.components.template.template_entity.TemplateEntity._attr_icon = None
staticprivate

Definition at line 256 of file template_entity.py.

◆ _attr_name

homeassistant.components.template.template_entity.TemplateEntity._attr_name
private

Definition at line 321 of file template_entity.py.

◆ _attr_unique_id

homeassistant.components.template.template_entity.TemplateEntity._attr_unique_id
private

Definition at line 275 of file template_entity.py.

◆ _attribute_templates

homeassistant.components.template.template_entity.TemplateEntity._attribute_templates
private

Definition at line 289 of file template_entity.py.

◆ _availability_template

homeassistant.components.template.template_entity.TemplateEntity._availability_template
private

Definition at line 290 of file template_entity.py.

◆ _blueprint_inputs

homeassistant.components.template.template_entity.TemplateEntity._blueprint_inputs
private

Definition at line 295 of file template_entity.py.

◆ _entity_picture_template

homeassistant.components.template.template_entity.TemplateEntity._entity_picture_template
private

Definition at line 292 of file template_entity.py.

◆ _friendly_name_template

homeassistant.components.template.template_entity.TemplateEntity._friendly_name_template
private

Definition at line 293 of file template_entity.py.

◆ _icon_template

homeassistant.components.template.template_entity.TemplateEntity._icon_template
private

Definition at line 291 of file template_entity.py.

◆ _preview_callback

homeassistant.components.template.template_entity.TemplateEntity._preview_callback
private

Definition at line 566 of file template_entity.py.

◆ _run_variables

homeassistant.components.template.template_entity.TemplateEntity._run_variables
private

Definition at line 294 of file template_entity.py.

◆ _self_ref_update_count

homeassistant.components.template.template_entity.TemplateEntity._self_ref_update_count
private

Definition at line 274 of file template_entity.py.

◆ _template_result_info

homeassistant.components.template.template_entity.TemplateEntity._template_result_info
private

Definition at line 516 of file template_entity.py.

◆ entity_id

homeassistant.components.template.template_entity.TemplateEntity.entity_id

Definition at line 311 of file template_entity.py.


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