Skip to content

Commit 1dca50b

Browse files
committed
feat: Added repair notice when no rates are retrievable (1.5 hours dev time)
1 parent ae0b73d commit 1dca50b

File tree

9 files changed

+797
-44
lines changed

9 files changed

+797
-44
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Repairs - Tariff Rates Empty
2+
3+
If you have received this repair notice, it means you have one or more meters associated with a tariff that no longer appears to be returning up to date rate information.
4+
5+
This can be confirmed by looking at the rate feed. For example if you have tariff 'G-1R-SILVER-25-09-02-M' and product 'SILVER-25-09-02', then for electricity you can find the rates at https://api.octopus.energy/v1/products/SILVER-25-09-02/electricity-tariffs/E-1R-SILVER-25-09-02-A/standard-unit-rates/ and for gas you can find the rates at https://api.octopus.energy/v1/products/SILVER-25-09-02/gas-tariffs/G-1R-SILVER-25-09-02-A/standard-unit-rates/. If the first record has an "valid_to" value that isn't "null" and in the past, then new rates are no longer being published.
6+
7+
This can occur for a number of reasons
8+
9+
1. Your tariff has finished but you haven't been moved to a new tariff for some reason.
10+
2. There is an issue with the rate feed. This might be a short term issue with the Octopus Energy servers, so waiting my rectify the issue.
11+
12+
To rectify all of these issues, you will need to contact Octopus Energy to fix this issue.

custom_components/octopus_energy/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
REPAIR_TARGET_RATE_REMOVAL_PROPOSAL = "target_rate_removal_proposal"
214214
REPAIR_INTELLIGENT_DEVICE_NOT_FOUND = "intelligent_device_not_found_{}"
215215
REPAIR_INTELLIGENT_DEVICE_CHANGED = "intelligent_device_changed_{}"
216+
REPAIR_TARIFF_RATES_EMPTY = "tariff_rates_empty_{}_{}"
216217

217218
# During BST, two records are returned before the rest of the data is available
218219
MINIMUM_CONSUMPTION_DATA_LENGTH = 3

custom_components/octopus_energy/coordinators/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
import logging
33
from typing import Callable, Any
44

5+
from custom_components.octopus_energy.const import DOMAIN, REPAIR_TARIFF_RATES_EMPTY
6+
from custom_components.octopus_energy.utils.repairs import safe_repair_key
57
from homeassistant.helpers.update_coordinator import (
68
CoordinatorEntity,
79
)
810
from homeassistant.util.dt import (as_utc)
11+
from homeassistant.helpers import issue_registry as ir
12+
913

1014
from ..utils import (
15+
Tariff,
1116
get_active_tariff
1217
)
1318
from ..utils.rate_information import get_min_max_average_rates
@@ -128,4 +133,19 @@ def combine_rates(old_rates: list | None, new_rates: list | None, period_from: d
128133

129134
combined_rates.sort(key=lambda x: x["start"])
130135

131-
return combined_rates
136+
return combined_rates
137+
138+
def raise_rates_empty(hass, account_id: str, tariff: Tariff, mprn_mpan: str, serial_number: str, is_electricity: bool):
139+
ir.async_create_issue(
140+
hass,
141+
DOMAIN,
142+
safe_repair_key(REPAIR_TARIFF_RATES_EMPTY, account_id, tariff.code),
143+
is_fixable=False,
144+
severity=ir.IssueSeverity.WARNING,
145+
learn_more_url="https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/repairs/tariff_rates_empty",
146+
translation_key="tariff_rates_empty",
147+
translation_placeholders={ "account_id": account_id, "product_code": tariff.product, "tariff_code": tariff.code, "product_code": tariff.product, "mprn_mpan": mprn_mpan, "serial_number": serial_number, "meter_type": "electricity" if is_electricity else "gas" },
148+
)
149+
150+
def clear_rates_empty(hass, account_id: str, tariff: Tariff):
151+
ir.async_delete_issue(hass, DOMAIN, safe_repair_key(REPAIR_TARIFF_RATES_EMPTY, account_id, tariff.code))

custom_components/octopus_energy/coordinators/electricity_rates.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..api_client import ApiException, OctopusEnergyApiClient
3131
from ..coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult
3232
from ..utils import Tariff, private_rates_to_public_rates
33-
from . import BaseCoordinatorResult, combine_rates, get_electricity_meter_tariff, raise_rate_events
33+
from . import BaseCoordinatorResult, clear_rates_empty, combine_rates, get_electricity_meter_tariff, raise_rate_events, raise_rates_empty
3434
from ..intelligent import adjust_intelligent_rates, is_intelligent_product
3535
from ..utils.rate_information import get_unique_rates, has_peak_rates
3636
from ..utils.tariff_cache import async_save_cached_tariff_total_unique_rates
@@ -67,7 +67,9 @@ async def async_refresh_electricity_rates_data(
6767
unique_rates_changed: Callable[[Tariff, int], Awaitable[None]] = None,
6868
raise_no_active_rate: Callable[[], Awaitable[None]] = None,
6969
remove_no_active_rate: Callable[[], Awaitable[None]] = None,
70-
intelligent_rate_mode: str = CONFIG_MAIN_INTELLIGENT_RATE_MODE_PENDING_AND_STARTED_DISPATCHES
70+
intelligent_rate_mode: str = CONFIG_MAIN_INTELLIGENT_RATE_MODE_PENDING_AND_STARTED_DISPATCHES,
71+
raise_rates_empty: Callable[[Tariff], None] = None,
72+
clear_rates_empty: Callable[[Tariff], None] = None
7173
) -> ElectricityRatesCoordinatorResult:
7274
if (account_info is not None):
7375
period_from = as_utc((current - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0))
@@ -115,6 +117,11 @@ async def async_refresh_electricity_rates_data(
115117

116118
if new_rates is not None:
117119
_LOGGER.debug(f'Electricity rates retrieved for {target_mpan}/{target_serial_number} ({tariff.code});')
120+
121+
if len(new_rates) == 0 and raise_rates_empty is not None:
122+
raise_rates_empty(tariff)
123+
elif clear_rates_empty is not None:
124+
clear_rates_empty(tariff)
118125

119126
original_rates = new_rates.copy()
120127
original_rates.sort(key=lambda rate: (rate["start"].timestamp(), rate["start"].fold))
@@ -294,7 +301,9 @@ async def async_update_electricity_rates_data():
294301
lambda tariff, total_unique_rates: async_update_unique_rates(hass, account_id, tariff, total_unique_rates),
295302
lambda: async_raise_no_active_tariff(hass, account_id, target_mpan, target_serial_number),
296303
lambda: async_remove_no_active_tariff(hass, target_mpan, target_serial_number),
297-
intelligent_rate_mode
304+
intelligent_rate_mode,
305+
lambda tariff: raise_rates_empty(hass, account_id, tariff, target_mpan, target_serial_number, True),
306+
lambda tariff: clear_rates_empty(hass, account_id, tariff)
298307
)
299308

300309
return hass.data[DOMAIN][account_id][key]

custom_components/octopus_energy/coordinators/gas_rates.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
)
2323

