Skip to content

Commit

Permalink
fix: updated standing charge attribute on cost sensors to be in pound…
Browse files Browse the repository at this point in the history
…/pence for consistency

BREAKING CHANGE:
Standing charge attribute on cost sensors are now in pound/pence. If you are using this, then might
need to adjust any calculations etc.
  • Loading branch information
BottlecapDave committed Oct 30, 2023
1 parent 727db53 commit 913336a
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/octopus_energy/electricity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def calculate_electricity_consumption_and_cost(
last_calculated_timestamp = sorted_consumption_data[-1]["interval_end"]

result = {
"standing_charge": standing_charge,
"standing_charge": round(standing_charge / 100, 2),
"total_cost_without_standing_charge": total_cost,
"total_cost": total_cost_plus_standing_charge,
"total_consumption": total_consumption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def state(self):
"tariff_code": self._tariff_code,
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": f'£{consumption_and_cost["total_cost"]}',
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"charges": list(map(lambda charge: {
"from": charge["from"],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/octopus_energy/gas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def calculate_gas_consumption_and_cost(
last_calculated_timestamp = sorted_consumption_data[-1]["interval_end"]

return {
"standing_charge": standing_charge,
"standing_charge": round(standing_charge / 100, 2),
"total_cost_without_standing_charge": total_cost,
"total_cost": total_cost_plus_standing_charge,
"total_consumption_m3": total_consumption_m3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def async_update(self):
"tariff_code": self._tariff_code,
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": f'£{consumption_and_cost["total_cost"]}',
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"charges": list(map(lambda charge: {
"from": charge["from"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def fire_event(name, metadata):

# Assert
assert result is not None
assert result["standing_charge"] == standard_charge_result["value_inc_vat"]
assert result["standing_charge"] == round(standard_charge_result["value_inc_vat"] / 100, 2)
assert result["total_cost_without_standing_charge"] == 1.63
assert result["total_cost"] == 1.87
assert result["last_calculated_timestamp"] == consumption_and_rates_result["consumption"][-1]["interval_end"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def fire_event(name, metadata):
# Assert
assert result is not None
assert result["last_calculated_timestamp"] == consumption_and_rates_result["consumption"][-1]["interval_end"]
assert result["standing_charge"] == standard_charge_result["value_inc_vat"]
assert result["standing_charge"] == round(standard_charge_result["value_inc_vat"] / 100, 2)

if consumption_units == "m³":
assert result["total_cost_without_standing_charge"] == 2.88
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_when_electricity_consumption_available_then_calculation_returned(
# Assert
assert result is not None

assert result["standing_charge"] == standing_charge
assert result["standing_charge"] == round(standing_charge / 100, 2)
assert result["total_cost_without_standing_charge"] == round((48 * expected_rate_price) / 100, 2)
assert result["total_cost"] == round(((48 * expected_rate_price) + standing_charge) / 100, 2)
assert result["last_calculated_timestamp"] == consumption_data[-1]["interval_end"]
Expand Down Expand Up @@ -193,7 +193,7 @@ async def test_when_electricity_consumption_starting_at_latest_date_then_calcula
# Assert
assert result is not None

assert result["standing_charge"] == standing_charge
assert result["standing_charge"] == round(standing_charge / 100, 2)

# Total is reported in pounds and pence, but rate prices are in pence, so we need to calculate our expected value
assert result["total_cost_without_standing_charge"] == round((48 * expected_rate_price) / 100, 2)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/gas/test_calculate_gas_consumption_and_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def test_when_gas_consumption_available_then_calculation_returned(latest_d
assert result is not None
assert len(result["charges"]) == 48

assert result["standing_charge"] == standing_charge
assert result["standing_charge"] == round(standing_charge / 100, 2)

assert result["last_calculated_timestamp"] == consumption_data[-1]["interval_end"]

Expand Down Expand Up @@ -218,7 +218,7 @@ async def test_when_gas_consumption_starting_at_latest_date_then_calculation_ret
assert len(result["charges"]) == 48

assert result["last_calculated_timestamp"] == consumption_data[0]["interval_end"]
assert result["standing_charge"] == standing_charge
assert result["standing_charge"] == round(standing_charge / 100, 2)

# Total is reported in pounds and pence, but rate prices are in pence, so we need to calculate our expected value
if consumption_units == "m³":
Expand Down

0 comments on commit 913336a

Please sign in to comment.