Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.integration.sensor.IntegrationSensor Class Reference
Inheritance diagram for homeassistant.components.integration.sensor.IntegrationSensor:
[legend]
Collaboration diagram for homeassistant.components.integration.sensor.IntegrationSensor:
[legend]

Public Member Functions

None __init__ (self, *str integration_method, str|None name, int|None round_digits, str source_entity, str|None unique_id, str|None unit_prefix, UnitOfTime unit_time, timedelta|None max_sub_interval, DeviceInfo|None device_info=None)
 
None async_added_to_hass (self)
 
IntegrationSensorExtraStoredData|None async_get_last_sensor_data (self)
 
IntegrationSensorExtraStoredData extra_restore_state_data (self)
 
dict[str, str]|None extra_state_attributes (self)
 
str|None native_unit_of_measurement (self)
 
Decimal|None native_value (self)
 
- Public Member Functions inherited from homeassistant.components.sensor.SensorEntity
None add_to_platform_start (self, HomeAssistant hass, EntityPlatform platform, asyncio.Semaphore|None parallel_updates)
 
None async_internal_added_to_hass (self)
 
None async_registry_entry_updated (self)
 
dict[str, Any]|None capability_attributes (self)
 
SensorDeviceClass|None device_class (self)
 
er.EntityOptionsType|None get_initial_entity_options (self)
 
datetime|None last_reset (self)
 
list[str]|None options (self)
 
Any state (self)
 
dict[str, Any]|None state_attributes (self)
 
SensorStateClass|str|None state_class (self)
 
int|None suggested_display_precision (self)
 
str|None suggested_unit_of_measurement (self)
 
str|None unit_of_measurement (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)
 
bool assumed_state (self)
 
None async_device_update (self, bool warning=True)
 
None async_internal_will_remove_from_hass (self)
 
None async_on_remove (self, CALLBACK_TYPE func)
 
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)
 
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)
 
bool force_update (self)
 
HassJobType get_hassjob_type (self, str function_name)
 
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)
 
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)
 
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)
 

Private Member Functions

SensorDeviceClass|None _calculate_device_class (self, SensorDeviceClass|None source_device_class, str|None unit_of_measurement)
 
str _calculate_unit (self, str source_unit)
 
None _cancel_max_sub_interval_exceeded_callback (self)
 
None _derive_and_set_attributes_from_state (self, State source_state)
 
None _integrate_on_state_change (self, datetime|None old_last_reported, State|None old_state, State|None new_state)
 
None _integrate_on_state_change_callback (self, Event[EventStateChangedData] event)
 
None _integrate_on_state_change_with_max_sub_interval (self, Event[EventStateChangedData] event)
 
None _integrate_on_state_report_callback (self, Event[EventStateReportedData] event)
 
None _integrate_on_state_report_with_max_sub_interval (self, Event[EventStateReportedData] event)
 
None _integrate_on_state_update_with_max_sub_interval (self, datetime|None old_last_reported, State|None old_state, State|None new_state)
 
None _schedule_max_sub_interval_exceeded_if_state_is_numeric (self, State|None source_state)
 
None _update_integral (self, Decimal area)
 

Private Attributes

 _attr_available
 
 _attr_device_class
 
 _attr_device_info
 
 _attr_icon
 
 _attr_name
 
 _attr_native_value
 
 _attr_suggested_display_precision
 
 _attr_unique_id
 
 _last_integration_time
 
 _last_integration_trigger
 
 _last_valid_state
 
 _max_sub_interval_exceeded_callback
 
 _method
 
 _round_digits
 
 _sensor_source_id
 
 _state
 
 _unit_of_measurement
 
 _unit_prefix
 
 _unit_prefix_string
 
 _unit_time
 
 _unit_time_str
 

Static Private Attributes

bool _attr_should_poll = False
 
 _attr_state_class = SensorStateClass.TOTAL
 

Additional Inherited Members

- Public Attributes inherited from homeassistant.components.sensor.SensorEntity
 entity_category
 
 registry_entry
 
 unit_of_measurement
 
- Public Attributes inherited from homeassistant.helpers.entity.Entity
 device_entry
 
 entity_id
 
 hass
 
 parallel_updates
 
 platform
 
 registry_entry
 
- Static Public Attributes inherited from homeassistant.components.sensor.SensorEntity
 Decimal
 
 None
 
 UndefinedType
 
- Static Public Attributes inherited from homeassistant.helpers.entity.Entity
 bool
 
 EntityPlatform
 
 HomeAssistant
 
 None
 
 StateInfo
 
 StateType
 
 str
 

Detailed Description

Representation of an integration sensor.

