From 82fecf1adde75547b2f9d475291e9bb546dc74ad Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Tue, 3 Oct 2023 20:43:58 +0100 Subject: [PATCH] fix: Removed tracker tariff potentially looking at wrong API for standing charges --- .../octopus_energy/api_client.py | 18 -------- .../api_client/test_get_electricity_rates.py | 39 +---------------- .../test_get_electricity_standing_charge.py | 7 +--- .../api_client/test_get_gas_rates.py | 42 +------------------ .../test_get_gas_standing_charge.py | 7 +--- 5 files changed, 6 insertions(+), 107 deletions(-) diff --git a/custom_components/octopus_energy/api_client.py b/custom_components/octopus_energy/api_client.py index d1779252..86a74cfb 100644 --- a/custom_components/octopus_energy/api_client.py +++ b/custom_components/octopus_energy/api_client.py @@ -632,9 +632,6 @@ async def async_get_electricity_standing_charge(self, tariff_code, period_from, return None product_code = tariff_parts.product_code - - if self.__is_tracker_tariff__(tariff_code): - return await self.__async_get_tracker_standing_charge__(tariff_code, period_from, period_to) result = None async with aiohttp.ClientSession() as client: @@ -659,9 +656,6 @@ async def async_get_gas_standing_charge(self, tariff_code, period_from, period_t product_code = tariff_parts.product_code - if self.__is_tracker_tariff__(tariff_code): - return await self.__async_get_tracker_standing_charge__(tariff_code, period_from, period_to) - result = None async with aiohttp.ClientSession() as client: auth = aiohttp.BasicAuth(self._api_key, '') @@ -888,18 +882,6 @@ async def async_get_intelligent_device(self, account_id: str): return None - def __is_tracker_tariff__(self, tariff_code): - tariff_parts = get_tariff_parts(tariff_code) - if tariff_parts is None: - return None - - product_code = tariff_parts.product_code - - if product_code in self._product_tracker_cache: - return self._product_tracker_cache[product_code] - - return False - def __get_interval_end(self, item): return item["interval_end"] diff --git a/tests/integration/api_client/test_get_electricity_rates.py b/tests/integration/api_client/test_get_electricity_rates.py index 535f878b..8af3a659 100644 --- a/tests/integration/api_client/test_get_electricity_rates.py +++ b/tests/integration/api_client/test_get_electricity_rates.py @@ -3,7 +3,7 @@ from homeassistant.util.dt import (now) -from integration import (get_test_context, async_get_tracker_tariff) +from integration import (get_test_context) from custom_components.octopus_energy.api_client import OctopusEnergyApiClient default_period_from = datetime.strptime("2022-12-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") @@ -160,43 +160,6 @@ async def test_when_get_electricity_rates_is_called_with_duel_rate_tariff_smart_ else: assert item["value_inc_vat"] != cheapest_rate -# @pytest.mark.asyncio -# @pytest.mark.parametrize("tariff,price_cap",[("E-1R-SILVER-FLEX-22-11-25-C", None), ("E-1R-SILVER-FLEX-22-11-25-C", 10)]) -# async def test_when_get_electricity_rates_is_called_with_tracker_tariff_then_rates_are_returned(tariff, price_cap): -# # Arrange -# context = get_test_context() -# period_from = now().replace(hour=0, minute=0, second=0, microsecond=0) -# period_to = (now() + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) -# client = OctopusEnergyApiClient(context["api_key"], price_cap) - -# expected_tracker = await async_get_tracker_tariff(context["api_key"], tariff, now()) -# assert expected_tracker is not None - -# # Act -# data = await client.async_get_electricity_rates(tariff, False, period_from, period_to) - -# # Assert -# assert data is not None -# assert len(data) == 48 - -# # Make sure our data is returned in 30 minute increments -# expected_valid_from = period_from -# for item in data: -# expected_valid_to = expected_valid_from + timedelta(minutes=30) - -# assert "valid_from" in item -# assert item["valid_from"] == expected_valid_from -# assert "valid_to" in item -# assert item["valid_to"] == expected_valid_to - -# assert "value_inc_vat" in item -# if (price_cap is not None and expected_tracker["unit_rate"] > price_cap): -# assert item["value_inc_vat"] == price_cap -# else: -# assert item["value_inc_vat"] == expected_tracker["unit_rate"] - -# expected_valid_from = expected_valid_to - @pytest.mark.asyncio @pytest.mark.parametrize("tariff",[("E-2R-NOT-A-TARIFF-A"), ("E-1R-NOT-A-TARIFF-A"), ("NOT-A-TARIFF")]) async def test_when_get_electricity_rates_is_called_for_non_existent_tariff_then_none_is_returned(tariff): diff --git a/tests/integration/api_client/test_get_electricity_standing_charge.py b/tests/integration/api_client/test_get_electricity_standing_charge.py index 9b71a0c6..c89b2e18 100644 --- a/tests/integration/api_client/test_get_electricity_standing_charge.py +++ b/tests/integration/api_client/test_get_electricity_standing_charge.py @@ -3,7 +3,7 @@ from homeassistant.util.dt import (now) -from integration import (get_test_context, async_get_tracker_tariff) +from integration import (get_test_context) from custom_components.octopus_energy.api_client import OctopusEnergyApiClient period_from = datetime.strptime("2022-12-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") @@ -40,16 +40,13 @@ async def test_when_get_electricity_standing_charge_is_called_with_tracker_tarif period_to = (now() + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) client = OctopusEnergyApiClient(context["api_key"]) - expected_tracker = await async_get_tracker_tariff(context["api_key"], tariff, now()) - assert expected_tracker is not None - # Act result = await client.async_get_electricity_standing_charge(tariff, period_from, period_to) # Assert assert result is not None assert "value_inc_vat" in result - assert result["value_inc_vat"] == expected_tracker["standing_charge"] + assert result["value_inc_vat"] is not None @pytest.mark.asyncio @pytest.mark.parametrize("tariff",[("E-1R-NOT-A-TARIFF-A"), ("NOT-A-TARIFF")]) diff --git a/tests/integration/api_client/test_get_gas_rates.py b/tests/integration/api_client/test_get_gas_rates.py index 4fbbd9b1..a1696067 100644 --- a/tests/integration/api_client/test_get_gas_rates.py +++ b/tests/integration/api_client/test_get_gas_rates.py @@ -3,7 +3,7 @@ from homeassistant.util.dt import (now) -from integration import (get_test_context, async_get_tracker_tariff) +from integration import (get_test_context) from custom_components.octopus_energy.api_client import OctopusEnergyApiClient @pytest.mark.asyncio @@ -42,46 +42,6 @@ async def test_when_get_gas_rates_is_called_for_existent_tariff_then_rates_are_r expected_valid_from = expected_valid_to -# @pytest.mark.asyncio -# @pytest.mark.parametrize("tariff,price_cap",[ -# ("G-1R-SILVER-FLEX-22-11-25-C", None), -# ("G-1R-SILVER-FLEX-22-11-25-C", 2), -# ]) -# async def test_when_get_gas_rates_is_called_with_tracker_tariff_then_rates_are_returned(tariff, price_cap): -# # Arrange -# context = get_test_context() -# period_from = now().replace(hour=0, minute=0, second=0, microsecond=0) -# period_to = (now() + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) -# client = OctopusEnergyApiClient(context["api_key"], None, price_cap) - -# expected_tracker = await async_get_tracker_tariff(context["api_key"], tariff, now()) -# assert expected_tracker is not None - -# # Act -# data = await client.async_get_gas_rates(tariff, period_from, period_to) - -# # Assert -# assert data is not None -# assert len(data) == 48 - -# # Make sure our data is returned in 30 minute increments -# expected_valid_from = period_from -# for item in data: -# expected_valid_to = expected_valid_from + timedelta(minutes=30) - -# assert "valid_from" in item -# assert item["valid_from"] == expected_valid_from -# assert "valid_to" in item -# assert item["valid_to"] == expected_valid_to - -# assert "value_inc_vat" in item -# if (price_cap is not None and expected_tracker["unit_rate"] > price_cap): -# assert item["value_inc_vat"] == price_cap -# else: -# assert item["value_inc_vat"] == expected_tracker["unit_rate"] - -# expected_valid_from = expected_valid_to - @pytest.mark.asyncio @pytest.mark.parametrize("tariff",[("G-1R-NOT-A-TARIFF-A"), ("NOT-A-TARIFF")]) async def test_when_get_gas_rates_is_called_for_non_existent_tariff_then_none_is_returned(tariff): diff --git a/tests/integration/api_client/test_get_gas_standing_charge.py b/tests/integration/api_client/test_get_gas_standing_charge.py index 8e2deb06..361291b0 100644 --- a/tests/integration/api_client/test_get_gas_standing_charge.py +++ b/tests/integration/api_client/test_get_gas_standing_charge.py @@ -3,7 +3,7 @@ from homeassistant.util.dt import (now) -from integration import (get_test_context, async_get_tracker_tariff) +from integration import (get_test_context) from custom_components.octopus_energy.api_client import OctopusEnergyApiClient period_from = datetime.strptime("2021-12-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") @@ -34,16 +34,13 @@ async def test_when_get_gas_standing_charge_is_called_with_tracker_tariff_then_r period_to = (now() + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) client = OctopusEnergyApiClient(context["api_key"]) - expected_tracker = await async_get_tracker_tariff(context["api_key"], tariff, now()) - assert expected_tracker is not None - # Act result = await client.async_get_gas_standing_charge(tariff, period_from, period_to) # Assert assert result is not None assert "value_inc_vat" in result - assert result["value_inc_vat"] == expected_tracker["standing_charge"] + assert result["value_inc_vat"] is not None @pytest.mark.asyncio @pytest.mark.parametrize("tariff",[("G-1R-NOT-A-TARIFF-A"), ("NOT-A-TARIFF")])