2424
from ..api_client import ApiException, OctopusEnergyApiClient
25-
from ..utils import private_rates_to_public_rates
26-
from . import BaseCoordinatorResult, combine_rates, get_gas_meter_tariff, raise_rate_events
25+
from ..utils import Tariff, private_rates_to_public_rates
26+
from . import BaseCoordinatorResult, clear_rates_empty, combine_rates, get_gas_meter_tariff, raise_rate_events, raise_rates_empty
2727
from ..utils.repairs import safe_repair_key
2828

2929
_LOGGER = logging.getLogger(__name__)
@@ -44,7 +44,9 @@ async def async_refresh_gas_rates_data(
4444
existing_rates_result: GasRatesCoordinatorResult,
4545
fire_event: Callable[[str, "dict[str, Any]"], None],
4646
raise_no_active_rate: Callable[[], None] = None,
47-
remove_no_active_rate: Callable[[], None] = None
47+
remove_no_active_rate: Callable[[], None] = None,
48+
raise_rates_empty: Callable[[Tariff], None] = None,
49+
clear_rates_empty: Callable[[Tariff], None] = None
4850
) -> GasRatesCoordinatorResult:
4951
if (account_info is not None):
5052
period_from = as_utc((current - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0))
@@ -95,6 +97,11 @@ async def async_refresh_gas_rates_data(
9597
if new_rates is not None:
9698
_LOGGER.debug(f'Gas rates retrieved for {target_mprn}/{target_serial_number} ({tariff.code});')
9799

100+
if new_rates is not None and len(new_rates) == 0 and raise_rates_empty is not None:
101+
raise_rates_empty(tariff)
102+
elif clear_rates_empty is not None:
103+
clear_rates_empty(tariff)
104+
98105
raise_rate_events(current,
99106
private_rates_to_public_rates(new_rates),
100107
{ "mprn": target_mprn, "serial_number": target_serial_number, "tariff_code": tariff.code },
@@ -168,7 +175,9 @@ async def async_update_gas_rates_data():
168175
rates,
169176
hass.bus.async_fire,
170177
lambda: async_raise_no_active_tariff(hass, account_id, target_mprn, target_serial_number),
171-
lambda: async_remove_no_active_tariff(hass, target_mprn, target_serial_number)
178+
lambda: async_remove_no_active_tariff(hass, target_mprn, target_serial_number),
179+
lambda tariff: raise_rates_empty(hass, account_id, tariff, target_mprn, target_serial_number, False),
180+
lambda tariff: clear_rates_empty(hass, account_id, tariff)
172181
)
173182

174183
return hass.data[DOMAIN][account_id][key]

custom_components/octopus_energy/translations/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@
407407
"meter_added": {
408408
"title": "{meter_type} meter added for {account_id} ({mprn_mpan}/{serial_number})",
409409
"description": "A new meter has been found for your account which has an active tariff. Please reload the integration to start using this meter and associated entities."
410+
},
411+
"tariff_rates_empty": {
412+
"title": "{meter_type} {tariff_code} rates are empty for {account_id} ({mprn_mpan}/{serial_number})",
413+
"description": "One of your meters ({mprn_mpan}/{serial_number}) is associated with tariff \"{tariff_code}\" for product \"{product_code}\", but no longer seems to be returning new rates. Please click \"Learn More\" with details on how to rectify this."
410414
}
411415
}
412416
}

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ nav:
3434
- ./repairs/unknown_intelligent_provider.md
3535
- ./repairs/no_active_tariff.md
3636
- ./repairs/meter_removed.md
37+
- ./repairs/tariff_rates_empty.md
3738
- Community: community.md
3839
- blueprints.md
3940
- faq.md

0 commit comments

Comments
 (0)