Definition at line 300 of file sensor.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.integration.sensor.IntegrationSensor.__init__ (   self,
*str  integration_method,
str | None  name,
int | None  round_digits,
str  source_entity,
str | None  unique_id,
str | None  unit_prefix,
UnitOfTime  unit_time,
timedelta | None  max_sub_interval,
DeviceInfo | None   device_info = None 
)
Initialize the integration sensor.

Definition at line 306 of file sensor.py.

Member Function Documentation

◆ _calculate_device_class()

SensorDeviceClass | None homeassistant.components.integration.sensor.IntegrationSensor._calculate_device_class (   self,
SensorDeviceClass | None  source_device_class,
str | None  unit_of_measurement 
)
private
Deduce device class if possible from source device class and target unit.

Definition at line 366 of file sensor.py.

◆ _calculate_unit()

str homeassistant.components.integration.sensor.IntegrationSensor._calculate_unit (   self,
str  source_unit 
)
private
Multiply source_unit with time unit of the integral.

Possibly cancelling out a time unit in the denominator of the source_unit.
Note that this is a heuristic string manipulation method and might not
transform all source units in a sensible way.

Examples:
- Speed to distance: 'km/h' and 'h' will be transformed to 'km'
- Power to energy: 'W' and 'h' will be transformed to 'Wh'

Definition at line 346 of file sensor.py.

◆ _cancel_max_sub_interval_exceeded_callback()

None homeassistant.components.integration.sensor.IntegrationSensor._cancel_max_sub_interval_exceeded_callback (   self)
private

Definition at line 608 of file sensor.py.

◆ _derive_and_set_attributes_from_state()

None homeassistant.components.integration.sensor.IntegrationSensor._derive_and_set_attributes_from_state (   self,
State  source_state 
)
private

Definition at line 382 of file sensor.py.

◆ _integrate_on_state_change()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_change (   self,
datetime | None  old_last_reported,
State | None  old_state,
State | None  new_state 
)
private

Definition at line 517 of file sensor.py.

◆ _integrate_on_state_change_callback()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_change_callback (   self,
Event[EventStateChangedData]   event 
)
private
Handle sensor state change.

Definition at line 500 of file sensor.py.

◆ _integrate_on_state_change_with_max_sub_interval()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_change_with_max_sub_interval (   self,
Event[EventStateChangedData]   event 
)
private
Handle sensor state update when sub interval is configured.

Definition at line 460 of file sensor.py.

◆ _integrate_on_state_report_callback()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_report_callback (   self,
Event[EventStateReportedData]   event 
)
private
Handle sensor state report.

Definition at line 509 of file sensor.py.

◆ _integrate_on_state_report_with_max_sub_interval()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_report_with_max_sub_interval (   self,
Event[EventStateReportedData]   event 
)
private
Handle sensor state report when sub interval is configured.

Definition at line 469 of file sensor.py.

◆ _integrate_on_state_update_with_max_sub_interval()

None homeassistant.components.integration.sensor.IntegrationSensor._integrate_on_state_update_with_max_sub_interval (   self,
datetime | None  old_last_reported,
State | None  old_state,
State | None  new_state 
)
private
Integrate based on state change and time.

Next to doing the integration based on state change this method cancels and
reschedules time based integration.

Definition at line 478 of file sensor.py.

◆ _schedule_max_sub_interval_exceeded_if_state_is_numeric()

None homeassistant.components.integration.sensor.IntegrationSensor._schedule_max_sub_interval_exceeded_if_state_is_numeric (   self,
State | None   source_state 
)
private
Schedule possible integration using the source state and max_sub_interval.

The callback reference is stored for possible cancellation if the source state
reports a change before max_sub_interval has passed.

If the callback is executed, meaning there was no state change reported, the
source_state is assumed constant and integration is done using its value.

Definition at line 565 of file sensor.py.

◆ _update_integral()

None homeassistant.components.integration.sensor.IntegrationSensor._update_integral (   self,
Decimal  area 
)
private

Definition at line 398 of file sensor.py.

◆ async_added_to_hass()

None homeassistant.components.integration.sensor.IntegrationSensor.async_added_to_hass (   self)
Handle entity which will be added.

Reimplemented from homeassistant.helpers.entity.Entity.

Definition at line 409 of file sensor.py.

◆ async_get_last_sensor_data()

IntegrationSensorExtraStoredData | None homeassistant.components.integration.sensor.IntegrationSensor.async_get_last_sensor_data (   self)
Restore Utility Meter Sensor Extra Stored Data.

Reimplemented from homeassistant.components.sensor.RestoreSensor.

Definition at line 640 of file sensor.py.

◆ extra_restore_state_data()

