mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Integration Sensor unit of measurement overwrite (#55869)
This commit is contained in:
parent
8d4aac618d
commit
34d54511e8
@ -110,16 +110,10 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
|||||||
self._method = integration_method
|
self._method = integration_method
|
||||||
|
|
||||||
self._name = name if name is not None else f"{source_entity} integral"
|
self._name = name if name is not None else f"{source_entity} integral"
|
||||||
|
self._unit_template = (
|
||||||
if unit_of_measurement is None:
|
f"{'' if unit_prefix is None else unit_prefix}{{}}{unit_time}"
|
||||||
self._unit_template = (
|
)
|
||||||
f"{'' if unit_prefix is None else unit_prefix}{{}}{unit_time}"
|
self._unit_of_measurement = unit_of_measurement
|
||||||
)
|
|
||||||
# we postpone the definition of unit_of_measurement to later
|
|
||||||
self._unit_of_measurement = None
|
|
||||||
else:
|
|
||||||
self._unit_of_measurement = unit_of_measurement
|
|
||||||
|
|
||||||
self._unit_prefix = UNIT_PREFIXES[unit_prefix]
|
self._unit_prefix = UNIT_PREFIXES[unit_prefix]
|
||||||
self._unit_time = UNIT_TIME[unit_time]
|
self._unit_time = UNIT_TIME[unit_time]
|
||||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||||
@ -135,10 +129,10 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
|||||||
_LOGGER.warning("Could not restore last state: %s", err)
|
_LOGGER.warning("Could not restore last state: %s", err)
|
||||||
else:
|
else:
|
||||||
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||||
|
if self._unit_of_measurement is None:
|
||||||
self._unit_of_measurement = state.attributes.get(
|
self._unit_of_measurement = state.attributes.get(
|
||||||
ATTR_UNIT_OF_MEASUREMENT
|
ATTR_UNIT_OF_MEASUREMENT
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def calc_integration(event):
|
def calc_integration(event):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user