Skip to content

Commit

Permalink
fix: removed all_rates and applicable_rates attributes from rate sens…
Browse files Browse the repository at this point in the history
…ors to fix statistics warning

BREAKING CHANGE:
all_rates and applicable_rates attributes are no longer accessible in rate sensors. All rate
information is available in the events attribute. See
#444 for more information
  • Loading branch information
BottlecapDave committed Nov 17, 2023
1 parent 0cf90d3 commit 280e6d2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 33 deletions.
16 changes: 8 additions & 8 deletions custom_components/octopus_energy/electricity/current_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point, tariff_code,
"is_export": self._is_export,
"is_smart_meter": self._is_smart_meter,
"tariff": self._tariff_code,
"all_rates": [],
"applicable_rates": [],
"start": None,
"end": None,
"is_capped": None,
Expand Down Expand Up @@ -111,8 +109,6 @@ def state(self):
"current_day_min_rate": rate_information["min_rate_today"],
"current_day_max_rate": rate_information["max_rate_today"],
"current_day_average_rate": rate_information["average_rate_today"],
"all_rates": rate_information["all_rates"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["current_rate"]["value_inc_vat"]
Expand All @@ -129,9 +125,7 @@ def state(self):
"is_intelligent_adjusted": None,
"current_day_min_rate": None,
"current_day_max_rate": None,
"current_day_average_rate": None,
"all_rates": [],
"applicable_rates": [],
"current_day_average_rate": None
}

self._state = None
Expand All @@ -151,6 +145,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

_LOGGER.debug(f'Restored OctopusEnergyElectricityCurrentRate state: {self._state}')
11 changes: 7 additions & 4 deletions custom_components/octopus_energy/electricity/next_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"serial_number": self._serial_number,
"is_export": self._is_export,
"is_smart_meter": self._is_smart_meter,
"applicable_rates": [],
"start": None,
"end": None,
}
Expand Down Expand Up @@ -96,7 +95,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": rate_information["next_rate"]["start"],
"end": rate_information["next_rate"]["end"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["next_rate"]["value_inc_vat"]
Expand All @@ -108,7 +106,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": None,
"end": None,
"applicable_rates": [],
}

self._state = None
Expand All @@ -125,6 +122,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

_LOGGER.debug(f'Restored OctopusEnergyElectricityNextRate state: {self._state}')
11 changes: 7 additions & 4 deletions custom_components/octopus_energy/electricity/previous_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"serial_number": self._serial_number,
"is_export": self._is_export,
"is_smart_meter": self._is_smart_meter,
"applicable_rates": [],
"start": None,
"end": None,
}
Expand Down Expand Up @@ -96,7 +95,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": rate_information["previous_rate"]["start"],
"end": rate_information["previous_rate"]["end"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["previous_rate"]["value_inc_vat"]
Expand All @@ -108,7 +106,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": None,
"end": None,
"applicable_rates": [],
}

self._state = None
Expand All @@ -125,6 +122,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

_LOGGER.debug(f'Restored OctopusEnergyElectricityPreviousRate state: {self._state}')
14 changes: 7 additions & 7 deletions custom_components/octopus_energy/gas/current_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point,
"serial_number": self._serial_number,
"is_smart_meter": self._is_smart_meter,
"tariff": self._tariff_code,
"all_rates": [],
"applicable_rates": [],
"start": None,
"end": None,
"is_capped": None,
Expand Down Expand Up @@ -99,8 +97,6 @@ def state(self):
"start": rate_information["current_rate"]["start"],
"end": rate_information["current_rate"]["end"],
"is_capped": rate_information["current_rate"]["is_capped"],
"all_rates": rate_information["all_rates"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["current_rate"]["value_inc_vat"]
Expand All @@ -113,8 +109,6 @@ def state(self):
"start": None,
"end": None,
"is_capped": None,
"all_rates": [],
"applicable_rates": [],
}

self._state = None
Expand All @@ -134,6 +128,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

_LOGGER.debug(f'Restored OctopusEnergyGasCurrentRate state: {self._state}')
12 changes: 7 additions & 5 deletions custom_components/octopus_energy/gas/next_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"mprn": self._mprn,
"serial_number": self._serial_number,
"is_smart_meter": self._is_smart_meter,
"all_rates": [],
"applicable_rates": [],
"start": None,
"end": None,
}
Expand Down Expand Up @@ -92,7 +90,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": rate_information["next_rate"]["start"],
"end": rate_information["next_rate"]["end"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["next_rate"]["value_inc_vat"]
Expand All @@ -103,7 +100,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": None,
"end": None,
"applicable_rates": [],
}

self._state = None
Expand All @@ -120,6 +116,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

_LOGGER.debug(f'Restored OctopusEnergyGasNextRate state: {self._state}')
12 changes: 7 additions & 5 deletions custom_components/octopus_energy/gas/previous_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point):
"mprn": self._mprn,
"serial_number": self._serial_number,
"is_smart_meter": self._is_smart_meter,
"all_rates": [],
"applicable_rates": [],
"start": None,
"end": None,
}
Expand Down Expand Up @@ -92,7 +90,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": rate_information["previous_rate"]["start"],
"end": rate_information["previous_rate"]["end"],
"applicable_rates": rate_information["applicable_rates"],
}

self._state = rate_information["previous_rate"]["value_inc_vat"]
Expand All @@ -103,7 +100,6 @@ def state(self):
"is_smart_meter": self._is_smart_meter,
"start": None,
"end": None,
"applicable_rates": [],
}

self._state = None
Expand All @@ -120,6 +116,12 @@ async def async_added_to_hass(self):

if state is not None and self._state is None:
self._state = state.state
self._attributes = dict_to_typed_dict(state.attributes)
self._attributes = {}
temp_attributes = dict_to_typed_dict(state.attributes)
for x in temp_attributes.keys():
if x in ['all_rates', 'applicable_rates']:
continue

self._attributes[x] = state.attributes[x]

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

0 comments on commit 280e6d2

Please sign in to comment.