IntegrationSensorExtraStoredData homeassistant.components.integration.sensor.IntegrationSensor.extra_restore_state_data (   self)
Return sensor specific state data to be restored.

Reimplemented from homeassistant.components.sensor.RestoreSensor.

Definition at line 631 of file sensor.py.

◆ extra_state_attributes()

dict[str, str] | None homeassistant.components.integration.sensor.IntegrationSensor.extra_state_attributes (   self)
Return the state attributes of the sensor.

Reimplemented from homeassistant.helpers.entity.Entity.

Definition at line 624 of file sensor.py.

◆ native_unit_of_measurement()

str | None homeassistant.components.integration.sensor.IntegrationSensor.native_unit_of_measurement (   self)
Return the unit the value is expressed in.

Reimplemented from homeassistant.components.sensor.SensorEntity.

Definition at line 619 of file sensor.py.

◆ native_value()

Decimal | None homeassistant.components.integration.sensor.IntegrationSensor.native_value (   self)
Return the state of the sensor.

Reimplemented from homeassistant.components.sensor.SensorEntity.

Definition at line 612 of file sensor.py.

Member Data Documentation

◆ _attr_available

homeassistant.components.integration.sensor.IntegrationSensor._attr_available
private

Definition at line 527 of file sensor.py.

◆ _attr_device_class

homeassistant.components.integration.sensor.IntegrationSensor._attr_device_class
private

Definition at line 390 of file sensor.py.

◆ _attr_device_info

homeassistant.components.integration.sensor.IntegrationSensor._attr_device_info
private

Definition at line 335 of file sensor.py.

◆ _attr_icon

homeassistant.components.integration.sensor.IntegrationSensor._attr_icon
private

Definition at line 332 of file sensor.py.

◆ _attr_name

homeassistant.components.integration.sensor.IntegrationSensor._attr_name
private

Definition at line 326 of file sensor.py.

◆ _attr_native_value

homeassistant.components.integration.sensor.IntegrationSensor._attr_native_value
private

Definition at line 419 of file sensor.py.

◆ _attr_should_poll

bool homeassistant.components.integration.sensor.IntegrationSensor._attr_should_poll = False
staticprivate

Definition at line 304 of file sensor.py.

◆ _attr_state_class

homeassistant.components.integration.sensor.IntegrationSensor._attr_state_class = SensorStateClass.TOTAL
staticprivate

Definition at line 303 of file sensor.py.

◆ _attr_suggested_display_precision

homeassistant.components.integration.sensor.IntegrationSensor._attr_suggested_display_precision
private

Definition at line 344 of file sensor.py.

◆ _attr_unique_id

homeassistant.components.integration.sensor.IntegrationSensor._attr_unique_id
private

Definition at line 320 of file sensor.py.

◆ _last_integration_time

homeassistant.components.integration.sensor.IntegrationSensor._last_integration_time
private

Definition at line 493 of file sensor.py.

◆ _last_integration_trigger

homeassistant.components.integration.sensor.IntegrationSensor._last_integration_trigger
private

Definition at line 343 of file sensor.py.

◆ _last_valid_state

homeassistant.components.integration.sensor.IntegrationSensor._last_valid_state
private

Definition at line 407 of file sensor.py.

◆ _max_sub_interval_exceeded_callback

homeassistant.components.integration.sensor.IntegrationSensor._max_sub_interval_exceeded_callback
private

Definition at line 602 of file sensor.py.

◆ _method

homeassistant.components.integration.sensor.IntegrationSensor._method
private

Definition at line 324 of file sensor.py.

◆ _round_digits

homeassistant.components.integration.sensor.IntegrationSensor._round_digits
private

Definition at line 322 of file sensor.py.

◆ _sensor_source_id

homeassistant.components.integration.sensor.IntegrationSensor._sensor_source_id
private

Definition at line 321 of file sensor.py.

◆ _state

homeassistant.components.integration.sensor.IntegrationSensor._state
private

Definition at line 403 of file sensor.py.

◆ _unit_of_measurement

homeassistant.components.integration.sensor.IntegrationSensor._unit_of_measurement
private

Definition at line 385 of file sensor.py.

◆ _unit_prefix

homeassistant.components.integration.sensor.IntegrationSensor._unit_prefix
private

Definition at line 329 of file sensor.py.

◆ _unit_prefix_string

homeassistant.components.integration.sensor.IntegrationSensor._unit_prefix_string
private

Definition at line 327 of file sensor.py.

◆ _unit_time

homeassistant.components.integration.sensor.IntegrationSensor._unit_time
private

Definition at line 330 of file sensor.py.

◆ _unit_time_str

homeassistant.components.integration.sensor.IntegrationSensor._unit_time_str
private

Definition at line 331 of file sensor.py.


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