diff --git a/custom_components/octopus_energy/intelligent/bump_charge.py b/custom_components/octopus_energy/intelligent/bump_charge.py index 3eb650c3..c19d252c 100644 --- a/custom_components/octopus_energy/intelligent/bump_charge.py +++ b/custom_components/octopus_energy/intelligent/bump_charge.py @@ -13,7 +13,7 @@ from ..api_client import OctopusEnergyApiClient from . import is_in_bump_charge from ..coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult - +from ..utils.attributes import dict_to_typed_dict _LOGGER = logging.getLogger(__name__) @@ -85,4 +85,19 @@ async def async_turn_off(self): ) self._state = False self._last_updated = utcnow() - self.async_write_ha_state() \ No newline at end of file + self.async_write_ha_state() + + async def async_added_to_hass(self): + """Call when entity about to be added to hass.""" + # If not None, we got an initial value. + await super().async_added_to_hass() + state = await self.async_get_last_state() + + if state is not None: + self._state = None if state.state == "unknown" else state.state + self._attributes = dict_to_typed_dict(state.attributes) + + if (self._state is None): + self._state = False + + _LOGGER.debug(f'Restored OctopusEnergyIntelligentBumpCharge state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/intelligent/ready_time.py b/custom_components/octopus_energy/intelligent/ready_time.py index bf2a63e3..fb70383c 100644 --- a/custom_components/octopus_energy/intelligent/ready_time.py +++ b/custom_components/octopus_energy/intelligent/ready_time.py @@ -1,5 +1,7 @@ import logging from datetime import time +import time as time_time +from custom_components.octopus_energy.utils.attributes import dict_to_typed_dict from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import generate_entity_id @@ -77,4 +79,19 @@ async def async_set_value(self, value: time) -> None: ) self._state = value self._last_updated = utcnow() - self.async_write_ha_state() \ No newline at end of file + self.async_write_ha_state() + + async def async_added_to_hass(self): + """Call when entity about to be added to hass.""" + # If not None, we got an initial value. + await super().async_added_to_hass() + state = await self.async_get_last_state() + + if state is not None: + self._state = None if state.state == "unknown" else time_time.strptime(state.state, "%H:%M:%S") + self._attributes = dict_to_typed_dict(state.attributes) + + if (self._state is None): + self._state = False + + _LOGGER.debug(f'Restored OctopusEnergyIntelligentReadyTime state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/intelligent/smart_charge.py b/custom_components/octopus_energy/intelligent/smart_charge.py index 356b4952..a6ad9b1a 100644 --- a/custom_components/octopus_energy/intelligent/smart_charge.py +++ b/custom_components/octopus_energy/intelligent/smart_charge.py @@ -12,7 +12,7 @@ from .base import OctopusEnergyIntelligentSensor from ..api_client import OctopusEnergyApiClient from ..coordinators.intelligent_settings import IntelligentCoordinatorResult - +from ..utils.attributes import dict_to_typed_dict _LOGGER = logging.getLogger(__name__) @@ -84,4 +84,19 @@ async def async_turn_off(self): ) self._state = False self._last_updated = utcnow() - self.async_write_ha_state() \ No newline at end of file + self.async_write_ha_state() + + async def async_added_to_hass(self): + """Call when entity about to be added to hass.""" + # If not None, we got an initial value. + await super().async_added_to_hass() + state = await self.async_get_last_state() + + if state is not None: + self._state = None if state.state == "unknown" else state.state + self._attributes = dict_to_typed_dict(state.attributes) + + if (self._state is None): + self._state = False + + _LOGGER.debug(f'Restored OctopusEnergyIntelligentSmartCharge state: {self._state}') \ No newline at end of file