From 280e6d25fcb18ce17df158734f9cba3cd7d92574 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Fri, 17 Nov 2023 21:12:22 +0000 Subject: [PATCH] fix: removed all_rates and applicable_rates attributes from rate sensors 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 https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/discussions/444 for more information --- .../octopus_energy/electricity/current_rate.py | 16 ++++++++-------- .../octopus_energy/electricity/next_rate.py | 11 +++++++---- .../octopus_energy/electricity/previous_rate.py | 11 +++++++---- .../octopus_energy/gas/current_rate.py | 14 +++++++------- .../octopus_energy/gas/next_rate.py | 12 +++++++----- .../octopus_energy/gas/previous_rate.py | 12 +++++++----- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/custom_components/octopus_energy/electricity/current_rate.py b/custom_components/octopus_energy/electricity/current_rate.py index 964e049c..9f575cd8 100644 --- a/custom_components/octopus_energy/electricity/current_rate.py +++ b/custom_components/octopus_energy/electricity/current_rate.py @@ -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, @@ -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"] @@ -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 @@ -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}') \ 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 049ee1f8..4fda8063 100644 --- a/custom_components/octopus_energy/electricity/next_rate.py +++ b/custom_components/octopus_energy/electricity/next_rate.py @@ -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, } @@ -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"] @@ -108,7 +106,6 @@ def state(self): "is_smart_meter": self._is_smart_meter, "start": None, "end": None, - "applicable_rates": [], } self._state = None @@ -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}') \ 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 b04d9ef7..14bb1136 100644 --- a/custom_components/octopus_energy/electricity/previous_rate.py +++ b/custom_components/octopus_energy/electricity/previous_rate.py @@ -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, } @@ -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"] @@ -108,7 +106,6 @@ def state(self): "is_smart_meter": self._is_smart_meter, "start": None, "end": None, - "applicable_rates": [], } self._state = None @@ -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}') \ No newline at end of file diff --git a/custom_components/octopus_energy/gas/current_rate.py b/custom_components/octopus_energy/gas/current_rate.py index b141d983..9b6a8cb7 100644 --- a/custom_components/octopus_energy/gas/current_rate.py +++ b/custom_components/octopus_energy/gas/current_rate.py @@ -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, @@ -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"] @@ -113,8 +109,6 @@ def state(self): "start": None, "end": None, "is_capped": None, - "all_rates": [], - "applicable_rates": [], } self._state = None @@ -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}') \ 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 e552adeb..d1457692 100644 --- a/custom_components/octopus_energy/gas/next_rate.py +++ b/custom_components/octopus_energy/gas/next_rate.py @@ -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, } @@ -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"] @@ -103,7 +100,6 @@ def state(self): "is_smart_meter": self._is_smart_meter, "start": None, "end": None, - "applicable_rates": [], } self._state = None @@ -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}') \ 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 2cb2960f..d8cc01d7 100644 --- a/custom_components/octopus_energy/gas/previous_rate.py +++ b/custom_components/octopus_energy/gas/previous_rate.py @@ -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, } @@ -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"] @@ -103,7 +100,6 @@ def state(self): "is_smart_meter": self._is_smart_meter, "start": None, "end": None, - "applicable_rates": [], } self._state = None @@ -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}') \ No newline at end of file