Skip to content

Commit

Permalink
fix(sensor): Fixed rate sensors to update on the half hour
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Mar 2, 2023
1 parent 8685aef commit 2e2d795
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/octopus_energy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def state(self):
"""The state of the sensor."""
# Find the current rate. We only need to do this every half an hour
now = utcnow()
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30))):
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30)) or (now.minute % 30) == 0):
_LOGGER.debug(f"Updating OctopusEnergyElectricityCurrentRate for '{self._mpan}/{self._serial_number}'")

current_rate = None
Expand Down Expand Up @@ -381,7 +381,7 @@ def state(self):
"""The state of the sensor."""
# Find the previous rate. We only need to do this every half an hour
now = utcnow()
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30))):
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30)) or (now.minute % 30) == 0):
_LOGGER.debug(f"Updating OctopusEnergyElectricityPreviousRate for '{self._mpan}/{self._serial_number}'")

target = now - timedelta(minutes=30)
Expand Down Expand Up @@ -472,7 +472,7 @@ def state(self):
"""The state of the sensor."""
# Find the next rate. We only need to do this every half an hour
now = utcnow()
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30))):
if (self._last_updated is None or self._last_updated < (now - timedelta(minutes=30)) or (now.minute % 30) == 0):
_LOGGER.debug(f"Updating OctopusEnergyElectricityNextRate for '{self._mpan}/{self._serial_number}'")

target = now + timedelta(minutes=30)
Expand Down

0 comments on commit 2e2d795

Please sign in to comment.