Integration Sensor unit of measurement overwrite (#55869)

This commit is contained in:
Diogo Gomes 2021-09-06 21:41:01 +01:00 committed by GitHub
parent 8d4aac618d
commit 34d54511e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,16 +110,10 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
self._method = integration_method
self._name = name if name is not None else f"{source_entity} integral"
if unit_of_measurement is None:
self._unit_template = (
f"{'' if unit_prefix is None else unit_prefix}{{}}{unit_time}"
)
# 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_template = (
f"{'' if unit_prefix is None else unit_prefix}{{}}{unit_time}"
)
self._unit_of_measurement = unit_of_measurement
self._unit_prefix = UNIT_PREFIXES[unit_prefix]
self._unit_time = UNIT_TIME[unit_time]
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)
else:
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
self._unit_of_measurement = state.attributes.get(
ATTR_UNIT_OF_MEASUREMENT
)
if self._unit_of_measurement is None:
self._unit_of_measurement = state.attributes.get(
ATTR_UNIT_OF_MEASUREMENT
)
@callback
def calc_integration(event):