From 11f887815eec47c3665e0bb36641ac36da036427 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Sat, 18 Nov 2023 17:24:49 +0000 Subject: [PATCH] feat: Added two new attributes to various sensors determining when the underlying data was last retrieved and when the value was last evaluated. These will slowly be added to other entities. --- .../electricity/current_consumption.py | 6 ++-- .../electricity/current_demand.py | 4 +-- .../electricity/current_rate.py | 16 ++++++---- .../octopus_energy/electricity/next_rate.py | 16 ++++++---- .../electricity/previous_rate.py | 16 ++++++---- .../octopus_energy/gas/current_consumption.py | 6 ++-- .../octopus_energy/gas/current_rate.py | 16 ++++++---- .../octopus_energy/gas/next_rate.py | 16 ++++++---- .../octopus_energy/gas/previous_rate.py | 16 ++++++---- .../octopus_energy/intelligent/bump_charge.py | 7 ++++- .../intelligent/charge_limit.py | 6 ++-- .../octopus_energy/intelligent/dispatching.py | 9 +++--- .../octopus_energy/intelligent/ready_time.py | 6 ++-- .../intelligent/smart_charge.py | 5 +++- .../octopus_energy/octoplus/points.py | 3 +- .../octoplus/saving_sessions.py | 29 ++++++++++++------- .../wheel_of_fortune/electricity_spins.py | 6 ++-- .../wheel_of_fortune/gas_spins.py | 4 ++- 18 files changed, 124 insertions(+), 63 deletions(-) diff --git a/custom_components/octopus_energy/electricity/current_consumption.py b/custom_components/octopus_energy/electricity/current_consumption.py index 68bc3079..98284bdf 100644 --- a/custom_components/octopus_energy/electricity/current_consumption.py +++ b/custom_components/octopus_energy/electricity/current_consumption.py @@ -34,7 +34,7 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): self._latest_date = None self._previous_total_consumption = None self._attributes = { - "last_updated_timestamp": None + "last_evaluated": None } @property @@ -88,11 +88,11 @@ def state(self): total_consumption = get_total_consumption(consumption_result) self._state = get_current_consumption_delta(current_date, total_consumption, - self._attributes["last_updated_timestamp"] if self._attributes["last_updated_timestamp"] is not None else current_date, + self._attributes["last_evaluated"] if self._attributes["last_evaluated"] is not None else current_date, self._previous_total_consumption) if (self._state is not None): self._latest_date = current_date - self._attributes["last_updated_timestamp"] = current_date + self._attributes["last_evaluated"] = current_date # Store the total consumption ready for the next run self._previous_total_consumption = total_consumption diff --git a/custom_components/octopus_energy/electricity/current_demand.py b/custom_components/octopus_energy/electricity/current_demand.py index 5d311030..9599cfaf 100644 --- a/custom_components/octopus_energy/electricity/current_demand.py +++ b/custom_components/octopus_energy/electricity/current_demand.py @@ -28,7 +28,7 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): self._state = None self._latest_date = None self._attributes = { - "last_updated_timestamp": None + "last_evaluated": None } @property @@ -74,7 +74,7 @@ def state(self): if (consumption_result is not None): self._state = consumption_result[-1]["demand"] - self._attributes["last_updated_timestamp"] = now() + self._attributes["last_evaluated"] = now() return self._state diff --git a/custom_components/octopus_energy/electricity/current_rate.py b/custom_components/octopus_energy/electricity/current_rate.py index 9f575cd8..29be32d6 100644 --- a/custom_components/octopus_energy/electricity/current_rate.py +++ b/custom_components/octopus_energy/electricity/current_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -15,6 +15,7 @@ from .base import (OctopusEnergyElectricitySensor) from ..utils.attributes import dict_to_typed_dict +from ..coordinators.electricity_rates import ElectricityRatesCoordinatorResult from ..utils.rate_information import (get_current_rate_information) @@ -88,12 +89,12 @@ def extra_state_attributes(self): def state(self): """Retrieve the current rate for the sensor.""" # Find the current rate. We only need to do this every half an hour - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: ElectricityRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyElectricityCurrentRate for '{self._mpan}/{self._serial_number}'") - rate_information = get_current_rate_information(rates, current) + rate_information = get_current_rate_information(rates_result.rates, current) if rate_information is not None: self._attributes = { @@ -135,6 +136,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/electricity/next_rate.py b/custom_components/octopus_energy/electricity/next_rate.py index 4fda8063..6eb5d27f 100644 --- a/custom_components/octopus_energy/electricity/next_rate.py +++ b/custom_components/octopus_energy/electricity/next_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity ) @@ -16,6 +16,7 @@ from .base import (OctopusEnergyElectricitySensor) from ..utils.attributes import dict_to_typed_dict from ..utils.rate_information import (get_next_rate_information) +from ..coordinators.electricity_rates import ElectricityRatesCoordinatorResult _LOGGER = logging.getLogger(__name__) @@ -79,13 +80,13 @@ def extra_state_attributes(self): def state(self): """Retrieve the next rate for the sensor.""" # Find the next rate. We only need to do this every half an hour - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: ElectricityRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyElectricityNextRate for '{self._mpan}/{self._serial_number}'") target = current - rate_information = get_next_rate_information(rates, target) + rate_information = get_next_rate_information(rates_result.rates, target) if rate_information is not None: self._attributes = { @@ -112,6 +113,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/electricity/previous_rate.py b/custom_components/octopus_energy/electricity/previous_rate.py index 14bb1136..f59fe359 100644 --- a/custom_components/octopus_energy/electricity/previous_rate.py +++ b/custom_components/octopus_energy/electricity/previous_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity ) @@ -16,6 +16,7 @@ from .base import (OctopusEnergyElectricitySensor) from ..utils.attributes import dict_to_typed_dict from ..utils.rate_information import (get_previous_rate_information) +from ..coordinators.electricity_rates import ElectricityRatesCoordinatorResult _LOGGER = logging.getLogger(__name__) @@ -79,13 +80,13 @@ def extra_state_attributes(self): def state(self): """Retrieve the previous rate.""" # Find the previous rate. We only need to do this every half an hour - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: ElectricityRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyElectricityPreviousRate for '{self._mpan}/{self._serial_number}'") target = current - rate_information = get_previous_rate_information(rates, target) + rate_information = get_previous_rate_information(rates_result.rates, target) if rate_information is not None: self._attributes = { @@ -112,6 +113,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/gas/current_consumption.py b/custom_components/octopus_energy/gas/current_consumption.py index d9be0a4b..482ffb6e 100644 --- a/custom_components/octopus_energy/gas/current_consumption.py +++ b/custom_components/octopus_energy/gas/current_consumption.py @@ -34,7 +34,7 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): self._latest_date = None self._previous_total_consumption = None self._attributes = { - "last_updated_timestamp": None + "last_evaluated": None } @property @@ -88,11 +88,11 @@ def state(self): total_consumption = get_total_consumption(consumption_result) self._state = get_current_consumption_delta(current_date, total_consumption, - self._attributes["last_updated_timestamp"] if self._attributes["last_updated_timestamp"] is not None else current_date, + self._attributes["last_evaluated"] if self._attributes["last_evaluated"] is not None else current_date, self._previous_total_consumption) if (self._state is not None): self._latest_date = current_date - self._attributes["last_updated_timestamp"] = current_date + self._attributes["last_evaluated"] = current_date # Store the total consumption ready for the next run self._previous_total_consumption = total_consumption diff --git a/custom_components/octopus_energy/gas/current_rate.py b/custom_components/octopus_energy/gas/current_rate.py index 9b6a8cb7..2927348f 100644 --- a/custom_components/octopus_energy/gas/current_rate.py +++ b/custom_components/octopus_energy/gas/current_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -16,6 +16,7 @@ from .base import (OctopusEnergyGasSensor) from ..utils.attributes import dict_to_typed_dict from ..utils.rate_information import get_current_rate_information +from ..coordinators.gas_rates import GasRatesCoordinatorResult _LOGGER = logging.getLogger(__name__) @@ -81,12 +82,12 @@ def extra_state_attributes(self): @property def state(self): """Retrieve the current rate for the sensor.""" - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: GasRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyGasCurrentRate for '{self._mprn}/{self._serial_number}'") - rate_information = get_current_rate_information(rates, current) + rate_information = get_current_rate_information(rates_result.rates, current) if rate_information is not None: self._attributes = { @@ -118,6 +119,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/gas/next_rate.py b/custom_components/octopus_energy/gas/next_rate.py index d1457692..363e7eea 100644 --- a/custom_components/octopus_energy/gas/next_rate.py +++ b/custom_components/octopus_energy/gas/next_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -16,6 +16,7 @@ from .base import (OctopusEnergyGasSensor) from ..utils.attributes import dict_to_typed_dict from ..utils.rate_information import get_next_rate_information +from ..coordinators.gas_rates import GasRatesCoordinatorResult _LOGGER = logging.getLogger(__name__) @@ -76,12 +77,12 @@ def extra_state_attributes(self): @property def state(self): """Retrieve the next rate for the sensor.""" - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: GasRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyGasNextRate for '{self._mprn}/{self._serial_number}'") - rate_information = get_next_rate_information(rates, current) + rate_information = get_next_rate_information(rates_result.rates, current) if rate_information is not None: self._attributes = { @@ -106,6 +107,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/gas/previous_rate.py b/custom_components/octopus_energy/gas/previous_rate.py index d8cc01d7..0cafbd62 100644 --- a/custom_components/octopus_energy/gas/previous_rate.py +++ b/custom_components/octopus_energy/gas/previous_rate.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -16,6 +16,7 @@ from .base import (OctopusEnergyGasSensor) from ..utils.attributes import dict_to_typed_dict from ..utils.rate_information import get_previous_rate_information +from ..coordinators.gas_rates import GasRatesCoordinatorResult _LOGGER = logging.getLogger(__name__) @@ -76,12 +77,12 @@ def extra_state_attributes(self): @property def state(self): """Retrieve the previous rate for the sensor.""" - current = now() - rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None - if (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0): + current = utcnow() + rates_result: GasRatesCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None + if (rates_result is not None and (self._last_updated is None or self._last_updated < (current - timedelta(minutes=30)) or (current.minute % 30) == 0)): _LOGGER.debug(f"Updating OctopusEnergyGasPreviousRate for '{self._mprn}/{self._serial_number}'") - rate_information = get_previous_rate_information(rates, current) + rate_information = get_previous_rate_information(rates_result.rates, current) if rate_information is not None: self._attributes = { @@ -106,6 +107,11 @@ def state(self): self._last_updated = current + if rates_result is not None: + self._attributes["data_last_retrieved"] = rates_result.last_retrieved + + self._attributes["last_evaluated"] = current + return self._state async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/intelligent/bump_charge.py b/custom_components/octopus_energy/intelligent/bump_charge.py index c41ac71f..9ece82e7 100644 --- a/custom_components/octopus_energy/intelligent/bump_charge.py +++ b/custom_components/octopus_energy/intelligent/bump_charge.py @@ -59,8 +59,13 @@ def is_on(self): result: IntelligentDispatchesCoordinatorResult = self.coordinator.data if self.coordinator is not None else None if result is None or (self._last_updated is not None and self._last_updated > result.last_retrieved): return self._state + + if result is not None: + self._attributes["data_last_retrieved"] = result.last_retrieved - self._state = is_in_bump_charge(utcnow(), result.dispatches.planned) + current_date = utcnow() + self._state = is_in_bump_charge(current_date, result.dispatches.planned) + self._attributes["last_evaluated"] = current_date return self._state diff --git a/custom_components/octopus_energy/intelligent/charge_limit.py b/custom_components/octopus_energy/intelligent/charge_limit.py index be1af75e..22539a58 100644 --- a/custom_components/octopus_energy/intelligent/charge_limit.py +++ b/custom_components/octopus_energy/intelligent/charge_limit.py @@ -69,11 +69,13 @@ def native_value(self) -> float: """The value of the charge limit.""" settings_result: IntelligentCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None if settings_result is None or (self._last_updated is not None and self._last_updated > settings_result.last_retrieved): - self._attributes["last_updated_timestamp"] = self._last_updated return self._state - self._attributes["last_updated_timestamp"] = settings_result.last_retrieved + if settings_result is not None: + self._attributes["data_last_retrieved"] = settings_result.last_retrieved + self._state = settings_result.settings.charge_limit_weekday + self._attributes["last_evaluated"] = utcnow() return self._state diff --git a/custom_components/octopus_energy/intelligent/dispatching.py b/custom_components/octopus_energy/intelligent/dispatching.py index 9faf18a4..39f0759e 100644 --- a/custom_components/octopus_energy/intelligent/dispatching.py +++ b/custom_components/octopus_energy/intelligent/dispatching.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import generate_entity_id -from homeassistant.util.dt import (now) +from homeassistant.util.dt import (now, utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity ) @@ -41,7 +41,7 @@ def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, mpan: st self._attributes = { "planned_dispatches": [], "completed_dispatches": [], - "last_updated_timestamp": None, + "last_evaluated": None, "vehicle_battery_size_in_kwh": device["vehicleBatterySizeInKwh"], "charge_point_power_in_kw": device["chargePointPowerInKw"] } @@ -76,13 +76,14 @@ def is_on(self): if (result is not None): self._attributes["planned_dispatches"] = dispatches_to_dictionary_list(result.dispatches.planned) self._attributes["completed_dispatches"] = dispatches_to_dictionary_list(result.dispatches.completed) - self._attributes["last_updated_timestamp"] = result.last_retrieved + self._attributes["data_last_retrieved"] = result.last_retrieved else: self._attributes["planned_dispatches"] = [] self._attributes["completed_dispatches"] = [] - current_date = now() + current_date = utcnow() self._state = is_in_planned_dispatch(current_date, result.dispatches.planned) or is_off_peak(current_date, rates) + self._attributes["last_evaluated"] = current_date return self._state diff --git a/custom_components/octopus_energy/intelligent/ready_time.py b/custom_components/octopus_energy/intelligent/ready_time.py index fdf13bbf..5fce9713 100644 --- a/custom_components/octopus_energy/intelligent/ready_time.py +++ b/custom_components/octopus_energy/intelligent/ready_time.py @@ -58,11 +58,13 @@ def native_value(self) -> time: """The time that the car should be ready by.""" settings_result: IntelligentCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None if settings_result is None or (self._last_updated is not None and self._last_updated > settings_result.last_retrieved): - self._attributes["last_updated_timestamp"] = self._last_updated return self._state + + if settings_result is not None: + self._attributes["data_last_retrieved"] = settings_result.last_retrieved - self._attributes["last_updated_timestamp"] = settings_result.last_retrieved self._state = settings_result.settings.ready_time_weekday + self._attributes["last_evaluated"] = utcnow() return self._state diff --git a/custom_components/octopus_energy/intelligent/smart_charge.py b/custom_components/octopus_energy/intelligent/smart_charge.py index 9de06e93..d1c25c97 100644 --- a/custom_components/octopus_energy/intelligent/smart_charge.py +++ b/custom_components/octopus_energy/intelligent/smart_charge.py @@ -57,10 +57,13 @@ def is_on(self): """Determines if smart charge is currently on.""" settings_result: IntelligentCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None if settings_result is None or (self._last_updated is not None and self._last_updated > settings_result.last_retrieved): - self._attributes["last_updated_timestamp"] = self._last_updated return self._state + + if settings_result is not None: + self._attributes["data_last_retrieved"] = settings_result.last_retrieved self._state = settings_result.settings.smart_charge + self._attributes["last_evaluated"] = utcnow() return self._state diff --git a/custom_components/octopus_energy/octoplus/points.py b/custom_components/octopus_energy/octoplus/points.py index c79b203a..6a9d7d88 100644 --- a/custom_components/octopus_energy/octoplus/points.py +++ b/custom_components/octopus_energy/octoplus/points.py @@ -64,7 +64,8 @@ async def async_update(self): if self._last_evaluated is None or self._last_evaluated + timedelta(minutes=30) < now: self._state = await self._client.async_get_octoplus_points() self._last_evaluated = now - + + self._attributes["data_last_retrieved"] = self._last_evaluated self._attributes["last_evaluated"] = self._last_evaluated async def async_added_to_hass(self): diff --git a/custom_components/octopus_energy/octoplus/saving_sessions.py b/custom_components/octopus_energy/octoplus/saving_sessions.py index b5151b50..384bee74 100644 --- a/custom_components/octopus_energy/octoplus/saving_sessions.py +++ b/custom_components/octopus_energy/octoplus/saving_sessions.py @@ -1,9 +1,9 @@ import logging -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import generate_entity_id +from homeassistant.util.dt import (utcnow) -from homeassistant.util.dt import (now) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity ) @@ -39,7 +39,9 @@ def __init__(self, hass: HomeAssistant, coordinator, account_id: str): "current_joined_event_duration_in_minutes": None, "next_joined_event_start": None, "next_joined_event_end": None, - "next_joined_event_duration_in_minutes": None + "next_joined_event_duration_in_minutes": None, + "data_last_retrieved": None, + "last_evaluated": None } self.entity_id = generate_entity_id("binary_sensor.{}", self.unique_id, hass=hass) @@ -67,22 +69,25 @@ def extra_state_attributes(self): @property def is_on(self): """Determine if the user is in a saving session.""" - saving_session: SavingSessionsCoordinatorResult = self.coordinator.data if self.coordinator is not None else None - if (saving_session is not None): - self._events = saving_session.joined_events - else: - self._events = [] - self._attributes = { "current_joined_event_start": None, "current_joined_event_end": None, "current_joined_event_duration_in_minutes": None, "next_joined_event_start": None, "next_joined_event_end": None, - "next_joined_event_duration_in_minutes": None + "next_joined_event_duration_in_minutes": None, + "data_last_retrieved": None, + "last_evaluated": None } - current_date = now() + saving_session: SavingSessionsCoordinatorResult = self.coordinator.data if self.coordinator is not None else None + if (saving_session is not None): + self._events = saving_session.joined_events + self._attributes["data_last_retrieved"] = saving_session.last_retrieved + else: + self._events = [] + + current_date = utcnow() current_event = current_saving_sessions_event(current_date, self._events) if (current_event is not None): self._state = True @@ -98,6 +103,8 @@ def is_on(self): self._attributes["next_joined_event_end"] = next_event.end self._attributes["next_joined_event_duration_in_minutes"] = next_event.duration_in_minutes + self._attributes["last_evaluated"] = current_date + return self._state async def async_added_to_hass(self): 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 331e60e3..12b82875 100644 --- a/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py +++ b/custom_components/octopus_energy/wheel_of_fortune/electricity_spins.py @@ -2,6 +2,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import generate_entity_id +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -63,8 +64,9 @@ def state(self): result: WheelOfFortuneSpinsCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None if result is not None: self._state = result.spins.electricity - self._attributes["last_evaluated"] = result.last_retrieved - + self._attributes["data_last_retrieved"] = result.last_retrieved + + self._attributes["last_evaluated"] = utcnow() return self._state async def async_added_to_hass(self): 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 d3575c07..6bc972ba 100644 --- a/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py +++ b/custom_components/octopus_energy/wheel_of_fortune/gas_spins.py @@ -2,6 +2,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import generate_entity_id +from homeassistant.util.dt import (utcnow) from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, ) @@ -63,8 +64,9 @@ def state(self): result: WheelOfFortuneSpinsCoordinatorResult = self.coordinator.data if self.coordinator is not None and self.coordinator.data is not None else None if result is not None: self._state = result.spins.gas - self._attributes["last_evaluated"] = result.last_retrieved + self._attributes["data_last_retrieved"] = result.last_retrieved + self._attributes["last_evaluated"] = utcnow() return self._state async def async_added_to_hass(self):