Don't try to restore unavailable nor unknown states (#92825)
parent
7361c29cba
commit
3c45bda0e8
|
@ -174,7 +174,10 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
if state := await self.async_get_last_state():
|
if (state := await self.async_get_last_state()) is not None:
|
||||||
|
if state.state == STATE_UNAVAILABLE:
|
||||||
|
self._attr_available = False
|
||||||
|
elif state.state != STATE_UNKNOWN:
|
||||||
try:
|
try:
|
||||||
self._state = Decimal(state.state)
|
self._state = Decimal(state.state)
|
||||||
except (DecimalException, ValueError) as err:
|
except (DecimalException, ValueError) as err:
|
||||||
|
@ -184,12 +187,9 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
||||||
state.state,
|
state.state,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
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(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
self._unit_of_measurement = state.attributes.get(
|
|
||||||
ATTR_UNIT_OF_MEASUREMENT
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def calc_integration(event: Event) -> None:
|
def calc_integration(event: Event) -> None:
|
||||||
|
|
Loading…
Reference in New Issue