mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
parent
268e5244f0
commit
f96446cb24
@ -298,18 +298,14 @@ class IntegrationSensor(RestoreSensor):
|
|||||||
old_state = event.data["old_state"]
|
old_state = event.data["old_state"]
|
||||||
new_state = event.data["new_state"]
|
new_state = event.data["new_state"]
|
||||||
|
|
||||||
# We may want to update our state before an early return,
|
|
||||||
# based on the source sensor's unit_of_measurement
|
|
||||||
# or device_class.
|
|
||||||
update_state = False
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
source_state := self.hass.states.get(self._sensor_source_id)
|
source_state := self.hass.states.get(self._sensor_source_id)
|
||||||
) is None or source_state.state == STATE_UNAVAILABLE:
|
) is None or source_state.state == STATE_UNAVAILABLE:
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
update_state = True
|
self.async_write_ha_state()
|
||||||
else:
|
return
|
||||||
self._attr_available = True
|
|
||||||
|
self._attr_available = True
|
||||||
|
|
||||||
if old_state is None or new_state is None:
|
if old_state is None or new_state is None:
|
||||||
# we can't calculate the elapsed time, so we can't calculate the integral
|
# we can't calculate the elapsed time, so we can't calculate the integral
|
||||||
@ -317,10 +313,7 @@ class IntegrationSensor(RestoreSensor):
|
|||||||
|
|
||||||
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
if unit is not None:
|
if unit is not None:
|
||||||
new_unit_of_measurement = self._unit(unit)
|
self._unit_of_measurement = self._unit(unit)
|
||||||
if self._unit_of_measurement != new_unit_of_measurement:
|
|
||||||
self._unit_of_measurement = new_unit_of_measurement
|
|
||||||
update_state = True
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.device_class is None
|
self.device_class is None
|
||||||
@ -329,10 +322,8 @@ class IntegrationSensor(RestoreSensor):
|
|||||||
):
|
):
|
||||||
self._attr_device_class = SensorDeviceClass.ENERGY
|
self._attr_device_class = SensorDeviceClass.ENERGY
|
||||||
self._attr_icon = None
|
self._attr_icon = None
|
||||||
update_state = True
|
|
||||||
|
|
||||||
if update_state:
|
self.async_write_ha_state()
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# integration as the Riemann integral of previous measures.
|
# integration as the Riemann integral of previous measures.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user