Skip to content

Commit

Permalink
feat: updated last_calculated_timestamp attributes to last_evaluated …
Browse files Browse the repository at this point in the history
…for consistency

BREAKING CHANGE:
Any references to last_calculated_timestamp attribute should be updated to last_evaluated
  • Loading branch information
BottlecapDave committed Nov 5, 2023
1 parent 7ed2441 commit 702eb4a
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 27 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 @@ -79,7 +79,7 @@ def calculate_electricity_consumption_and_cost(
"total_cost": total_cost_plus_standing_charge,
"total_consumption": total_consumption,
"last_reset": last_reset,
"last_calculated_timestamp": last_calculated_timestamp,
"last_evaluated": last_calculated_timestamp,
"charges": charges
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def state(self):
"is_export": self._is_export,
"is_smart_meter": self._is_smart_meter,
"total": consumption_and_cost["total_consumption"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def state(self):
self._state = consumption_and_cost["total_consumption_off_peak"] if "total_consumption_off_peak" in consumption_and_cost else 0
self._last_reset = consumption_and_cost["last_reset"]

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def state(self):
self._state = consumption_and_cost["total_consumption_peak"] if "total_consumption_peak" in consumption_and_cost else 0
self._last_reset = consumption_and_cost["last_reset"]

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def state(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def state(self):
self._last_reset = consumption_and_cost["last_reset"]
self._state = consumption_and_cost["total_cost_off_peak"] if "total_cost_off_peak" in consumption_and_cost else 0

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def state(self):
self._last_reset = consumption_and_cost["last_reset"]
self._state = consumption_and_cost["total_cost_peak"] if "total_cost_peak" in consumption_and_cost else 0

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def async_update(self):
"is_export": self._is_export,
"is_smart_meter": self._is_smart_meter,
"total": consumption_and_cost["total_consumption"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def state(self):
self._state = consumption_and_cost["total_consumption_off_peak"] if "total_consumption_off_peak" in consumption_and_cost else 0
self._last_reset = consumption_and_cost["last_reset"]

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def state(self):
self._state = consumption_and_cost["total_consumption_peak"] if "total_consumption_peak" in consumption_and_cost else 0
self._last_reset = consumption_and_cost["last_reset"]

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def async_update(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def state(self):
self._last_reset = consumption_and_cost["last_reset"]
self._state = consumption_and_cost["total_cost_off_peak"] if "total_cost_off_peak" in consumption_and_cost else 0

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def async_update(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def state(self):
self._last_reset = consumption_and_cost["last_reset"]
self._state = consumption_and_cost["total_cost_peak"] if "total_cost_peak" in consumption_and_cost else 0

self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"]
self._attributes["last_evaluated"] = consumption_and_cost["last_evaluated"]

return self._state

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 @@ -89,7 +89,7 @@ def calculate_gas_consumption_and_cost(
"total_consumption_m3": total_consumption_m3,
"total_consumption_kwh": total_consumption_kwh,
"last_reset": last_reset,
"last_calculated_timestamp": last_calculated_timestamp,
"last_evaluated": last_calculated_timestamp,
"charges": charges
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def state(self):
"mprn": self._mprn,
"serial_number": self._serial_number,
"total": consumption_and_cost["total_consumption_kwh"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def state(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def async_update(self):
"is_estimated": self._native_consumption_units != "m³",
"total_kwh": consumption_and_cost["total_consumption_kwh"],
"total_m3": consumption_and_cost["total_consumption_m3"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def async_update(self):
"mprn": self._mprn,
"serial_number": self._serial_number,
"is_estimated": self._native_consumption_units == "m³",
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def async_update(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def async_update(self):
"standing_charge": consumption_and_cost["standing_charge"],
"total_without_standing_charge": consumption_and_cost["total_cost_without_standing_charge"],
"total": consumption_and_cost["total_cost"],
"last_calculated_timestamp": consumption_and_cost["last_calculated_timestamp"],
"last_evaluated": consumption_and_cost["last_evaluated"],
"charges": list(map(lambda charge: {
"from": charge["from"],
"to": charge["to"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def fire_event(name, metadata):
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"]
assert result["last_evaluated"] == consumption_and_rates_result["consumption"][-1]["interval_end"]

assert len(result["charges"]) == 48

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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["last_evaluated"] == consumption_and_rates_result["consumption"][-1]["interval_end"]
assert result["standing_charge"] == round(standard_charge_result["value_inc_vat"] / 100, 2)

if consumption_units == "m³":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def test_when_electricity_consumption_available_then_calculation_returned(
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"]
assert result["last_evaluated"] == consumption_data[-1]["interval_end"]
assert result["total_consumption"] == expected_consumption_total

# Make sure our data is returned in 30 minute increments
Expand Down Expand Up @@ -199,7 +199,7 @@ async def test_when_electricity_consumption_starting_at_latest_date_then_calcula
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[0]["interval_end"]
assert result["last_evaluated"] == consumption_data[0]["interval_end"]
assert result["total_consumption"] == expected_consumption_total

# Make sure our data is returned in 30 minute increments
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 @@ -137,7 +137,7 @@ async def test_when_gas_consumption_available_then_calculation_returned(latest_d

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

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

# 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 Expand Up @@ -220,7 +220,7 @@ async def test_when_gas_consumption_starting_at_latest_date_then_calculation_ret
assert result is not None
assert len(result["charges"]) == 48

assert result["last_calculated_timestamp"] == consumption_data[0]["interval_end"]
assert result["last_evaluated"] == consumption_data[0]["interval_end"]
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
Expand Down

0 comments on commit 702eb4a

Please sign in to comment.