Skip to content

Commit

Permalink
fix: Fixed issue with restoring saving session baseline entity and cu…
Browse files Browse the repository at this point in the history
…rrent interval accumulative consumption sensor (5 minutes dev time)
  • Loading branch information
BottlecapDave committed Sep 28, 2024
1 parent 1dedab4 commit a7fa406
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import logging

from homeassistant.core import HomeAssistant, callback
from homeassistant.const import (
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)

from homeassistant.helpers.update_coordinator import (
CoordinatorEntity
Expand Down Expand Up @@ -109,7 +113,7 @@ async def async_added_to_hass(self):
state = await self.async_get_last_state()

if state is not None and self._state is None:
self._state = None if state.state == "unknown" else state.state
self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state
self._attributes = dict_to_typed_dict(state.attributes)

_LOGGER.debug(f'Restored OctopusEnergyCurrentElectricityIntervalAccumulativeConsumption state: {self._state}')
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from homeassistant.core import HomeAssistant
from homeassistant.util.dt import (utcnow)
from homeassistant.const import (
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)

from homeassistant.components.sensor import (
RestoreSensor,
Expand Down Expand Up @@ -172,7 +176,7 @@ async def async_added_to_hass(self):
state = await self.async_get_last_state()

if state is not None:
self._state = None if state.state == "unknown" else state.state
self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state
self._attributes = dict_to_typed_dict(state.attributes)

_LOGGER.debug(f'Restored state: {self._state}')

0 comments on commit a7fa406

Please sign in to comment.