Skip to content

Commit

Permalink
fix: Fixed issue where event entities were not being restored properly
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Nov 28, 2023
1 parent b8418e1 commit 00ec35c
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 34 deletions.
6 changes: 3 additions & 3 deletions custom_components/octopus_energy/api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
def get_valid_from(rate):
return rate["valid_from"]

def get_from(rate):
def get_start(rate):
return rate["start"]

def rates_to_thirty_minute_increments(data, period_from: datetime, period_to: datetime, tariff_code: str, price_cap: float = None):
Expand Down Expand Up @@ -626,7 +626,7 @@ async def async_get_electricity_standard_rates(self, product_code, tariff_code,
if has_more_rates:
page = page + 1

results.sort(key=get_from)
results.sort(key=get_start)
return results

async def async_get_electricity_day_night_rates(self, product_code, tariff_code, is_smart_meter, period_from, period_to):
Expand Down Expand Up @@ -659,7 +659,7 @@ async def async_get_electricity_day_night_rates(self, product_code, tariff_code,
results.append(rate)

# Because we retrieve our day and night periods separately over a 2 day period, we need to sort our rates
results.sort(key=get_from)
results.sort(key=get_start)

return results

Expand Down
2 changes: 0 additions & 2 deletions custom_components/octopus_energy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@

STORAGE_COMPLETED_DISPATCHES_NAME = "octopus_energy.{}-completed-intelligent-dispatches.json"

STORAGE_COMPLETED_DISPATCHES_NAME = "octopus_energy.{}-completed-intelligent-dispatches.json"

REGEX_HOURS = "^[0-9]+(\\.[0-9]+)*$"
REGEX_TIME = "^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$"
REGEX_ENTITY_NAME = "^[a-z0-9_]+$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ async def async_added_to_hass(self):

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""
self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
4 changes: 1 addition & 3 deletions custom_components/octopus_energy/gas/rates_current_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
4 changes: 1 addition & 3 deletions custom_components/octopus_energy/gas/rates_previous_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ async def async_added_to_hass(self):
self._attributes = dict_to_typed_dict(state.attributes)

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

async def async_added_to_hass(self) -> None:
"""Register callbacks."""

self._hass.bus.async_listen(self._attr_event_types[0], self._async_handle_event)

@callback
Expand Down

0 comments on commit 00ec35c

Please sign in to comment.