Skip to content

Commit

Permalink
fix(sensor): Removed code for falling back on fixed tariffs if no agr…
Browse files Browse the repository at this point in the history
…eement is found

This code was added when we had people who had moved and we thought their sensors were not picking up their latest agreement. I believe this code is now wrong
  • Loading branch information
BottlecapDave committed Dec 19, 2021
1 parent 42a1408 commit 9a5045b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
4 changes: 2 additions & 2 deletions custom_components/octopus_energy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def async_setup_default_sensors(hass, entry, async_add_entities):
if len(account_info["electricity_meter_points"]) > 0:
for point in account_info["electricity_meter_points"]:
# We only care about points that have active agreements
if async_get_active_tariff_code(point["agreements"], client) != None:
if (await async_get_active_tariff_code(point["agreements"], client)) != None:
for meter in point["meters"]:
coordinator = create_reading_coordinator(hass, client, True, point["mpan"], meter["serial_number"])
entities.append(OctopusEnergyPreviousAccumulativeElectricityReading(coordinator, point["mpan"], meter["serial_number"]))
Expand All @@ -124,7 +124,7 @@ async def async_setup_default_sensors(hass, entry, async_add_entities):
if len(account_info["gas_meter_points"]) > 0:
for point in account_info["gas_meter_points"]:
# We only care about points that have active agreements
if async_get_active_tariff_code(point["agreements"], client) != None:
if (await async_get_active_tariff_code(point["agreements"], client)) != None:
for meter in point["meters"]:
coordinator = create_reading_coordinator(hass, client, False, point["mprn"], meter["serial_number"])
entities.append(OctopusEnergyPreviousAccumulativeGasReading(coordinator, point["mprn"], meter["serial_number"], is_smets1))
Expand Down
16 changes: 0 additions & 16 deletions custom_components/octopus_energy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async def async_get_active_tariff_code(agreements, client):

latest_agreement = None
latest_valid_from = None
fixed_indicators = ["12M", "24M"]

# Find our latest agreement
for agreement in agreements:
Expand All @@ -42,7 +41,6 @@ async def async_get_active_tariff_code(agreements, client):

if latest_agreement != None:
now = utcnow()
tariff_parts = get_tariff_parts(latest_agreement["tariff_code"])

latest_valid_to = None
if "valid_to" in latest_agreement and latest_agreement["valid_to"] != None:
Expand All @@ -51,20 +49,6 @@ async def async_get_active_tariff_code(agreements, client):
# If there is no end for our latest agreement, then it is our most active
if latest_valid_to == None or latest_valid_to >= now:
return latest_agreement["tariff_code"]

# If our latest agreement was a fixed rate and is in the past, then we must have moved into a variable rate
# (according to Octopus support), therefore we need to find the latest variable rate that
if latest_valid_to < now and any(x in tariff_parts["product_code"] for x in fixed_indicators):
products = await client.async_get_products(True)

variable_product = None
for product in products:
available_from = as_utc(parse_datetime(product["available_from"]))
if product["code"].startswith("VAR") and (variable_product == None or available_from < now):
variable_product = product

if variable_product != None:
return f'{tariff_parts["energy"]}-{tariff_parts["rate"]}-{variable_product["code"]}-{tariff_parts["region"]}'

return None

Expand Down

0 comments on commit 9a5045b

Please sign in to comment.