From 8aedcb93f173c676eaa43227b5aa34363a4d551b Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Wed, 1 Jan 2025 12:41:32 +0000 Subject: [PATCH 1/3] docs: Updated the warning for intelligent target time --- _docs/entities/intelligent.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/entities/intelligent.md b/_docs/entities/intelligent.md index 958f0b14..ddb0d591 100644 --- a/_docs/entities/intelligent.md +++ b/_docs/entities/intelligent.md @@ -139,7 +139,7 @@ This sensor is used to see and set the target time for your future intelligent c !!! warning - There is a time based sensor called `select.octopus_energy_{{ACCOUNT_ID}}_intelligent_target_time` which represents this functionality. This is a legacy sensor which will be removed in the future. + There is a time based sensor called `time.octopus_energy_{{ACCOUNT_ID}}_intelligent_target_time` which represents this functionality. This is a legacy sensor which will be removed in the future. ## Migrating from megakid/ha_octopus_intelligent? From 1d819930ee8b82b4411f89f79412a70462314122 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Wed, 1 Jan 2025 12:51:34 +0000 Subject: [PATCH 2/3] docs: Updated FAQ to include heat pump data --- _docs/faq.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_docs/faq.md b/_docs/faq.md index a1c7c80c..5622b245 100644 --- a/_docs/faq.md +++ b/_docs/faq.md @@ -17,6 +17,7 @@ Based on a request from [Octopus Energy](https://forum.octopus.energy/t/pending- | Wheel of fortune | 60 | Doesn't change that frequently, and not fundamental for a smart home (other than knowledge) so no need to request too often. | | Greenness Forecast | 180 | Doesn't change frequently | | Free electricity sessions | 90 | Data is provided by my own [private API](https://github.com/BottlecapDave/OctopusEnergyApi) and there is usually at least half a day notice before the sessions which is why this is refreshed slightly less than saving sessions. | +| Heat Pump state | 1 | Data is updated frequently and doesn't seem to cause any issues around rate limits. This might change in the future. | If data cannot be refreshed for any reason (e.g. no internet or APIs are down), then the integration will attempt to retrieve data as soon as possible, slowly waiting longer between each attempt, to a maximum of 30 minutes between each attempt. Below is a rough example assuming the first (failed) scheduled refresh was at `10:35`. From 0c61292994f052f1782c2163a46ff4c5d7c04471 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Thu, 2 Jan 2025 08:29:55 +0000 Subject: [PATCH 3/3] fix: Fixed issue with restoring sensors where the unit of measurement has been changed (1 hour dev time) --- .../octopus_energy/cost_tracker/cost_tracker.py | 5 +++-- .../octopus_energy/cost_tracker/cost_tracker_month.py | 5 +++-- .../octopus_energy/cost_tracker/cost_tracker_week.py | 5 +++-- .../electricity/current_accumulative_consumption.py | 5 +++-- .../electricity/current_accumulative_cost.py | 5 +++-- .../octopus_energy/electricity/current_consumption.py | 5 +++-- .../octopus_energy/electricity/current_demand.py | 5 +++-- .../current_interval_accumulative_consumption_.py | 5 +++-- .../octopus_energy/electricity/current_rate.py | 5 +++-- .../electricity/current_total_consumption.py | 5 +++-- custom_components/octopus_energy/electricity/next_rate.py | 5 +++-- .../electricity/previous_accumulative_consumption.py | 5 +++-- .../electricity/previous_accumulative_cost.py | 5 +++-- .../electricity/previous_accumulative_cost_override.py | 5 +++-- .../octopus_energy/electricity/previous_rate.py | 5 +++-- .../octopus_energy/electricity/standing_charge.py | 5 +++-- .../gas/current_accumulative_consumption_cubic_meters.py | 5 +++-- .../gas/current_accumulative_consumption_kwh.py | 5 +++-- .../octopus_energy/gas/current_accumulative_cost.py | 5 +++-- .../octopus_energy/gas/current_consumption.py | 5 +++-- custom_components/octopus_energy/gas/current_rate.py | 5 +++-- .../gas/current_total_consumption_cubic_meters.py | 5 +++-- .../octopus_energy/gas/current_total_consumption_kwh.py | 5 +++-- custom_components/octopus_energy/gas/next_rate.py | 5 +++-- .../gas/previous_accumulative_consumption_cubic_meters.py | 5 +++-- .../gas/previous_accumulative_consumption_kwh.py | 5 +++-- .../octopus_energy/gas/previous_accumulative_cost.py | 5 +++-- .../gas/previous_accumulative_cost_override.py | 5 +++-- custom_components/octopus_energy/gas/previous_rate.py | 5 +++-- custom_components/octopus_energy/gas/standing_charge.py | 5 +++-- .../octopus_energy/greenness_forecast/current_index.py | 5 +++-- .../octopus_energy/greenness_forecast/next_index.py | 5 +++-- .../octopus_energy/heat_pump/sensor_humidity.py | 5 +++-- .../heat_pump/sensor_lifetime_energy_input.py | 5 +++-- .../heat_pump/sensor_lifetime_heat_output.py | 5 +++-- .../octopus_energy/heat_pump/sensor_lifetime_scop.py | 5 +++-- .../octopus_energy/heat_pump/sensor_live_cop.py | 5 +++-- .../octopus_energy/heat_pump/sensor_live_heat_output.py | 5 +++-- .../heat_pump/sensor_live_outdoor_temperature.py | 5 +++-- .../octopus_energy/heat_pump/sensor_live_power_input.py | 5 +++-- .../octopus_energy/heat_pump/sensor_temperature.py | 5 +++-- .../octopus_energy/intelligent/current_state.py | 5 +++-- .../octoplus/free_electricity_session_baseline.py | 7 ++++--- custom_components/octopus_energy/octoplus/points.py | 7 ++++--- .../octopus_energy/octoplus/saving_session_baseline.py | 7 ++++--- .../octopus_energy/wheel_of_fortune/electricity_spins.py | 7 ++++--- .../octopus_energy/wheel_of_fortune/gas_spins.py | 7 ++++--- 47 files changed, 146 insertions(+), 99 deletions(-) diff --git a/custom_components/octopus_energy/cost_tracker/cost_tracker.py b/custom_components/octopus_energy/cost_tracker/cost_tracker.py index 8a92b8df..2636ab72 100644 --- a/custom_components/octopus_energy/cost_tracker/cost_tracker.py +++ b/custom_components/octopus_energy/cost_tracker/cost_tracker.py @@ -134,9 +134,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) # Make sure our attributes don't override any changed settings self._attributes.update(self._config) diff --git a/custom_components/octopus_energy/cost_tracker/cost_tracker_month.py b/custom_components/octopus_energy/cost_tracker/cost_tracker_month.py index 1fc81eb3..6a5e4cb4 100644 --- a/custom_components/octopus_energy/cost_tracker/cost_tracker_month.py +++ b/custom_components/octopus_energy/cost_tracker/cost_tracker_month.py @@ -127,9 +127,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) # Make sure our attributes don't override any changed settings self._attributes.update(self._config) diff --git a/custom_components/octopus_energy/cost_tracker/cost_tracker_week.py b/custom_components/octopus_energy/cost_tracker/cost_tracker_week.py index 6e94027d..3b877093 100644 --- a/custom_components/octopus_energy/cost_tracker/cost_tracker_week.py +++ b/custom_components/octopus_energy/cost_tracker/cost_tracker_week.py @@ -126,9 +126,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) # Make sure our attributes don't override any changed settings self._attributes.update(self._config) diff --git a/custom_components/octopus_energy/electricity/current_accumulative_consumption.py b/custom_components/octopus_energy/electricity/current_accumulative_consumption.py index 8dc4e231..7afb33a3 100644 --- a/custom_components/octopus_energy/electricity/current_accumulative_consumption.py +++ b/custom_components/octopus_energy/electricity/current_accumulative_consumption.py @@ -153,9 +153,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/current_accumulative_cost.py b/custom_components/octopus_energy/electricity/current_accumulative_cost.py index 41f69418..0848cd43 100644 --- a/custom_components/octopus_energy/electricity/current_accumulative_cost.py +++ b/custom_components/octopus_energy/electricity/current_accumulative_cost.py @@ -160,9 +160,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/current_consumption.py b/custom_components/octopus_energy/electricity/current_consumption.py index b74986d2..e2880557 100644 --- a/custom_components/octopus_energy/electricity/current_consumption.py +++ b/custom_components/octopus_energy/electricity/current_consumption.py @@ -112,9 +112,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) if "last_updated_timestamp" in self._attributes: diff --git a/custom_components/octopus_energy/electricity/current_demand.py b/custom_components/octopus_energy/electricity/current_demand.py index c511e7c4..d9758625 100644 --- a/custom_components/octopus_energy/electricity/current_demand.py +++ b/custom_components/octopus_energy/electricity/current_demand.py @@ -91,9 +91,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) if "last_updated_timestamp" in self._attributes: diff --git a/custom_components/octopus_energy/electricity/current_interval_accumulative_consumption_.py b/custom_components/octopus_energy/electricity/current_interval_accumulative_consumption_.py index def7af26..2accac79 100644 --- a/custom_components/octopus_energy/electricity/current_interval_accumulative_consumption_.py +++ b/custom_components/octopus_energy/electricity/current_interval_accumulative_consumption_.py @@ -109,9 +109,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyCurrentElectricityIntervalAccumulativeConsumption state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/current_rate.py b/custom_components/octopus_energy/electricity/current_rate.py index cae19580..e398aeb0 100644 --- a/custom_components/octopus_energy/electricity/current_rate.py +++ b/custom_components/octopus_energy/electricity/current_rate.py @@ -156,9 +156,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyElectricityCurrentRate state: {self._state}') diff --git a/custom_components/octopus_energy/electricity/current_total_consumption.py b/custom_components/octopus_energy/electricity/current_total_consumption.py index 9e896b42..d4bde7f9 100644 --- a/custom_components/octopus_energy/electricity/current_total_consumption.py +++ b/custom_components/octopus_energy/electricity/current_total_consumption.py @@ -115,9 +115,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/next_rate.py b/custom_components/octopus_energy/electricity/next_rate.py index a59cc4cd..0913582b 100644 --- a/custom_components/octopus_energy/electricity/next_rate.py +++ b/custom_components/octopus_energy/electricity/next_rate.py @@ -129,9 +129,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyElectricityNextRate state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py index f1dd5521..6204161f 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py @@ -183,9 +183,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py index cb87c5db..bdc00945 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py @@ -181,9 +181,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py index 0ea11859..9e4c9e0b 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py @@ -197,9 +197,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyPreviousAccumulativeElectricityCostOverride state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/previous_rate.py b/custom_components/octopus_energy/electricity/previous_rate.py index c4d74b16..6641164a 100644 --- a/custom_components/octopus_energy/electricity/previous_rate.py +++ b/custom_components/octopus_energy/electricity/previous_rate.py @@ -129,9 +129,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyElectricityPreviousRate state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/electricity/standing_charge.py b/custom_components/octopus_energy/electricity/standing_charge.py index 81a7347c..e0722330 100644 --- a/custom_components/octopus_energy/electricity/standing_charge.py +++ b/custom_components/octopus_energy/electricity/standing_charge.py @@ -90,9 +90,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['valid_from', 'valid_to']) _LOGGER.debug(f'Restored OctopusEnergyElectricityCurrentStandingCharge state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_accumulative_consumption_cubic_meters.py b/custom_components/octopus_energy/gas/current_accumulative_consumption_cubic_meters.py index ee99e3d8..8b489ffb 100644 --- a/custom_components/octopus_energy/gas/current_accumulative_consumption_cubic_meters.py +++ b/custom_components/octopus_energy/gas/current_accumulative_consumption_cubic_meters.py @@ -127,9 +127,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyCurrentAccumulativeGasConsumption state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_accumulative_consumption_kwh.py b/custom_components/octopus_energy/gas/current_accumulative_consumption_kwh.py index e6e58851..3ea2940a 100644 --- a/custom_components/octopus_energy/gas/current_accumulative_consumption_kwh.py +++ b/custom_components/octopus_energy/gas/current_accumulative_consumption_kwh.py @@ -127,9 +127,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ["total"]) _LOGGER.debug(f'Restored OctopusEnergyCurrentAccumulativeGasConsumption state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_accumulative_cost.py b/custom_components/octopus_energy/gas/current_accumulative_cost.py index e21ae218..5833dcc1 100644 --- a/custom_components/octopus_energy/gas/current_accumulative_cost.py +++ b/custom_components/octopus_energy/gas/current_accumulative_cost.py @@ -138,9 +138,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyCurrentAccumulativeGasCost state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_consumption.py b/custom_components/octopus_energy/gas/current_consumption.py index fef6c0b9..e988f539 100644 --- a/custom_components/octopus_energy/gas/current_consumption.py +++ b/custom_components/octopus_energy/gas/current_consumption.py @@ -112,9 +112,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) if "last_updated_timestamp" in self._attributes: diff --git a/custom_components/octopus_energy/gas/current_rate.py b/custom_components/octopus_energy/gas/current_rate.py index 3965a389..6c9c4137 100644 --- a/custom_components/octopus_energy/gas/current_rate.py +++ b/custom_components/octopus_energy/gas/current_rate.py @@ -134,9 +134,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyGasCurrentRate state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_total_consumption_cubic_meters.py b/custom_components/octopus_energy/gas/current_total_consumption_cubic_meters.py index 9be19c9e..897be55d 100644 --- a/custom_components/octopus_energy/gas/current_total_consumption_cubic_meters.py +++ b/custom_components/octopus_energy/gas/current_total_consumption_cubic_meters.py @@ -118,9 +118,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_total_consumption_kwh.py b/custom_components/octopus_energy/gas/current_total_consumption_kwh.py index 6fad52db..16e1c6ec 100644 --- a/custom_components/octopus_energy/gas/current_total_consumption_kwh.py +++ b/custom_components/octopus_energy/gas/current_total_consumption_kwh.py @@ -118,9 +118,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/next_rate.py b/custom_components/octopus_energy/gas/next_rate.py index a98d4d67..99eb6a2d 100644 --- a/custom_components/octopus_energy/gas/next_rate.py +++ b/custom_components/octopus_energy/gas/next_rate.py @@ -123,9 +123,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyGasNextRate state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py b/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py index a8363689..983ac360 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py @@ -167,9 +167,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyPreviousAccumulativeGasConsumption state: {self._state}') diff --git a/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py b/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py index 4f0f98d9..713df8b2 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py @@ -159,9 +159,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyPreviousAccumulativeGasConsumptionKwh state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/previous_accumulative_cost.py b/custom_components/octopus_energy/gas/previous_accumulative_cost.py index 06554eb1..1f101e18 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_cost.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_cost.py @@ -164,9 +164,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyPreviousAccumulativeGasCost state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py b/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py index 4901683d..b51fe74a 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py @@ -199,9 +199,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyPreviousAccumulativeGasCostOverride state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/previous_rate.py b/custom_components/octopus_energy/gas/previous_rate.py index 157ade3c..3ae31c51 100644 --- a/custom_components/octopus_energy/gas/previous_rate.py +++ b/custom_components/octopus_energy/gas/previous_rate.py @@ -123,9 +123,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['all_rates', 'applicable_rates']) _LOGGER.debug(f'Restored OctopusEnergyGasPreviousRate state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/standing_charge.py b/custom_components/octopus_energy/gas/standing_charge.py index ae5cfa98..53d519f4 100644 --- a/custom_components/octopus_energy/gas/standing_charge.py +++ b/custom_components/octopus_energy/gas/standing_charge.py @@ -96,8 +96,9 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, ['valid_from', 'valid_to']) _LOGGER.debug(f'Restored OctopusEnergyGasCurrentStandingCharge state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/greenness_forecast/current_index.py b/custom_components/octopus_energy/greenness_forecast/current_index.py index 113a1ac8..d0c48f26 100644 --- a/custom_components/octopus_energy/greenness_forecast/current_index.py +++ b/custom_components/octopus_energy/greenness_forecast/current_index.py @@ -105,8 +105,9 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyGreennessForecastCurrentIndex state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/greenness_forecast/next_index.py b/custom_components/octopus_energy/greenness_forecast/next_index.py index eb1eba81..dde3e37a 100644 --- a/custom_components/octopus_energy/greenness_forecast/next_index.py +++ b/custom_components/octopus_energy/greenness_forecast/next_index.py @@ -99,8 +99,9 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyGreennessForecastNextIndex state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_humidity.py b/custom_components/octopus_energy/heat_pump/sensor_humidity.py index ea04da7d..bf04675c 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_humidity.py +++ b/custom_components/octopus_energy/heat_pump/sensor_humidity.py @@ -104,9 +104,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) self._attributes["type"] = self._sensor.type diff --git a/custom_components/octopus_energy/heat_pump/sensor_lifetime_energy_input.py b/custom_components/octopus_energy/heat_pump/sensor_lifetime_energy_input.py index c2135744..fe5dbcee 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_lifetime_energy_input.py +++ b/custom_components/octopus_energy/heat_pump/sensor_lifetime_energy_input.py @@ -100,9 +100,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLifetimeEnergyInput state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_lifetime_heat_output.py b/custom_components/octopus_energy/heat_pump/sensor_lifetime_heat_output.py index 9a1de051..934060bb 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_lifetime_heat_output.py +++ b/custom_components/octopus_energy/heat_pump/sensor_lifetime_heat_output.py @@ -100,9 +100,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLifetimeHeatOutput state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_lifetime_scop.py b/custom_components/octopus_energy/heat_pump/sensor_lifetime_scop.py index 31cac1e1..c807d2af 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_lifetime_scop.py +++ b/custom_components/octopus_energy/heat_pump/sensor_lifetime_scop.py @@ -85,9 +85,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLifetimeSCoP state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_live_cop.py b/custom_components/octopus_energy/heat_pump/sensor_live_cop.py index d8221255..fca9bae4 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_live_cop.py +++ b/custom_components/octopus_energy/heat_pump/sensor_live_cop.py @@ -89,9 +89,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLiveCoP state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_live_heat_output.py b/custom_components/octopus_energy/heat_pump/sensor_live_heat_output.py index e8121d67..b9a62784 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_live_heat_output.py +++ b/custom_components/octopus_energy/heat_pump/sensor_live_heat_output.py @@ -101,9 +101,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLiveHeatOutput state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_live_outdoor_temperature.py b/custom_components/octopus_energy/heat_pump/sensor_live_outdoor_temperature.py index 361af0b2..c9941354 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_live_outdoor_temperature.py +++ b/custom_components/octopus_energy/heat_pump/sensor_live_outdoor_temperature.py @@ -101,9 +101,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLiveOutdoorTemperature state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_live_power_input.py b/custom_components/octopus_energy/heat_pump/sensor_live_power_input.py index 6d43946f..da47f89c 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_live_power_input.py +++ b/custom_components/octopus_energy/heat_pump/sensor_live_power_input.py @@ -101,9 +101,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyHeatPumpSensorLivePowerInput state: {self._state}') \ No newline at end of file diff --git a/custom_components/octopus_energy/heat_pump/sensor_temperature.py b/custom_components/octopus_energy/heat_pump/sensor_temperature.py index 0d71cb22..5cc975b6 100644 --- a/custom_components/octopus_energy/heat_pump/sensor_temperature.py +++ b/custom_components/octopus_energy/heat_pump/sensor_temperature.py @@ -105,9 +105,10 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) self._attributes["type"] = self._sensor.type diff --git a/custom_components/octopus_energy/intelligent/current_state.py b/custom_components/octopus_energy/intelligent/current_state.py index 264bd788..f270413d 100644 --- a/custom_components/octopus_energy/intelligent/current_state.py +++ b/custom_components/octopus_energy/intelligent/current_state.py @@ -82,8 +82,9 @@ async def async_added_to_hass(self): # If not None, we got an initial value. await super().async_added_to_hass() state = await self.async_get_last_state() + last_sensor_state = await self.async_get_last_sensor_data() - if state is not None and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes, []) _LOGGER.debug(f'Restored OctopusEnergyIntelligentCurrentState state: {self._state}') diff --git a/custom_components/octopus_energy/octoplus/free_electricity_session_baseline.py b/custom_components/octopus_energy/octoplus/free_electricity_session_baseline.py index ad158dc9..f6f71f97 100644 --- a/custom_components/octopus_energy/octoplus/free_electricity_session_baseline.py +++ b/custom_components/octopus_energy/octoplus/free_electricity_session_baseline.py @@ -170,9 +170,10 @@ async def async_added_to_hass(self): # 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 in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + last_sensor_state = await self.async_get_last_sensor_data() + + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') diff --git a/custom_components/octopus_energy/octoplus/points.py b/custom_components/octopus_energy/octoplus/points.py index 39e2dddf..2d703d61 100644 --- a/custom_components/octopus_energy/octoplus/points.py +++ b/custom_components/octopus_energy/octoplus/points.py @@ -82,9 +82,10 @@ async def async_added_to_hass(self): # 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 and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + last_sensor_state = await self.async_get_last_sensor_data() + + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyOctoplusPoints state: {self._state}') diff --git a/custom_components/octopus_energy/octoplus/saving_session_baseline.py b/custom_components/octopus_energy/octoplus/saving_session_baseline.py index 74ce9b11..c014e9c9 100644 --- a/custom_components/octopus_energy/octoplus/saving_session_baseline.py +++ b/custom_components/octopus_energy/octoplus/saving_session_baseline.py @@ -171,9 +171,10 @@ async def async_added_to_hass(self): # 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 in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + last_sensor_state = await self.async_get_last_sensor_data() + + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored state: {self._state}') diff --git a/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py b/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py index 515af446..d2bd2751 100644 --- a/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py +++ b/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py @@ -80,9 +80,10 @@ async def async_added_to_hass(self): # 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 and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + last_sensor_state = await self.async_get_last_sensor_data() + + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyWheelOfFortuneElectricitySpins state: {self._state}') diff --git a/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py b/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py index 0b26203a..e4287d51 100644 --- a/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py +++ b/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py @@ -80,9 +80,10 @@ async def async_added_to_hass(self): # 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 and self._state is None: - self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else state.state + last_sensor_state = await self.async_get_last_sensor_data() + + if state is not None and last_sensor_state is not None and self._state is None: + self._state = None if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN) else last_sensor_state.native_value self._attributes = dict_to_typed_dict(state.attributes) _LOGGER.debug(f'Restored OctopusEnergyWheelOfFortuneGasSpins state: {self._state}')