diff --git a/.gitignore b/.gitignore index d144764e..e2f6e13d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ **/__pycache__/** run_tests.sh run_unit_tests.sh +run_integration_tests.sh diff --git a/custom_components/octopus_energy/api_client/__init__.py b/custom_components/octopus_energy/api_client/__init__.py index 1fca18ca..c5c68ea0 100644 --- a/custom_components/octopus_energy/api_client/__init__.py +++ b/custom_components/octopus_energy/api_client/__init__.py @@ -283,6 +283,9 @@ def get_valid_from(rate): return rate["valid_from"] + +def get_from(rate): + return rate["start"] def rates_to_thirty_minute_increments(data, period_from: datetime, period_to: datetime, tariff_code: str, price_cap: float = None): """Process the collection of rates to ensure they're in 30 minute periods""" @@ -326,8 +329,8 @@ def rates_to_thirty_minute_increments(data, period_from: datetime, period_to: da valid_to = valid_from + timedelta(minutes=30) results.append({ "value_inc_vat": value_inc_vat, - "valid_from": valid_from, - "valid_to": valid_to, + "start": valid_from, + "end": valid_to, "tariff_code": tariff_code, "is_capped": is_capped }) @@ -434,8 +437,8 @@ async def async_get_account(self, account_id): else [] )), "agreements": list(map(lambda a: { - "valid_from": a["validFrom"], - "valid_to": a["validTo"], + "start": a["validFrom"], + "end": a["validTo"], "tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None, "product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None, }, @@ -470,8 +473,8 @@ async def async_get_account(self, account_id): else [] )), "agreements": list(map(lambda a: { - "valid_from": a["validFrom"], - "valid_to": a["validTo"], + "start": a["validFrom"], + "end": a["validTo"], "tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None, "product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None, }, @@ -572,8 +575,8 @@ async def async_get_smart_meter_consumption(self, device_id: str, period_from: d return list(map(lambda mp: { "consumption": float(mp["consumptionDelta"]) / 1000, "demand": float(mp["demand"]) if "demand" in mp and mp["demand"] is not None else None, - "interval_start": parse_datetime(mp["readAt"]), - "interval_end": parse_datetime(mp["readAt"]) + timedelta(minutes=30) + "start": parse_datetime(mp["readAt"]), + "end": parse_datetime(mp["readAt"]) + timedelta(minutes=30) }, response_body["data"]["smartMeterTelemetry"])) else: _LOGGER.debug(f"Failed to retrieve smart meter consumption data - device_id: {device_id}; period_from: {period_from}; period_to: {period_to}") @@ -625,7 +628,7 @@ async def async_get_electricity_day_night_rates(self, product_code, tariff_code, results.append(rate) # Because we retrieve our day and night periods separately over a 2 day period, we need to sort our rates - results.sort(key=get_valid_from) + results.sort(key=get_from) return results @@ -659,7 +662,7 @@ async def async_get_electricity_consumption(self, mpan, serial_number, period_fr # For some reason, the end point returns slightly more data than we requested, so we need to filter out # the results - if as_utc(item["interval_start"]) >= period_from and as_utc(item["interval_end"]) <= period_to: + if as_utc(item["start"]) >= period_from and as_utc(item["end"]) <= period_to: results.append(item) results.sort(key=self.__get_interval_end) @@ -703,7 +706,7 @@ async def async_get_gas_consumption(self, mprn, serial_number, period_from, peri # For some reason, the end point returns slightly more data than we requested, so we need to filter out # the results - if as_utc(item["interval_start"]) >= period_from and as_utc(item["interval_end"]) <= period_to: + if as_utc(item["start"]) >= period_from and as_utc(item["end"]) <= period_to: results.append(item) results.sort(key=self.__get_interval_end) @@ -735,8 +738,8 @@ async def async_get_electricity_standing_charge(self, tariff_code, period_from, data = await self.__async_read_response__(response, url) if (data is not None and "results" in data and len(data["results"]) > 0): result = { - "valid_from": parse_datetime(data["results"][0]["valid_from"]) if "valid_from" in data["results"][0] and data["results"][0]["valid_from"] is not None else None, - "valid_to": parse_datetime(data["results"][0]["valid_to"]) if "valid_to" in data["results"][0] and data["results"][0]["valid_to"] is not None else None, + "start": parse_datetime(data["results"][0]["valid_from"]) if "valid_from" in data["results"][0] and data["results"][0]["valid_from"] is not None else None, + "end": parse_datetime(data["results"][0]["valid_to"]) if "valid_to" in data["results"][0] and data["results"][0]["valid_to"] is not None else None, "value_inc_vat": float(data["results"][0]["value_inc_vat"]) } @@ -758,8 +761,8 @@ async def async_get_gas_standing_charge(self, tariff_code, period_from, period_t data = await self.__async_read_response__(response, url) if (data is not None and "results" in data and len(data["results"]) > 0): result = { - "valid_from": parse_datetime(data["results"][0]["valid_from"]) if "valid_from" in data["results"][0] and data["results"][0]["valid_from"] is not None else None, - "valid_to": parse_datetime(data["results"][0]["valid_to"]) if "valid_to" in data["results"][0] and data["results"][0]["valid_to"] is not None else None, + "start": parse_datetime(data["results"][0]["valid_from"]) if "valid_from" in data["results"][0] and data["results"][0]["valid_from"] is not None else None, + "end": parse_datetime(data["results"][0]["valid_to"]) if "valid_to" in data["results"][0] and data["results"][0]["valid_to"] is not None else None, "value_inc_vat": float(data["results"][0]["value_inc_vat"]) } @@ -1050,7 +1053,7 @@ async def async_spin_wheel_of_fortune(self, account_id: str, is_electricity: boo return None def __get_interval_end(self, item): - return item["interval_end"] + return item["end"] def __is_night_rate(self, rate, is_smart_meter): # Normally the economy seven night rate is between 12am and 7am UK time @@ -1065,11 +1068,11 @@ def __is_night_rate(self, rate, is_smart_meter): def __is_between_times(self, rate, target_from_time, target_to_time, use_utc): """Determines if a current rate is between two times""" - rate_local_valid_from = as_local(rate["valid_from"]) - rate_local_valid_to = as_local(rate["valid_to"]) + rate_local_valid_from = as_local(rate["start"]) + rate_local_valid_to = as_local(rate["end"]) if use_utc: - rate_utc_valid_from = as_utc(rate["valid_from"]) + rate_utc_valid_from = as_utc(rate["start"]) # We need to convert our times into local time to account for BST to ensure that our rate is valid between the target times. from_date_time = as_local(parse_datetime(rate_utc_valid_from.strftime(f"%Y-%m-%dT{target_from_time}Z"))) to_date_time = as_local(parse_datetime(rate_utc_valid_from.strftime(f"%Y-%m-%dT{target_to_time}Z"))) @@ -1086,8 +1089,8 @@ def __is_between_times(self, rate, target_from_time, target_to_time, use_utc): def __process_consumption(self, item): return { "consumption": float(item["consumption"]), - "interval_start": as_utc(parse_datetime(item["interval_start"])), - "interval_end": as_utc(parse_datetime(item["interval_end"])) + "start": as_utc(parse_datetime(item["interval_start"])), + "end": as_utc(parse_datetime(item["interval_end"])) } async def __async_read_response__(self, response, url): diff --git a/custom_components/octopus_energy/coordinators/__init__.py b/custom_components/octopus_energy/coordinators/__init__.py index c1377a9f..d16d60a3 100644 --- a/custom_components/octopus_energy/coordinators/__init__.py +++ b/custom_components/octopus_energy/coordinators/__init__.py @@ -74,9 +74,9 @@ def raise_rate_events(now: datetime, next_rates = [] for rate in rates: - if (rate["valid_from"] < today_start): + if (rate["start"] < today_start): previous_rates.append(rate) - elif (rate["valid_from"] >= today_end): + elif (rate["start"] >= today_end): next_rates.append(rate) else: current_rates.append(rate) diff --git a/custom_components/octopus_energy/coordinators/electricity_rates.py b/custom_components/octopus_energy/coordinators/electricity_rates.py index 904f605d..c1831911 100644 --- a/custom_components/octopus_energy/coordinators/electricity_rates.py +++ b/custom_components/octopus_energy/coordinators/electricity_rates.py @@ -62,7 +62,7 @@ async def async_refresh_electricity_rates_data( existing_rates_result is None or existing_rates_result.rates is None or len(existing_rates_result.rates) < 1 or - existing_rates_result.rates[-1]["valid_from"] < period_from): + existing_rates_result.rates[-1]["start"] < period_from): try: new_rates = await client.async_get_electricity_rates(tariff_code, is_smart_meter, period_from, period_to) except: diff --git a/custom_components/octopus_energy/coordinators/electricity_standing_charges.py b/custom_components/octopus_energy/coordinators/electricity_standing_charges.py index 8a5d804f..009b3d8c 100644 --- a/custom_components/octopus_energy/coordinators/electricity_standing_charges.py +++ b/custom_components/octopus_energy/coordinators/electricity_standing_charges.py @@ -47,7 +47,7 @@ async def async_refresh_electricity_standing_charges_data( if ((current.minute % 30) == 0 or existing_standing_charges_result is None or existing_standing_charges_result.standing_charge is None or - (existing_standing_charges_result.standing_charge["valid_from"] is not None and existing_standing_charges_result.standing_charge["valid_from"] < period_from)): + (existing_standing_charges_result.standing_charge["start"] is not None and existing_standing_charges_result.standing_charge["start"] < period_from)): try: new_standing_charge = await client.async_get_electricity_standing_charge(tariff_code, period_from, period_to) _LOGGER.debug(f'Electricity standing charges retrieved for {target_mpan}/{target_serial_number} ({tariff_code})') diff --git a/custom_components/octopus_energy/coordinators/gas_rates.py b/custom_components/octopus_energy/coordinators/gas_rates.py index ad64b049..3bbbccb9 100644 --- a/custom_components/octopus_energy/coordinators/gas_rates.py +++ b/custom_components/octopus_energy/coordinators/gas_rates.py @@ -53,7 +53,7 @@ async def async_refresh_gas_rates_data( existing_rates_result is None or existing_rates_result.rates is None or len(existing_rates_result.rates) < 1 or - existing_rates_result.rates[-1]["valid_from"] < period_from): + existing_rates_result.rates[-1]["start"] < period_from): try: new_rates = await client.async_get_gas_rates(tariff_code, period_from, period_to) except: diff --git a/custom_components/octopus_energy/coordinators/gas_standing_charges.py b/custom_components/octopus_energy/coordinators/gas_standing_charges.py index 94332ad2..28aaeed7 100644 --- a/custom_components/octopus_energy/coordinators/gas_standing_charges.py +++ b/custom_components/octopus_energy/coordinators/gas_standing_charges.py @@ -47,7 +47,7 @@ async def async_refresh_gas_standing_charges_data( if ((current.minute % 30) == 0 or existing_standing_charges_result is None or existing_standing_charges_result.standing_charge is None or - (existing_standing_charges_result.standing_charge["valid_from"] is not None and existing_standing_charges_result.standing_charge["valid_from"] < period_from)): + (existing_standing_charges_result.standing_charge["start"] is not None and existing_standing_charges_result.standing_charge["start"] < period_from)): try: new_standing_charge = await client.async_get_gas_standing_charge(tariff_code, period_from, period_to) _LOGGER.debug(f'Gas standing charges retrieved for {target_mprn}/{target_serial_number} ({tariff_code})') diff --git a/custom_components/octopus_energy/coordinators/previous_consumption_and_rates.py b/custom_components/octopus_energy/coordinators/previous_consumption_and_rates.py index 6c59eaaa..d6102d5f 100644 --- a/custom_components/octopus_energy/coordinators/previous_consumption_and_rates.py +++ b/custom_components/octopus_energy/coordinators/previous_consumption_and_rates.py @@ -27,7 +27,7 @@ _LOGGER = logging.getLogger(__name__) def __get_interval_end(item): - return item["interval_end"] + return item["end"] def __sort_consumption(consumption_data): sorted = consumption_data.copy() @@ -53,7 +53,7 @@ async def async_fetch_consumption_and_rates( if (previous_data == None or ((len(previous_data["consumption"]) < 1 or - previous_data["consumption"][-1]["interval_end"] < period_to) and + previous_data["consumption"][-1]["end"] < period_to) and utc_now.minute % 30 == 0)): _LOGGER.debug(f"Retrieving previous consumption data for {'electricity' if is_electricity else 'gas'} {identifier}/{serial_number}...") diff --git a/custom_components/octopus_energy/electricity/__init__.py b/custom_components/octopus_energy/electricity/__init__.py index c9027704..9d3ba6ef 100644 --- a/custom_components/octopus_energy/electricity/__init__.py +++ b/custom_components/octopus_energy/electricity/__init__.py @@ -3,12 +3,12 @@ from ..utils.conversions import value_inc_vat_to_pounds from ..utils import get_off_peak_cost -def __get_interval_end(item): - return item["interval_end"] +def __get_to(item): + return item["end"] def __sort_consumption(consumption_data): sorted = consumption_data.copy() - sorted.sort(key=__get_interval_end) + sorted.sort(key=__get_to) return sorted def calculate_electricity_consumption_and_cost( @@ -25,7 +25,7 @@ def calculate_electricity_consumption_and_cost( sorted_consumption_data = __sort_consumption(consumption_data) # Only calculate our consumption if our data has changed - if (last_reset is None or last_reset < sorted_consumption_data[0]["interval_start"]): + if (last_reset is None or last_reset < sorted_consumption_data[0]["start"]): charges = [] total_cost_in_pence = 0 @@ -39,12 +39,12 @@ def calculate_electricity_consumption_and_cost( for consumption in sorted_consumption_data: consumption_value = consumption["consumption"] - consumption_from = consumption["interval_start"] - consumption_to = consumption["interval_end"] + consumption_from = consumption["start"] + consumption_to = consumption["end"] total_consumption = total_consumption + consumption_value try: - rate = next(r for r in rate_data if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to) + rate = next(r for r in rate_data if r["start"] == consumption_from and r["end"] == consumption_to) except StopIteration: raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {tariff_code}") @@ -60,8 +60,8 @@ def calculate_electricity_consumption_and_cost( total_cost_peak = total_cost_peak + cost charges.append({ - "from": rate["valid_from"], - "to": rate["valid_to"], + "start": rate["start"], + "end": rate["end"], "rate": value_inc_vat_to_pounds(value), "consumption": consumption_value, "cost": round(cost / 100, 2) @@ -70,8 +70,8 @@ def calculate_electricity_consumption_and_cost( total_cost = round(total_cost_in_pence / 100, 2) total_cost_plus_standing_charge = round((total_cost_in_pence + standing_charge) / 100, 2) - last_reset = sorted_consumption_data[0]["interval_start"] - last_calculated_timestamp = sorted_consumption_data[-1]["interval_end"] + last_reset = sorted_consumption_data[0]["start"] + last_calculated_timestamp = sorted_consumption_data[-1]["end"] result = { "standing_charge": round(standing_charge / 100, 2), diff --git a/custom_components/octopus_energy/electricity/current_accumulative_consumption.py b/custom_components/octopus_energy/electricity/current_accumulative_consumption.py index 6530a371..df3c053b 100644 --- a/custom_components/octopus_energy/electricity/current_accumulative_consumption.py +++ b/custom_components/octopus_energy/electricity/current_accumulative_consumption.py @@ -108,8 +108,8 @@ def state(self): "total": consumption_and_cost["total_consumption"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "consumption": charge["consumption"] }, consumption_and_cost["charges"])) } diff --git a/custom_components/octopus_energy/electricity/current_accumulative_cost.py b/custom_components/octopus_energy/electricity/current_accumulative_cost.py index 38ab2610..9d47e5fb 100644 --- a/custom_components/octopus_energy/electricity/current_accumulative_cost.py +++ b/custom_components/octopus_energy/electricity/current_accumulative_cost.py @@ -119,8 +119,8 @@ def state(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption"], "cost": charge["cost"] diff --git a/custom_components/octopus_energy/electricity/current_rate.py b/custom_components/octopus_energy/electricity/current_rate.py index 9bd7fa79..8681e59e 100644 --- a/custom_components/octopus_energy/electricity/current_rate.py +++ b/custom_components/octopus_energy/electricity/current_rate.py @@ -41,8 +41,8 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point, tariff_code, "tariff": self._tariff_code, "all_rates": [], "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "is_capped": None, "is_intelligent_adjusted": None, "current_day_min_rate": None, @@ -103,8 +103,8 @@ def state(self): "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, "tariff": self._tariff_code, - "valid_from": rate_information["current_rate"]["valid_from"], - "valid_to": rate_information["current_rate"]["valid_to"], + "start": rate_information["current_rate"]["start"], + "end": rate_information["current_rate"]["end"], "is_capped": rate_information["current_rate"]["is_capped"], "is_intelligent_adjusted": rate_information["current_rate"]["is_intelligent_adjusted"], "current_day_min_rate": rate_information["min_rate_today"], @@ -122,8 +122,8 @@ def state(self): "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, "tariff": self._tariff_code, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "is_capped": None, "is_intelligent_adjusted": None, "current_day_min_rate": None, diff --git a/custom_components/octopus_energy/electricity/next_rate.py b/custom_components/octopus_energy/electricity/next_rate.py index 06e53e2c..cbc5dcf6 100644 --- a/custom_components/octopus_energy/electricity/next_rate.py +++ b/custom_components/octopus_energy/electricity/next_rate.py @@ -36,8 +36,8 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, } @property @@ -93,8 +93,8 @@ def state(self): "serial_number": self._serial_number, "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, - "valid_from": rate_information["next_rate"]["valid_from"], - "valid_to": rate_information["next_rate"]["valid_to"], + "start": rate_information["next_rate"]["start"], + "end": rate_information["next_rate"]["end"], "applicable_rates": rate_information["applicable_rates"], } @@ -105,8 +105,8 @@ def state(self): "serial_number": self._serial_number, "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "applicable_rates": [], } diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py index 81f597de..8b1b15b2 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py @@ -108,7 +108,7 @@ async def async_update(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, @@ -144,8 +144,8 @@ async def async_update(self): "total": consumption_and_cost["total_consumption"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "consumption": charge["consumption"] }, consumption_and_cost["charges"])) } diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py index 50ea549c..55a29319 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py @@ -92,7 +92,7 @@ def state(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py index 95c20b89..fc18f430 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py @@ -92,7 +92,7 @@ def state(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py index 98a54d8f..a02debfc 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py @@ -104,7 +104,7 @@ async def async_update(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, @@ -142,8 +142,8 @@ async def async_update(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption"], "cost": charge["cost"], diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py index 99d220a5..cc4cdfb2 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py @@ -90,7 +90,7 @@ def state(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py index 774f4923..ab2ae71a 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_override.py @@ -112,7 +112,7 @@ async def async_update(self): tariff_override_key = get_electricity_tariff_override_key(self._serial_number, self._mpan) - is_old_data = self._last_reset is None or (consumption_data is not None and self._last_reset < consumption_data[-1]["interval_end"]) + is_old_data = self._last_reset is None or (consumption_data is not None and self._last_reset < consumption_data[-1]["end"]) is_tariff_present = tariff_override_key in self._hass.data[DOMAIN] has_tariff_changed = is_tariff_present and self._hass.data[DOMAIN][tariff_override_key] != self._tariff_code @@ -120,8 +120,8 @@ async def async_update(self): _LOGGER.debug(f"Calculating previous electricity consumption cost override for '{self._mpan}/{self._serial_number}'...") tariff_override = self._hass.data[DOMAIN][tariff_override_key] - period_from = consumption_data[0]["interval_start"] - period_to = consumption_data[-1]["interval_end"] + period_from = consumption_data[0]["start"] + period_to = consumption_data[-1]["end"] [rate_data, standing_charge] = await asyncio.gather( self._client.async_get_electricity_rates(tariff_override, self._is_smart_meter, period_from, period_to), @@ -156,8 +156,8 @@ async def async_update(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption"], "cost": charge["cost"] diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py index 0e2639a8..87c49d24 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py @@ -90,7 +90,7 @@ def state(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None + current = consumption_data[0]["start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_rate.py b/custom_components/octopus_energy/electricity/previous_rate.py index 37388e3e..0ffd6143 100644 --- a/custom_components/octopus_energy/electricity/previous_rate.py +++ b/custom_components/octopus_energy/electricity/previous_rate.py @@ -36,8 +36,8 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, } @property @@ -93,8 +93,8 @@ def state(self): "serial_number": self._serial_number, "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, - "valid_from": rate_information["previous_rate"]["valid_from"], - "valid_to": rate_information["previous_rate"]["valid_to"], + "start": rate_information["previous_rate"]["start"], + "end": rate_information["previous_rate"]["end"], "applicable_rates": rate_information["applicable_rates"], } @@ -105,8 +105,8 @@ def state(self): "serial_number": self._serial_number, "is_export": self._is_export, "is_smart_meter": self._is_smart_meter, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "applicable_rates": [], } diff --git a/custom_components/octopus_energy/electricity/standing_charge.py b/custom_components/octopus_energy/electricity/standing_charge.py index 0b4f57ec..ba115120 100644 --- a/custom_components/octopus_energy/electricity/standing_charge.py +++ b/custom_components/octopus_energy/electricity/standing_charge.py @@ -65,12 +65,12 @@ def state(self): standard_charge_result = self.coordinator.data.standing_charge if self.coordinator is not None and self.coordinator.data is not None else None if standard_charge_result is not None: - self._latest_date = standard_charge_result["valid_from"] + self._latest_date = standard_charge_result["start"] self._state = standard_charge_result["value_inc_vat"] / 100 # Adjust our period, as our gas only changes on a daily basis - self._attributes["valid_from"] = standard_charge_result["valid_from"] - self._attributes["valid_to"] = standard_charge_result["valid_to"] + self._attributes["start"] = standard_charge_result["start"] + self._attributes["end"] = standard_charge_result["end"] else: self._state = None diff --git a/custom_components/octopus_energy/gas/__init__.py b/custom_components/octopus_energy/gas/__init__.py index c3eaf24d..f690d470 100644 --- a/custom_components/octopus_energy/gas/__init__.py +++ b/custom_components/octopus_energy/gas/__init__.py @@ -1,11 +1,11 @@ from ..utils.conversions import value_inc_vat_to_pounds -def __get_interval_end(item): - return item["interval_end"] +def __get_to(item): + return item["end"] def __sort_consumption(consumption_data): sorted = consumption_data.copy() - sorted.sort(key=__get_interval_end) + sorted.sort(key=__get_to) return sorted # Adapted from https://www.theenergyshop.com/guides/how-to-convert-gas-units-to-kwh @@ -34,7 +34,7 @@ def calculate_gas_consumption_and_cost( sorted_consumption_data = __sort_consumption(consumption_data) # Only calculate our consumption if our data has changed - if (last_reset == None or last_reset < sorted_consumption_data[0]["interval_start"]): + if (last_reset == None or last_reset < sorted_consumption_data[0]["start"]): charges = [] total_cost_in_pence = 0 @@ -56,11 +56,11 @@ def calculate_gas_consumption_and_cost( total_consumption_m3 = total_consumption_m3 + current_consumption_m3 total_consumption_kwh = total_consumption_kwh + current_consumption_kwh - consumption_from = consumption["interval_start"] - consumption_to = consumption["interval_end"] + consumption_from = consumption["start"] + consumption_to = consumption["end"] try: - rate = next(r for r in rate_data if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to) + rate = next(r for r in rate_data if r["start"] == consumption_from and r["end"] == consumption_to) except StopIteration: raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {tariff_code}") @@ -69,8 +69,8 @@ def calculate_gas_consumption_and_cost( total_cost_in_pence = total_cost_in_pence + cost charges.append({ - "from": rate["valid_from"], - "to": rate["valid_to"], + "start": rate["start"], + "end": rate["end"], "rate": value_inc_vat_to_pounds(value), "consumption_m3": current_consumption_m3, "consumption_kwh": current_consumption_kwh, @@ -79,8 +79,8 @@ def calculate_gas_consumption_and_cost( total_cost = round(total_cost_in_pence / 100, 2) total_cost_plus_standing_charge = round((total_cost_in_pence + standing_charge) / 100, 2) - last_reset = sorted_consumption_data[0]["interval_start"] - last_calculated_timestamp = sorted_consumption_data[-1]["interval_end"] + last_reset = sorted_consumption_data[0]["start"] + last_calculated_timestamp = sorted_consumption_data[-1]["end"] return { "standing_charge": round(standing_charge / 100, 2), diff --git a/custom_components/octopus_energy/gas/current_accumulative_consumption.py b/custom_components/octopus_energy/gas/current_accumulative_consumption.py index b1af886e..e42577c6 100644 --- a/custom_components/octopus_energy/gas/current_accumulative_consumption.py +++ b/custom_components/octopus_energy/gas/current_accumulative_consumption.py @@ -106,8 +106,8 @@ def state(self): "total": consumption_and_cost["total_consumption_kwh"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "consumption": charge["consumption_kwh"] }, consumption_and_cost["charges"])), "calorific_value": self._calorific_value diff --git a/custom_components/octopus_energy/gas/current_accumulative_cost.py b/custom_components/octopus_energy/gas/current_accumulative_cost.py index e8535541..4da6b46a 100644 --- a/custom_components/octopus_energy/gas/current_accumulative_cost.py +++ b/custom_components/octopus_energy/gas/current_accumulative_cost.py @@ -115,8 +115,8 @@ def state(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption_kwh"], "cost": charge["cost"], diff --git a/custom_components/octopus_energy/gas/current_rate.py b/custom_components/octopus_energy/gas/current_rate.py index c950d20b..fdc417fa 100644 --- a/custom_components/octopus_energy/gas/current_rate.py +++ b/custom_components/octopus_energy/gas/current_rate.py @@ -39,8 +39,8 @@ def __init__(self, hass: HomeAssistant, coordinator, tariff_code, meter, point, "tariff": self._tariff_code, "all_rates": [], "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "is_capped": None, } @@ -95,8 +95,8 @@ def state(self): "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, "tariff": self._tariff_code, - "valid_from": rate_information["current_rate"]["valid_from"], - "valid_to": rate_information["current_rate"]["valid_to"], + "start": rate_information["current_rate"]["start"], + "end": rate_information["current_rate"]["end"], "is_capped": rate_information["current_rate"]["is_capped"], "all_rates": rate_information["all_rates"], "applicable_rates": rate_information["applicable_rates"], @@ -109,8 +109,8 @@ def state(self): "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, "tariff": self._tariff_code, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "is_capped": None, "all_rates": [], "applicable_rates": [], diff --git a/custom_components/octopus_energy/gas/next_rate.py b/custom_components/octopus_energy/gas/next_rate.py index 6c2fd82c..84144ae9 100644 --- a/custom_components/octopus_energy/gas/next_rate.py +++ b/custom_components/octopus_energy/gas/next_rate.py @@ -35,8 +35,8 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): "is_smart_meter": self._is_smart_meter, "all_rates": [], "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, } @property @@ -89,8 +89,8 @@ def state(self): "mprn": self._mprn, "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, - "valid_from": rate_information["next_rate"]["valid_from"], - "valid_to": rate_information["next_rate"]["valid_to"], + "start": rate_information["next_rate"]["start"], + "end": rate_information["next_rate"]["end"], "applicable_rates": rate_information["applicable_rates"], } @@ -100,8 +100,8 @@ def state(self): "mprn": self._mprn, "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "applicable_rates": [], } diff --git a/custom_components/octopus_energy/gas/previous_accumulative_consumption.py b/custom_components/octopus_energy/gas/previous_accumulative_consumption.py index f08a0bca..538cf034 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_consumption.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_consumption.py @@ -147,8 +147,8 @@ async def async_update(self): "total_m3": consumption_and_cost["total_consumption_m3"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "consumption_m3": charge["consumption_m3"], "consumption_kwh": charge["consumption_kwh"] }, consumption_and_cost["charges"])), diff --git a/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py b/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py index 2e494a32..344fa55a 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_consumption_kwh.py @@ -141,8 +141,8 @@ async def async_update(self): "is_estimated": self._native_consumption_units == "m³", "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "consumption_m3": charge["consumption_m3"], "consumption_kwh": charge["consumption_kwh"] }, consumption_and_cost["charges"])), diff --git a/custom_components/octopus_energy/gas/previous_accumulative_cost.py b/custom_components/octopus_energy/gas/previous_accumulative_cost.py index 6f5ff704..500dae15 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_cost.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_cost.py @@ -145,8 +145,8 @@ async def async_update(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption_kwh"], "cost": charge["cost"], diff --git a/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py b/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py index 59e488a2..59f1bf22 100644 --- a/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py +++ b/custom_components/octopus_energy/gas/previous_accumulative_cost_override.py @@ -109,7 +109,7 @@ async def async_update(self): consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None tariff_override_key = get_gas_tariff_override_key(self._serial_number, self._mprn) - is_old_data = self._last_reset is None or (consumption_data is not None and self._last_reset < consumption_data[-1]["interval_end"]) + is_old_data = self._last_reset is None or (consumption_data is not None and self._last_reset < consumption_data[-1]["end"]) is_tariff_present = tariff_override_key in self._hass.data[DOMAIN] has_tariff_changed = is_tariff_present and self._hass.data[DOMAIN][tariff_override_key] != self._tariff_code @@ -117,8 +117,8 @@ async def async_update(self): _LOGGER.debug(f"Calculating previous gas consumption cost override for '{self._mprn}/{self._serial_number}'...") tariff_override = self._hass.data[DOMAIN][tariff_override_key] - period_from = consumption_data[0]["interval_start"] - period_to = consumption_data[-1]["interval_end"] + period_from = consumption_data[0]["start"] + period_to = consumption_data[-1]["end"] [rate_data, standing_charge] = await asyncio.gather( self._client.async_get_gas_rates(tariff_override, period_from, period_to), @@ -152,8 +152,8 @@ async def async_update(self): "total": consumption_and_cost["total_cost"], "last_evaluated": consumption_and_cost["last_evaluated"], "charges": list(map(lambda charge: { - "from": charge["from"], - "to": charge["to"], + "start": charge["start"], + "end": charge["end"], "rate": charge["rate"], "consumption": charge["consumption_kwh"], "cost": charge["cost"] diff --git a/custom_components/octopus_energy/gas/previous_rate.py b/custom_components/octopus_energy/gas/previous_rate.py index 484115d5..f61e23f9 100644 --- a/custom_components/octopus_energy/gas/previous_rate.py +++ b/custom_components/octopus_energy/gas/previous_rate.py @@ -35,8 +35,8 @@ def __init__(self, hass: HomeAssistant, coordinator, meter, point): "is_smart_meter": self._is_smart_meter, "all_rates": [], "applicable_rates": [], - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, } @property @@ -89,8 +89,8 @@ def state(self): "mprn": self._mprn, "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, - "valid_from": rate_information["previous_rate"]["valid_from"], - "valid_to": rate_information["previous_rate"]["valid_to"], + "start": rate_information["previous_rate"]["start"], + "end": rate_information["previous_rate"]["end"], "applicable_rates": rate_information["applicable_rates"], } @@ -100,8 +100,8 @@ def state(self): "mprn": self._mprn, "serial_number": self._serial_number, "is_smart_meter": self._is_smart_meter, - "valid_from": None, - "valid_to": None, + "start": None, + "end": None, "applicable_rates": [], } diff --git a/custom_components/octopus_energy/gas/standing_charge.py b/custom_components/octopus_energy/gas/standing_charge.py index 0843f8e2..dfc38dc4 100644 --- a/custom_components/octopus_energy/gas/standing_charge.py +++ b/custom_components/octopus_energy/gas/standing_charge.py @@ -71,12 +71,12 @@ def state(self): standard_charge_result = self.coordinator.data.standing_charge if self.coordinator is not None and self.coordinator.data is not None else None if standard_charge_result is not None: - self._latest_date = standard_charge_result["valid_from"] + self._latest_date = standard_charge_result["start"] self._state = standard_charge_result["value_inc_vat"] / 100 # Adjust our period, as our gas only changes on a daily basis - self._attributes["valid_from"] = standard_charge_result["valid_from"] - self._attributes["valid_to"] = standard_charge_result["valid_to"] + self._attributes["start"] = standard_charge_result["start"] + self._attributes["end"] = standard_charge_result["end"] else: self._state = None diff --git a/custom_components/octopus_energy/intelligent/__init__.py b/custom_components/octopus_energy/intelligent/__init__.py index 1d4f243f..6fa2680a 100644 --- a/custom_components/octopus_energy/intelligent/__init__.py +++ b/custom_components/octopus_energy/intelligent/__init__.py @@ -98,7 +98,7 @@ def has_intelligent_tariff(current: datetime, account_info): def __get_dispatch(rate, dispatches: list[IntelligentDispatchItem], expected_source: str): for dispatch in dispatches: - if (expected_source is None or dispatch.source == expected_source) and dispatch.start <= rate["valid_from"] and dispatch.end >= rate["valid_to"]: + if (expected_source is None or dispatch.source == expected_source) and dispatch.start <= rate["start"] and dispatch.end >= rate["end"]: return dispatch return None @@ -114,8 +114,8 @@ def adjust_intelligent_rates(rates, planned_dispatches: list[IntelligentDispatch if __get_dispatch(rate, planned_dispatches, "smart-charge") is not None or __get_dispatch(rate, completed_dispatches, None) is not None: adjusted_rates.append({ - "valid_from": rate["valid_from"], - "valid_to": rate["valid_to"], + "start": rate["start"], + "end": rate["end"], "value_inc_vat": off_peak_rate["value_inc_vat"], "is_capped": rate["is_capped"] if "is_capped" in rate else False, "is_intelligent_adjusted": True diff --git a/custom_components/octopus_energy/statistics/__init__.py b/custom_components/octopus_energy/statistics/__init__.py index c80eb43e..4a41f406 100644 --- a/custom_components/octopus_energy/statistics/__init__.py +++ b/custom_components/octopus_energy/statistics/__init__.py @@ -13,7 +13,7 @@ _LOGGER = logging.getLogger(__name__) def build_consumption_statistics(current: datetime, consumptions, rates, consumption_key: str, latest_total_sum: float, latest_peak_sum: float, latest_off_peak_sum: float): - last_reset = consumptions[0]["from"].replace(minute=0, second=0, microsecond=0) + last_reset = consumptions[0]["start"].replace(minute=0, second=0, microsecond=0) sums = { "total": latest_total_sum, "peak": latest_peak_sum, @@ -34,11 +34,11 @@ def build_consumption_statistics(current: datetime, consumptions, rates, consump for index in range(len(consumptions)): consumption = consumptions[index] - consumption_from = consumption["from"] - consumption_to = consumption["to"] + consumption_from = consumption["start"] + consumption_to = consumption["end"] try: - rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to) + rate = next(r for r in rates if r["start"] == consumption_from and r["end"] == consumption_to) except StopIteration: raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to}") @@ -49,7 +49,7 @@ def build_consumption_statistics(current: datetime, consumptions, rates, consump sums["peak"] += consumption[consumption_key] states["peak"] += consumption[consumption_key] - start = consumption["from"].replace(minute=0, second=0, microsecond=0) + start = consumption["start"].replace(minute=0, second=0, microsecond=0) sums["total"] += consumption[consumption_key] states["total"] += consumption[consumption_key] @@ -90,7 +90,7 @@ def build_consumption_statistics(current: datetime, consumptions, rates, consump } def build_cost_statistics(current: datetime, consumptions, rates, consumption_key: str, latest_total_sum: float, latest_peak_sum: float, latest_off_peak_sum: float): - last_reset = consumptions[0]["from"].replace(minute=0, second=0, microsecond=0) + last_reset = consumptions[0]["start"].replace(minute=0, second=0, microsecond=0) sums = { "total": latest_total_sum, "peak": latest_peak_sum, @@ -111,12 +111,12 @@ def build_cost_statistics(current: datetime, consumptions, rates, consumption_ke for index in range(len(consumptions)): consumption = consumptions[index] - consumption_from = consumption["from"] - consumption_to = consumption["to"] - start = consumption["from"].replace(minute=0, second=0, microsecond=0) + consumption_from = consumption["start"] + consumption_to = consumption["end"] + start = consumption["start"].replace(minute=0, second=0, microsecond=0) try: - rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to) + rate = next(r for r in rates if r["start"] == consumption_from and r["end"] == consumption_to) except StopIteration: raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to}") diff --git a/custom_components/octopus_energy/statistics/consumption.py b/custom_components/octopus_energy/statistics/consumption.py index 24d0074b..6ca10cbd 100644 --- a/custom_components/octopus_energy/statistics/consumption.py +++ b/custom_components/octopus_energy/statistics/consumption.py @@ -41,13 +41,13 @@ async def async_import_external_statistics_from_consumption( statistic_id = f"{DOMAIN}:{unique_id}".lower() # Our sum needs to be based from the last total, so we need to grab the last record from the previous day - total_sum = await async_get_last_sum(hass, consumptions[0]["from"], statistic_id) + total_sum = await async_get_last_sum(hass, consumptions[0]["start"], statistic_id) peak_statistic_id = f'{statistic_id}_peak' - peak_sum = await async_get_last_sum(hass, consumptions[0]["from"], peak_statistic_id) + peak_sum = await async_get_last_sum(hass, consumptions[0]["start"], peak_statistic_id) off_peak_statistic_id = f'{statistic_id}_off_peak' - off_peak_sum = await async_get_last_sum(hass, consumptions[0]["from"], off_peak_statistic_id) + off_peak_sum = await async_get_last_sum(hass, consumptions[0]["start"], off_peak_statistic_id) statistics = build_consumption_statistics(current, consumptions, rates, consumption_key, total_sum, peak_sum, off_peak_sum) diff --git a/custom_components/octopus_energy/statistics/cost.py b/custom_components/octopus_energy/statistics/cost.py index 7ece7130..a0338265 100644 --- a/custom_components/octopus_energy/statistics/cost.py +++ b/custom_components/octopus_energy/statistics/cost.py @@ -41,13 +41,13 @@ async def async_import_external_statistics_from_cost( statistic_id = f"{DOMAIN}:{unique_id}".lower() # Our sum needs to be based from the last total, so we need to grab the last record from the previous day - total_sum = await async_get_last_sum(hass, consumptions[0]["from"], statistic_id) + total_sum = await async_get_last_sum(hass, consumptions[0]["start"], statistic_id) peak_statistic_id = f'{statistic_id}_peak' - peak_sum = await async_get_last_sum(hass, consumptions[0]["from"], peak_statistic_id) + peak_sum = await async_get_last_sum(hass, consumptions[0]["start"], peak_statistic_id) off_peak_statistic_id = f'{statistic_id}_off_peak' - off_peak_sum = await async_get_last_sum(hass, consumptions[0]["from"], off_peak_statistic_id) + off_peak_sum = await async_get_last_sum(hass, consumptions[0]["start"], off_peak_statistic_id) statistics = build_cost_statistics(current, consumptions, rates, consumption_key, total_sum, peak_sum, off_peak_sum) diff --git a/custom_components/octopus_energy/target_rates/__init__.py b/custom_components/octopus_energy/target_rates/__init__.py index b1a50239..f9a960f7 100644 --- a/custom_components/octopus_energy/target_rates/__init__.py +++ b/custom_components/octopus_energy/target_rates/__init__.py @@ -62,7 +62,7 @@ def __get_applicable_rates(current_date: datetime, target_start_time: str, targe applicable_rates = [] if rates is not None: for rate in rates: - if rate["valid_from"] >= target_start and (target_end is None or rate["valid_to"] <= target_end): + if rate["start"] >= target_start and (target_end is None or rate["end"] <= target_end): new_rate = dict(rate) new_rate["value_inc_vat"] = value_inc_vat_to_pounds(rate["value_inc_vat"]) @@ -79,7 +79,7 @@ def __get_applicable_rates(current_date: datetime, target_start_time: str, targe return applicable_rates def __get_valid_to(rate): - return rate["valid_to"] + return rate["end"] def calculate_continuous_times( current_date: datetime, @@ -149,14 +149,14 @@ def calculate_intermittent_times( if find_last_rates: if search_for_highest_rate: - applicable_rates.sort(key= lambda rate: (-rate["value_inc_vat"], -rate["valid_to"].timestamp())) + applicable_rates.sort(key= lambda rate: (-rate["value_inc_vat"], -rate["end"].timestamp())) else: - applicable_rates.sort(key= lambda rate: (rate["value_inc_vat"], -rate["valid_to"].timestamp())) + applicable_rates.sort(key= lambda rate: (rate["value_inc_vat"], -rate["end"].timestamp())) else: if search_for_highest_rate: - applicable_rates.sort(key= lambda rate: (-rate["value_inc_vat"], rate["valid_to"])) + applicable_rates.sort(key= lambda rate: (-rate["value_inc_vat"], rate["end"])) else: - applicable_rates.sort(key= lambda rate: (rate["value_inc_vat"], rate["valid_to"])) + applicable_rates.sort(key= lambda rate: (rate["value_inc_vat"], rate["end"])) applicable_rates = applicable_rates[:total_required_rates] @@ -194,26 +194,26 @@ def get_target_rate_info(current_date: datetime, applicable_rates, offset: str = # intermittent rates. applicable_rates.sort(key=__get_valid_to) applicable_rate_blocks = list() - block_valid_from = applicable_rates[0]["valid_from"] + block_valid_from = applicable_rates[0]["start"] total_cost = 0 min_cost = None max_cost = None for index, rate in enumerate(applicable_rates): - if (index > 0 and applicable_rates[index - 1]["valid_to"] != rate["valid_from"]): - diff = applicable_rates[index - 1]["valid_to"] - block_valid_from + if (index > 0 and applicable_rates[index - 1]["end"] != rate["start"]): + diff = applicable_rates[index - 1]["end"] - block_valid_from minutes = diff.total_seconds() / 60 applicable_rate_blocks.append({ - "valid_from": block_valid_from, - "valid_to": applicable_rates[index - 1]["valid_to"], + "start": block_valid_from, + "end": applicable_rates[index - 1]["end"], "duration_in_hours": minutes / 60, "average_cost": total_cost / (minutes / 30), "min_cost": min_cost, "max_cost": max_cost }) - block_valid_from = rate["valid_from"] + block_valid_from = rate["start"] total_cost = 0 min_cost = None max_cost = None @@ -233,11 +233,11 @@ def get_target_rate_info(current_date: datetime, applicable_rates, offset: str = overall_max_cost = rate["value_inc_vat"] # Make sure our final block is added - diff = applicable_rates[-1]["valid_to"] - block_valid_from + diff = applicable_rates[-1]["end"] - block_valid_from minutes = diff.total_seconds() / 60 applicable_rate_blocks.append({ - "valid_from": block_valid_from, - "valid_to": applicable_rates[-1]["valid_to"], + "start": block_valid_from, + "end": applicable_rates[-1]["end"], "duration_in_hours": minutes / 60, "average_cost": total_cost / (minutes / 30), "min_cost": min_cost, @@ -247,11 +247,11 @@ def get_target_rate_info(current_date: datetime, applicable_rates, offset: str = # Find out if we're within an active block, or find the next block for index, rate in enumerate(applicable_rate_blocks): if (offset is not None): - valid_from = apply_offset(rate["valid_from"], offset) - valid_to = apply_offset(rate["valid_to"], offset) + valid_from = apply_offset(rate["start"], offset) + valid_to = apply_offset(rate["end"], offset) else: - valid_from = rate["valid_from"] - valid_to = rate["valid_to"] + valid_from = rate["start"] + valid_to = rate["end"] if current_date >= valid_from and current_date < valid_to: current_duration_in_hours = rate["duration_in_hours"] diff --git a/custom_components/octopus_energy/target_rates/target_rate.py b/custom_components/octopus_energy/target_rates/target_rate.py index 8084d4ba..0340d53f 100644 --- a/custom_components/octopus_energy/target_rates/target_rate.py +++ b/custom_components/octopus_energy/target_rates/target_rate.py @@ -119,7 +119,7 @@ def is_on(self): # If all of our target times have passed, it's time to recalculate the next set all_rates_in_past = True for rate in self._target_rates: - if rate["valid_to"] > current_date: + if rate["end"] > current_date: all_rates_in_past = False break diff --git a/custom_components/octopus_energy/utils/__init__.py b/custom_components/octopus_energy/utils/__init__.py index 88771928..ca60fd1e 100644 --- a/custom_components/octopus_energy/utils/__init__.py +++ b/custom_components/octopus_energy/utils/__init__.py @@ -46,13 +46,13 @@ def get_active_tariff_code(utcnow: datetime, agreements): if agreement["tariff_code"] is None: continue - valid_from = as_utc(parse_datetime(agreement["valid_from"])) + valid_from = as_utc(parse_datetime(agreement["start"])) if utcnow >= valid_from and (latest_valid_from is None or valid_from > latest_valid_from): latest_valid_to = None - if "valid_to" in agreement and agreement["valid_to"] is not None: - latest_valid_to = as_utc(parse_datetime(agreement["valid_to"])) + if "end" in agreement and agreement["end"] is not None: + latest_valid_to = as_utc(parse_datetime(agreement["end"])) if latest_valid_to is None or latest_valid_to >= utcnow: latest_agreement = agreement @@ -71,7 +71,7 @@ def get_off_peak_cost(current: datetime, rates: list): rate_charges = {} if rates is not None: for rate in rates: - if rate["valid_from"] >= today_start and rate["valid_to"] <= today_end: + if rate["start"] >= today_start and rate["end"] <= today_end: value = rate["value_inc_vat"] rate_charges[value] = (rate_charges[value] if value in rate_charges else value) if off_peak_cost is None or off_peak_cost > rate["value_inc_vat"]: @@ -94,8 +94,8 @@ def private_rates_to_public_rates(rates: list): for rate in rates: new_rate = { - "valid_from": rate["valid_from"], - "valid_to": rate["valid_to"], + "start": rate["start"], + "end": rate["end"], "value_inc_vat": value_inc_vat_to_pounds(rate["value_inc_vat"]) } diff --git a/custom_components/octopus_energy/utils/rate_information.py b/custom_components/octopus_energy/utils/rate_information.py index a7bf487d..61dd9830 100644 --- a/custom_components/octopus_energy/utils/rate_information.py +++ b/custom_components/octopus_energy/utils/rate_information.py @@ -25,10 +25,10 @@ def get_current_rate_information(rates, now: datetime): elif current_rate is not None and len(applicable_rates) > 0 and applicable_rates[0]["value_inc_vat"] != period["value_inc_vat"]: is_adding_applicable_rates = False - if now >= period["valid_from"] and now <= period["valid_to"]: + if now >= period["start"] and now <= period["end"]: current_rate = period - if period["valid_from"] >= min_target and period["valid_to"] <= max_target: + if period["start"] >= min_target and period["end"] <= max_target: if min_rate_value is None or period["value_inc_vat"] < min_rate_value: min_rate_value = period["value_inc_vat"] @@ -41,22 +41,22 @@ def get_current_rate_information(rates, now: datetime): if len(applicable_rates) > 0 and current_rate is not None: return { "all_rates": list(map(lambda x: { - "valid_from": x["valid_from"], - "valid_to": x["valid_to"], + "start": x["start"], + "end": x["end"], "value_inc_vat": value_inc_vat_to_pounds(x["value_inc_vat"]), "is_capped": x["is_capped"], "is_intelligent_adjusted": x["is_intelligent_adjusted"] if "is_intelligent_adjusted" in x else False }, rates)), "applicable_rates": list(map(lambda x: { - "valid_from": x["valid_from"], - "valid_to": x["valid_to"], + "start": x["start"], + "end": x["end"], "value_inc_vat": value_inc_vat_to_pounds(x["value_inc_vat"]), "is_capped": x["is_capped"], "is_intelligent_adjusted": x["is_intelligent_adjusted"] if "is_intelligent_adjusted" in x else False }, applicable_rates)), "current_rate": { - "valid_from": applicable_rates[0]["valid_from"], - "valid_to": applicable_rates[-1]["valid_to"], + "start": applicable_rates[0]["start"], + "end": applicable_rates[-1]["end"], "value_inc_vat": value_inc_vat_to_pounds(applicable_rates[0]["value_inc_vat"]), "is_capped": current_rate["is_capped"], "is_intelligent_adjusted": current_rate["is_intelligent_adjusted"] if "is_intelligent_adjusted" in current_rate else False @@ -68,8 +68,8 @@ def get_current_rate_information(rates, now: datetime): return None -def get_valid_from(rate): - return rate["valid_from"] +def get_from(rate): + return rate["start"] def get_previous_rate_information(rates, now: datetime): current_rate = None @@ -77,7 +77,7 @@ def get_previous_rate_information(rates, now: datetime): if rates is not None: for period in reversed(rates): - if now >= period["valid_from"] and now <= period["valid_to"]: + if now >= period["start"] and now <= period["end"]: current_rate = period if current_rate is not None and current_rate["value_inc_vat"] != period["value_inc_vat"]: @@ -86,20 +86,20 @@ def get_previous_rate_information(rates, now: datetime): else: break - applicable_rates.sort(key=get_valid_from) + applicable_rates.sort(key=get_from) if len(applicable_rates) > 0 and current_rate is not None: return { "applicable_rates": list(map(lambda x: { - "valid_from": x["valid_from"], - "valid_to": x["valid_to"], + "start": x["start"], + "end": x["end"], "value_inc_vat": value_inc_vat_to_pounds(x["value_inc_vat"]), "is_capped": x["is_capped"], "is_intelligent_adjusted": x["is_intelligent_adjusted"] if "is_intelligent_adjusted" in x else False }, applicable_rates)), "previous_rate": { - "valid_from": applicable_rates[0]["valid_from"], - "valid_to": applicable_rates[-1]["valid_to"], + "start": applicable_rates[0]["start"], + "end": applicable_rates[-1]["end"], "value_inc_vat": value_inc_vat_to_pounds(applicable_rates[0]["value_inc_vat"]), } } @@ -112,7 +112,7 @@ def get_next_rate_information(rates, now: datetime): if rates is not None: for period in rates: - if now >= period["valid_from"] and now <= period["valid_to"]: + if now >= period["start"] and now <= period["end"]: current_rate = period if current_rate is not None and current_rate["value_inc_vat"] != period["value_inc_vat"]: @@ -124,15 +124,15 @@ def get_next_rate_information(rates, now: datetime): if len(applicable_rates) > 0 and current_rate is not None: return { "applicable_rates": list(map(lambda x: { - "valid_from": x["valid_from"], - "valid_to": x["valid_to"], + "start": x["start"], + "end": x["end"], "value_inc_vat": value_inc_vat_to_pounds(x["value_inc_vat"]), "is_capped": x["is_capped"], "is_intelligent_adjusted": x["is_intelligent_adjusted"] if "is_intelligent_adjusted" in x else False }, applicable_rates)), "next_rate": { - "valid_from": applicable_rates[0]["valid_from"], - "valid_to": applicable_rates[-1]["valid_to"], + "start": applicable_rates[0]["start"], + "end": applicable_rates[-1]["end"], "value_inc_vat": value_inc_vat_to_pounds(applicable_rates[0]["value_inc_vat"]), } } diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 43af83c7..c8ab97be 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -46,8 +46,8 @@ def create_consumption_data(period_from, period_to, reverse = False): current_valid_to = current_valid_from + timedelta(minutes=30) consumption.append({ - "interval_start": current_valid_from, - "interval_end": current_valid_to, + "start": current_valid_from, + "end": current_valid_to, "consumption": 1 }) @@ -55,7 +55,7 @@ def create_consumption_data(period_from, period_to, reverse = False): if reverse == True: def get_interval_start(item): - return item["interval_start"] + return item["start"] consumption.sort(key=get_interval_start, reverse=True) @@ -71,8 +71,8 @@ def create_rate_data(period_from, period_to, expected_rates: list): current_valid_to = current_valid_from + timedelta(minutes=30) rates.append({ - "valid_from": current_valid_from, - "valid_to": current_valid_to, + "start": current_valid_from, + "end": current_valid_to, "value_inc_vat": expected_rates[rate_index], "is_capped": False }) diff --git a/tests/integration/api_client/test_get_account.py b/tests/integration/api_client/test_get_account.py index e6e78139..34157752 100644 --- a/tests/integration/api_client/test_get_account.py +++ b/tests/integration/api_client/test_get_account.py @@ -34,8 +34,8 @@ async def test_when_get_account_is_called_then_electricity_and_gas_points_return assert "agreements" in meter_point assert len(meter_point["agreements"]) == 1 assert "tariff_code" in meter_point["agreements"][0] - assert "valid_from" in meter_point["agreements"][0] - assert "valid_to" in meter_point["agreements"][0] + assert "start" in meter_point["agreements"][0] + assert "end" in meter_point["agreements"][0] assert "gas_meter_points" in account assert len(account["gas_meter_points"]) == 1 @@ -53,8 +53,8 @@ async def test_when_get_account_is_called_then_electricity_and_gas_points_return assert "agreements" in meter_point assert len(meter_point["agreements"]) == 1 assert "tariff_code" in meter_point["agreements"][0] - assert "valid_from" in meter_point["agreements"][0] - assert "valid_to" in meter_point["agreements"][0] + assert "start" in meter_point["agreements"][0] + assert "end" in meter_point["agreements"][0] @pytest.mark.asyncio async def test_when_get_account_is_called_and_not_found_then_none_returned(): diff --git a/tests/integration/api_client/test_get_electricity_rates.py b/tests/integration/api_client/test_get_electricity_rates.py index b437e357..d6f8fb48 100644 --- a/tests/integration/api_client/test_get_electricity_rates.py +++ b/tests/integration/api_client/test_get_electricity_rates.py @@ -28,17 +28,17 @@ async def async_assert_electricity_data(tariff, is_smart_meter, price_cap, perio 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 "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to assert "value_inc_vat" in item expected_value = None if expected_rates is not None: for rate in expected_rates: - if rate["valid_from"] <= item["valid_from"] and rate["valid_to"] >= item["valid_to"]: + if rate["start"] <= item["start"] and rate["end"] >= item["end"]: expected_value = rate["value_inc_vat"] if price_cap is not None: @@ -77,32 +77,32 @@ async def test_when_get_electricity_rates_is_called_with_flux_tariff_then_data_i expected_flux_rates = [{ "value_exc_vat": 32.1207, "value_inc_vat": 33.726735, - "valid_from": datetime.strptime("2023-03-27T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2023-03-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2023-03-27T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2023-03-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), }, { "value_exc_vat": 44.969, "value_inc_vat": 47.21745, - "valid_from": datetime.strptime("2023-03-27T15:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2023-03-27T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2023-03-27T15:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2023-03-27T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), }, { "value_exc_vat": 32.1207, "value_inc_vat": 33.726735, - "valid_from": datetime.strptime("2023-03-27T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2023-03-27T15:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2023-03-27T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2023-03-27T15:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), }, { "value_exc_vat": 19.2724, "value_inc_vat": 20.23602, - "valid_from": datetime.strptime("2023-03-27T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2023-03-27T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2023-03-27T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2023-03-27T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), }, { "value_exc_vat": 32.1207, "value_inc_vat": 33.726735, - "valid_from": datetime.strptime("2023-03-26T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2023-03-27T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2023-03-26T18:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2023-03-27T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), }] await async_assert_electricity_data( @@ -130,7 +130,7 @@ async def test_when_get_electricity_rates_is_called_with_duel_rate_tariff_dumb_m # Make sure all periods within the expected cheapest period have our cheapest rate for item in data: - if item["valid_from"] >= cheapest_rate_from and item["valid_to"] <= cheapest_rate_to: + if item["start"] >= cheapest_rate_from and item["end"] <= cheapest_rate_to: if price_cap is not None and item["value_inc_vat"] > price_cap: assert item["value_inc_vat"] == price_cap else: @@ -154,7 +154,7 @@ async def test_when_get_electricity_rates_is_called_with_duel_rate_tariff_smart_ # Make sure all periods within the expected cheapest period have our cheapest rate for item in data: - if item["valid_from"] >= cheapest_rate_from and item["valid_to"] <= cheapest_rate_to: + if item["start"] >= cheapest_rate_from and item["end"] <= cheapest_rate_to: if price_cap is not None and item["value_inc_vat"] > price_cap: assert item["value_inc_vat"] == price_cap else: @@ -199,11 +199,11 @@ async def test_when_get_electricity_rates_is_called_with_cosy_tariff_then_data_i # Make sure all periods within the expected cheapest/expensive period have our cheapest/expensive rate for item in data: - if (item["valid_from"].hour >= 3 and item["valid_from"].hour < 6): + if (item["start"].hour >= 3 and item["start"].hour < 6): assert item["value_inc_vat"] == cheapest_rate - elif (item["valid_from"].hour >= 12 and item["valid_from"].hour < 15): + elif (item["start"].hour >= 12 and item["start"].hour < 15): assert item["value_inc_vat"] == cheapest_rate - elif (item["valid_from"].hour >= 15 and item["valid_from"].hour < 18): + elif (item["start"].hour >= 15 and item["start"].hour < 18): assert item["value_inc_vat"] == expensive_rate else: assert item["value_inc_vat"] != cheapest_rate diff --git a/tests/integration/api_client/test_get_gas_rates.py b/tests/integration/api_client/test_get_gas_rates.py index a1696067..f0a2bdc9 100644 --- a/tests/integration/api_client/test_get_gas_rates.py +++ b/tests/integration/api_client/test_get_gas_rates.py @@ -31,10 +31,10 @@ async def test_when_get_gas_rates_is_called_for_existent_tariff_then_rates_are_r 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 "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to assert "value_inc_vat" in item if price_cap is not None: diff --git a/tests/integration/api_client/test_get_saving_sessions.py b/tests/integration/api_client/test_get_saving_sessions.py index 7384ef52..0f82ae5d 100644 --- a/tests/integration/api_client/test_get_saving_sessions.py +++ b/tests/integration/api_client/test_get_saving_sessions.py @@ -31,4 +31,4 @@ async def test_when_get_saving_sessions_is_called_then_events_are_returned(): assert event.code is None assert event.start is not None assert event.end is not None - assert event.octopoints >= 0 \ No newline at end of file + assert event.octopoints is None or event.octopoints >= 0 \ No newline at end of file diff --git a/tests/integration/coordinators/test_fetch_consumption_and_rates.py b/tests/integration/coordinators/test_fetch_consumption_and_rates.py index a85b6b18..0576d046 100644 --- a/tests/integration/coordinators/test_fetch_consumption_and_rates.py +++ b/tests/integration/coordinators/test_fetch_consumption_and_rates.py @@ -77,10 +77,10 @@ def fire_event(name, metadata): for item in result["consumption"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "interval_start" in item - assert item["interval_start"] == expected_valid_from - assert "interval_end" in item - assert item["interval_end"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to diff --git a/tests/integration/electricity/test_calculate_electricity_consumption_and_cost.py b/tests/integration/electricity/test_calculate_electricity_consumption_and_cost.py index 1f31327a..1a6bcf5e 100644 --- a/tests/integration/electricity/test_calculate_electricity_consumption_and_cost.py +++ b/tests/integration/electricity/test_calculate_electricity_consumption_and_cost.py @@ -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_evaluated"] == consumption_and_rates_result["consumption"][-1]["interval_end"] + assert result["last_evaluated"] == consumption_and_rates_result["consumption"][-1]["end"] assert len(result["charges"]) == 48 @@ -81,10 +81,10 @@ def fire_event(name, metadata): for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to diff --git a/tests/integration/gas/test_calculate_gas_consumption_and_cost.py b/tests/integration/gas/test_calculate_gas_consumption_and_cost.py index f8d3b3fe..9bfe9097 100644 --- a/tests/integration/gas/test_calculate_gas_consumption_and_cost.py +++ b/tests/integration/gas/test_calculate_gas_consumption_and_cost.py @@ -68,7 +68,7 @@ def fire_event(name, metadata): # Assert assert result is not None - assert result["last_evaluated"] == consumption_and_rates_result["consumption"][-1]["interval_end"] + assert result["last_evaluated"] == consumption_and_rates_result["consumption"][-1]["end"] assert result["standing_charge"] == round(standard_charge_result["value_inc_vat"] / 100, 2) if consumption_units == "m³": @@ -89,10 +89,10 @@ def fire_event(name, metadata): for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 8ddcea11..9a6387f1 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -5,7 +5,7 @@ logging.getLogger().setLevel(logging.DEBUG) -def create_consumption_data(period_from, period_to, reverse = False, from_key = "interval_start", to_key = "interval_end"): +def create_consumption_data(period_from, period_to, reverse = False, from_key = "start", to_key = "end"): consumption = [] current_valid_from = period_from current_valid_to = None @@ -38,8 +38,8 @@ def create_rate_data(period_from, period_to, expected_rates: list): current_valid_to = current_valid_from + timedelta(minutes=30) rates.append({ - "valid_from": current_valid_from, - "valid_to": current_valid_to, + "start": current_valid_from, + "end": current_valid_to, "value_inc_vat": expected_rates[rate_index], "is_capped": False }) diff --git a/tests/unit/config/test_validate_main_config.py b/tests/unit/config/test_validate_main_config.py index ae1cebe1..b1c3c4c5 100644 --- a/tests/unit/config/test_validate_main_config.py +++ b/tests/unit/config/test_validate_main_config.py @@ -28,8 +28,8 @@ def get_account_info(tariff_code: str = "E-1R-SUPER-GREEN-24M-21-07-30-C"): "mpan": mpan, "agreements": [ { - "valid_from": "2023-08-01T00:00:00+01:00", - "valid_to": "2023-09-01T00:00:00+01:00", + "start": "2023-08-01T00:00:00+01:00", + "end": "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } diff --git a/tests/unit/config/test_validate_target_rate_config.py b/tests/unit/config/test_validate_target_rate_config.py index 9a0354a6..bd5a38e7 100644 --- a/tests/unit/config/test_validate_target_rate_config.py +++ b/tests/unit/config/test_validate_target_rate_config.py @@ -14,8 +14,8 @@ def get_account_info(tariff_code: str = "E-1R-SUPER-GREEN-24M-21-07-30-C", is_ac "mpan": mpan, "agreements": [ { - "valid_from": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-01-01T00:00:00+01:00", - "valid_to": "2023-09-01T00:00:00+01:00" if is_active_agreement else "2023-02-01T00:00:00+01:00", + "start": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-01-01T00:00:00+01:00", + "end": "2023-09-01T00:00:00+01:00" if is_active_agreement else "2023-02-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } diff --git a/tests/unit/coordinators/test_async_refresh_electricity_rates_data.py b/tests/unit/coordinators/test_async_refresh_electricity_rates_data.py index ec246af8..d22bf9f1 100644 --- a/tests/unit/coordinators/test_async_refresh_electricity_rates_data.py +++ b/tests/unit/coordinators/test_async_refresh_electricity_rates_data.py @@ -35,8 +35,8 @@ def get_account_info(is_active_agreement = True): ], "agreements": [ { - "valid_from": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", + "start": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", + "end": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } @@ -53,10 +53,10 @@ def assert_raised_events(raised_events: dict, expected_event_name: str, expected assert raised_events[expected_event_name]["serial_number"] == serial_number assert "rates" in raised_events[expected_event_name] assert len(raised_events[expected_event_name]["rates"]) > 2 - assert "valid_from" in raised_events[expected_event_name]["rates"][0] - assert raised_events[expected_event_name]["rates"][0]["valid_from"] == expected_valid_from - assert "valid_to" in raised_events[expected_event_name]["rates"][-1] - assert raised_events[expected_event_name]["rates"][-1]["valid_to"] == expected_valid_to + assert "start" in raised_events[expected_event_name]["rates"][0] + assert raised_events[expected_event_name]["rates"][0]["start"] == expected_valid_from + assert "end" in raised_events[expected_event_name]["rates"][-1] + assert raised_events[expected_event_name]["rates"][-1]["end"] == expected_valid_to @pytest.mark.asyncio async def test_when_account_info_is_none_then_existing_rates_returned(): @@ -347,7 +347,7 @@ def fire_event(name, metadata): expected_rate = expected_retrieved_rates.rates[index] actual_rate = retrieved_rates.rates[index] - if is_export_meter == False and actual_rate["valid_from"] >= expected_dispatch_start and actual_rate["valid_to"] <= expected_dispatch_end: + if is_export_meter == False and actual_rate["start"] >= expected_dispatch_start and actual_rate["end"] <= expected_dispatch_end: assert "is_intelligent_adjusted" in actual_rate assert actual_rate["is_intelligent_adjusted"] == True assert actual_rate["value_inc_vat"] == 1 diff --git a/tests/unit/coordinators/test_async_refresh_electricity_standing_charge_data.py b/tests/unit/coordinators/test_async_refresh_electricity_standing_charge_data.py index 56e1164e..ba15da56 100644 --- a/tests/unit/coordinators/test_async_refresh_electricity_standing_charge_data.py +++ b/tests/unit/coordinators/test_async_refresh_electricity_standing_charge_data.py @@ -33,8 +33,8 @@ def get_account_info(is_active_agreement = True): ], "agreements": [ { - "valid_from": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", + "start": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", + "end": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } @@ -46,8 +46,8 @@ def get_account_info(is_active_agreement = True): @pytest.mark.asyncio async def test_when_account_info_is_none_then_existing_standing_charge_returned(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -76,8 +76,8 @@ async def async_mocked_get_electricity_standing_charge(*args, **kwargs): @pytest.mark.asyncio async def test_when_no_active_standing_charge_then_none_returned(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -111,8 +111,8 @@ async def test_when_current_is_not_thirty_minutes_then_existing_standing_charge_ current = datetime.strptime("2023-07-14T10:30:01+01:00", "%Y-%m-%dT%H:%M:%S%z").replace(minute=minute) expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -123,8 +123,8 @@ async def async_mocked_get_electricity_standing_charge(*args, **kwargs): account_info = get_account_info() existing_standing_charge = ElectricityStandingChargeCoordinatorResult(period_from, { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.10 }) @@ -153,8 +153,8 @@ async def test_when_existing_standing_charge_is_none_then_standing_charge_retrie expected_period_from = current.replace(hour=0, minute=0, second=0, microsecond=0) expected_period_to = expected_period_from + timedelta(days=1) expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -191,8 +191,8 @@ async def async_mocked_get_electricity_standing_charge(*args, **kwargs): @pytest.mark.asyncio async def test_when_existing_standing_charge_is_old_then_standing_charge_retrieved(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False diff --git a/tests/unit/coordinators/test_async_refresh_gas_rates_data.py b/tests/unit/coordinators/test_async_refresh_gas_rates_data.py index ea1d2181..efa2b41e 100644 --- a/tests/unit/coordinators/test_async_refresh_gas_rates_data.py +++ b/tests/unit/coordinators/test_async_refresh_gas_rates_data.py @@ -34,8 +34,8 @@ def get_account_info(is_active_agreement = True): ], "agreements": [ { - "valid_from": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", + "start": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", + "end": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } @@ -52,10 +52,10 @@ def assert_raised_events(raised_events: dict, expected_event_name: str, expected assert raised_events[expected_event_name]["serial_number"] == serial_number assert "rates" in raised_events[expected_event_name] assert len(raised_events[expected_event_name]["rates"]) > 2 - assert "valid_from" in raised_events[expected_event_name]["rates"][0] - assert raised_events[expected_event_name]["rates"][0]["valid_from"] == expected_valid_from - assert "valid_to" in raised_events[expected_event_name]["rates"][-1] - assert raised_events[expected_event_name]["rates"][-1]["valid_to"] == expected_valid_to + assert "start" in raised_events[expected_event_name]["rates"][0] + assert raised_events[expected_event_name]["rates"][0]["start"] == expected_valid_from + assert "end" in raised_events[expected_event_name]["rates"][-1] + assert raised_events[expected_event_name]["rates"][-1]["end"] == expected_valid_to @pytest.mark.asyncio async def test_when_account_info_is_none_then_existing_rates_returned(): diff --git a/tests/unit/coordinators/test_async_refresh_gas_standing_charge_data.py b/tests/unit/coordinators/test_async_refresh_gas_standing_charge_data.py index 361f9452..bc056c63 100644 --- a/tests/unit/coordinators/test_async_refresh_gas_standing_charge_data.py +++ b/tests/unit/coordinators/test_async_refresh_gas_standing_charge_data.py @@ -33,8 +33,8 @@ def get_account_info(is_active_agreement = True): ], "agreements": [ { - "valid_from": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", + "start": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", + "end": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } @@ -46,8 +46,8 @@ def get_account_info(is_active_agreement = True): @pytest.mark.asyncio async def test_when_account_info_is_none_then_existing_standing_charge_returned(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -76,8 +76,8 @@ async def async_mocked_get_gas_standing_charge(*args, **kwargs): @pytest.mark.asyncio async def test_when_no_active_standing_charge_then_none_returned(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -111,8 +111,8 @@ async def test_when_current_is_not_thirty_minutes_then_existing_standing_charge_ current = datetime.strptime("2023-07-14T10:30:01+01:00", "%Y-%m-%dT%H:%M:%S%z").replace(minute=minute) expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -123,8 +123,8 @@ async def async_mocked_get_gas_standing_charge(*args, **kwargs): account_info = get_account_info() existing_standing_charge = GasStandingChargeCoordinatorResult(period_from, { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.10 }) @@ -152,8 +152,8 @@ async def test_when_existing_standing_charge_is_none_then_standing_charge_retrie expected_period_from = current.replace(hour=0, minute=0, second=0, microsecond=0) expected_period_to = expected_period_from + timedelta(days=1) expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False @@ -190,8 +190,8 @@ async def async_mocked_get_gas_standing_charge(*args, **kwargs): @pytest.mark.asyncio async def test_when_existing_standing_charge_is_old_then_standing_charge_retrieved(): expected_standing_charge = { - "valid_from": period_from, - "valid_to": period_to, + "start": period_from, + "end": period_to, "value_inc_vat": 0.30 } standing_charge_returned = False diff --git a/tests/unit/coordinators/test_previous_consumption_and_rates.py b/tests/unit/coordinators/test_previous_consumption_and_rates.py index 6f73b223..e613c303 100644 --- a/tests/unit/coordinators/test_previous_consumption_and_rates.py +++ b/tests/unit/coordinators/test_previous_consumption_and_rates.py @@ -25,10 +25,10 @@ def assert_raised_events( assert raised_events[expected_event_name]["serial_number"] == sensor_serial_number assert "rates" in raised_events[expected_event_name] assert len(raised_events[expected_event_name]["rates"]) > 2 - assert "valid_from" in raised_events[expected_event_name]["rates"][0] - assert raised_events[expected_event_name]["rates"][0]["valid_from"] == expected_valid_from - assert "valid_to" in raised_events[expected_event_name]["rates"][-1] - assert raised_events[expected_event_name]["rates"][-1]["valid_to"] == expected_valid_to + assert "start" in raised_events[expected_event_name]["rates"][0] + assert raised_events[expected_event_name]["rates"][0]["start"] == expected_valid_from + assert "end" in raised_events[expected_event_name]["rates"][-1] + assert raised_events[expected_event_name]["rates"][-1]["end"] == expected_valid_to @pytest.mark.asyncio async def test_when_now_is_not_at_30_minute_mark_and_previous_data_is_available_then_previous_data_returned(): @@ -216,10 +216,10 @@ def fire_event(name, metadata): for item in result["consumption"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "interval_start" in item - assert item["interval_start"] == expected_valid_from - assert "interval_end" in item - assert item["interval_end"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to @@ -323,10 +323,10 @@ def fire_event(name, metadata): for item in result["consumption"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "interval_start" in item - assert item["interval_start"] == expected_valid_from - assert "interval_end" in item - assert item["interval_end"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to diff --git a/tests/unit/electricity/test_calculate_electricity_consumption_and_cost.py b/tests/unit/electricity/test_calculate_electricity_consumption_and_cost.py index 3b517edf..2bb87d18 100644 --- a/tests/unit/electricity/test_calculate_electricity_consumption_and_cost.py +++ b/tests/unit/electricity/test_calculate_electricity_consumption_and_cost.py @@ -105,8 +105,8 @@ async def test_when_electricity_consumption_available_then_calculation_returned( consumption_data = create_consumption_data(period_from, period_to) assert consumption_data is not None assert len(consumption_data) == 48 - assert consumption_data[-1]["interval_end"] == period_to - assert consumption_data[0]["interval_start"] == period_from + assert consumption_data[-1]["end"] == period_to + assert consumption_data[0]["start"] == period_from expected_consumption_total = 0 for consumption in consumption_data: @@ -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_evaluated"] == consumption_data[-1]["interval_end"] + assert result["last_evaluated"] == consumption_data[-1]["end"] assert result["total_consumption"] == expected_consumption_total # Make sure our data is returned in 30 minute increments @@ -137,10 +137,10 @@ async def test_when_electricity_consumption_available_then_calculation_returned( for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to @@ -173,8 +173,8 @@ async def test_when_electricity_consumption_starting_at_latest_date_then_calcula consumption_data = create_consumption_data(period_from, period_to, True) assert consumption_data is not None assert len(consumption_data) > 0 - assert consumption_data[0]["interval_end"] == period_to - assert consumption_data[-1]["interval_start"] == period_from + assert consumption_data[0]["end"] == period_to + assert consumption_data[-1]["start"] == period_from expected_consumption_total = 0 for consumption in consumption_data: @@ -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_evaluated"] == consumption_data[0]["interval_end"] + assert result["last_evaluated"] == consumption_data[0]["end"] assert result["total_consumption"] == expected_consumption_total # Make sure our data is returned in 30 minute increments @@ -208,10 +208,10 @@ async def test_when_electricity_consumption_starting_at_latest_date_then_calcula for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to expected_valid_from = expected_valid_to @@ -250,8 +250,8 @@ async def test_when_electricity_consumption_available_and_two_peaks_available_th consumption_data = create_consumption_data(period_from, period_to) assert consumption_data != None assert len(consumption_data) == 12 - assert consumption_data[-1]["interval_end"] == period_to - assert consumption_data[0]["interval_start"] == period_from + assert consumption_data[-1]["end"] == period_to + assert consumption_data[0]["start"] == period_from # Act result = calculate_electricity_consumption_and_cost( diff --git a/tests/unit/gas/test_calculate_gas_consumption_and_cost.py b/tests/unit/gas/test_calculate_gas_consumption_and_cost.py index 01aaaf0a..d4d2279d 100644 --- a/tests/unit/gas/test_calculate_gas_consumption_and_cost.py +++ b/tests/unit/gas/test_calculate_gas_consumption_and_cost.py @@ -117,8 +117,8 @@ async def test_when_gas_consumption_available_then_calculation_returned(latest_d consumption_data = create_consumption_data(period_from, period_to) assert consumption_data is not None assert len(consumption_data) > 0 - assert consumption_data[-1]["interval_end"] == period_to - assert consumption_data[0]["interval_start"] == period_from + assert consumption_data[-1]["end"] == period_to + assert consumption_data[0]["start"] == period_from # Act result = calculate_gas_consumption_and_cost( @@ -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_evaluated"] == consumption_data[-1]["interval_end"] + assert result["last_evaluated"] == consumption_data[-1]["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³": @@ -157,10 +157,10 @@ async def test_when_gas_consumption_available_then_calculation_returned(latest_d for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to assert "rate" in item assert item["rate"] == round(expected_rate_price / 100, 6) @@ -202,8 +202,8 @@ async def test_when_gas_consumption_starting_at_latest_date_then_calculation_ret consumption_data = create_consumption_data(period_from, period_to, True) assert consumption_data is not None assert len(consumption_data) > 0 - assert consumption_data[0]["interval_end"] == period_to - assert consumption_data[-1]["interval_start"] == period_from + assert consumption_data[0]["end"] == period_to + assert consumption_data[-1]["start"] == period_from # Act result = calculate_gas_consumption_and_cost( @@ -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_evaluated"] == consumption_data[0]["interval_end"] + assert result["last_evaluated"] == consumption_data[0]["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 @@ -241,10 +241,10 @@ async def test_when_gas_consumption_starting_at_latest_date_then_calculation_ret for item in result["charges"]: expected_valid_to = expected_valid_from + timedelta(minutes=30) - assert "from" in item - assert item["from"] == expected_valid_from - assert "to" in item - assert item["to"] == expected_valid_to + assert "start" in item + assert item["start"] == expected_valid_from + assert "end" in item + assert item["end"] == expected_valid_to assert "rate" in item assert item["rate"] == round(expected_rate_price / 100, 6) diff --git a/tests/unit/intelligent/test_adjust_intelligent_rates.py b/tests/unit/intelligent/test_adjust_intelligent_rates.py index 888a630a..b231537e 100644 --- a/tests/unit/intelligent/test_adjust_intelligent_rates.py +++ b/tests/unit/intelligent/test_adjust_intelligent_rates.py @@ -9,26 +9,26 @@ def create_rates(): { "value_exc_vat": 9.111, "value_inc_vat": 9.11, - "valid_from": as_utc(parse_datetime("2022-10-10T03:30:00Z")), - "valid_to": as_utc(parse_datetime("2022-10-10T04:00:00Z")) + "start": as_utc(parse_datetime("2022-10-10T03:30:00Z")), + "end": as_utc(parse_datetime("2022-10-10T04:00:00Z")) }, { "value_exc_vat": 30.1, "value_inc_vat": 30.1, - "valid_from": as_utc(parse_datetime("2022-10-10T04:00:00Z")), - "valid_to": as_utc(parse_datetime("2022-10-10T04:30:00Z")) + "start": as_utc(parse_datetime("2022-10-10T04:00:00Z")), + "end": as_utc(parse_datetime("2022-10-10T04:30:00Z")) }, { "value_exc_vat": 30.1, "value_inc_vat": 30.1, - "valid_from": as_utc(parse_datetime("2022-10-10T04:30:00Z")), - "valid_to": as_utc(parse_datetime("2022-10-10T05:00:00Z")) + "start": as_utc(parse_datetime("2022-10-10T04:30:00Z")), + "end": as_utc(parse_datetime("2022-10-10T05:00:00Z")) }, { "value_exc_vat": 30.1, "value_inc_vat": 30.1, - "valid_from": as_utc(parse_datetime("2022-10-10T05:00:00Z")), - "valid_to": as_utc(parse_datetime("2022-10-10T05:30:00Z")) + "start": as_utc(parse_datetime("2022-10-10T05:00:00Z")), + "end": as_utc(parse_datetime("2022-10-10T05:30:00Z")) }, ] @@ -67,8 +67,8 @@ async def test_when_planned_smart_charge_dispatch_present_in_rate_then_rates_adj assert len(rates) == len(adjusted_rates) for index, rate in enumerate(rates): if index == 3: - assert rate["valid_from"] == adjusted_rates[index]["valid_from"] - assert rate["valid_to"] == adjusted_rates[index]["valid_to"] + assert rate["start"] == adjusted_rates[index]["start"] + assert rate["end"] == adjusted_rates[index]["end"] assert off_peak == adjusted_rates[index]["value_inc_vat"] assert True == adjusted_rates[index]["is_intelligent_adjusted"] @@ -117,8 +117,8 @@ async def test_when_complete_smart_charge_dispatch_present_in_rate_then_rates_ad assert len(rates) == len(adjusted_rates) for index, rate in enumerate(rates): if index == 3: - assert rate["valid_from"] == adjusted_rates[index]["valid_from"] - assert rate["valid_to"] == adjusted_rates[index]["valid_to"] + assert rate["start"] == adjusted_rates[index]["start"] + assert rate["end"] == adjusted_rates[index]["end"] assert off_peak == adjusted_rates[index]["value_inc_vat"] assert True == adjusted_rates[index]["is_intelligent_adjusted"] @@ -147,8 +147,8 @@ async def test_when_complete_non_smart_charge_dispatch_present_in_rate_then_rate assert len(rates) == len(adjusted_rates) for index, rate in enumerate(rates): if index == 3: - assert rate["valid_from"] == adjusted_rates[index]["valid_from"] - assert rate["valid_to"] == adjusted_rates[index]["valid_to"] + assert rate["start"] == adjusted_rates[index]["start"] + assert rate["end"] == adjusted_rates[index]["end"] assert off_peak == adjusted_rates[index]["value_inc_vat"] assert True == adjusted_rates[index]["is_intelligent_adjusted"] diff --git a/tests/unit/intelligent/test_has_intelligent_tariff.py b/tests/unit/intelligent/test_has_intelligent_tariff.py index 15e7bbc6..a69571f3 100644 --- a/tests/unit/intelligent/test_has_intelligent_tariff.py +++ b/tests/unit/intelligent/test_has_intelligent_tariff.py @@ -23,8 +23,8 @@ def get_account_info(tariff_code: str, is_active_agreement = True): ], "agreements": [ { - "valid_from": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", + "start": "2023-07-01T00:00:00+01:00" if is_active_agreement else "2023-08-01T00:00:00+01:00", + "end": "2023-08-01T00:00:00+01:00" if is_active_agreement else "2023-09-01T00:00:00+01:00", "tariff_code": tariff_code, "product": "SUPER-GREEN-24M-21-07-30" } diff --git a/tests/unit/statistics/test_consumption_build_consumption_statistics.py b/tests/unit/statistics/test_consumption_build_consumption_statistics.py index 30060424..3b3854d3 100644 --- a/tests/unit/statistics/test_consumption_build_consumption_statistics.py +++ b/tests/unit/statistics/test_consumption_build_consumption_statistics.py @@ -11,7 +11,7 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() period_from = datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") period_to = datetime.strptime("2022-03-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") current = datetime.strptime("2022-02-28T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z") - consumptions = create_consumption_data(period_from, period_to, False, "from", "to") + consumptions = create_consumption_data(period_from, period_to, False, "start", "end") rates = create_rate_data(period_from, period_to, [2, 4]) consumption_key = 'consumption' latest_total_sum = 3 @@ -40,14 +40,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() item = result["total"][int(index / 2)] expected_sum += consumptions[index]["consumption"] expected_state += consumptions[index]["consumption"] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -66,14 +66,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() expected_sum += consumptions[index]["consumption"] expected_state += consumptions[index]["consumption"] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -92,14 +92,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() expected_sum += consumptions[index]["consumption"] expected_state += consumptions[index]["consumption"] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -117,7 +117,7 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av period_from = datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") period_to = datetime.strptime("2022-03-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") current = datetime.strptime("2022-02-28T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z") - consumptions = create_consumption_data(period_from, period_to, False, "from", "to") + consumptions = create_consumption_data(period_from, period_to, False, "start", "end") rates = create_rate_data(period_from, period_to, expected_rates) consumption_key = 'consumption' latest_total_sum = 3 @@ -146,14 +146,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av item = result["total"][int(index / 2)] expected_sum += consumptions[index]["consumption"] expected_state += consumptions[index]["consumption"] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -164,14 +164,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av assert "off_peak" in result for index in range(len(consumptions)): item = result["off_peak"][int(index / 2)] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == 0 @@ -189,14 +189,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av expected_sum += consumptions[index]["consumption"] expected_state += consumptions[index]["consumption"] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum diff --git a/tests/unit/statistics/test_consumption_build_cost_statistics.py b/tests/unit/statistics/test_consumption_build_cost_statistics.py index cfc6a165..996cf1d2 100644 --- a/tests/unit/statistics/test_consumption_build_cost_statistics.py +++ b/tests/unit/statistics/test_consumption_build_cost_statistics.py @@ -11,7 +11,7 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() period_from = datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") period_to = datetime.strptime("2022-03-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") current = datetime.strptime("2022-02-28T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z") - consumptions = create_consumption_data(period_from, period_to, False, "from", "to") + consumptions = create_consumption_data(period_from, period_to, False, "start", "end") rates = create_rate_data(period_from, period_to, [2, 4]) consumption_key = 'consumption' latest_total_sum = 3 @@ -40,14 +40,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() item = result["total"][int(index / 2)] expected_sum += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -66,14 +66,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() if index % 2 == 1: - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) item = result["off_peak"][int(index / 2)] assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -91,14 +91,14 @@ async def test_when_two_rates_available_then_total_peak_and_off_peak_available() expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) if index % 2 == 1: - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) item = result["peak"][int(index / 2)] assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -112,7 +112,7 @@ async def test_when_three_rates_available_then_total_peak_and_off_peak_available period_from = datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") period_to = datetime.strptime("2022-03-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") current = datetime.strptime("2022-02-28T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z") - consumptions = create_consumption_data(period_from, period_to, False, "from", "to") + consumptions = create_consumption_data(period_from, period_to, False, "start", "end") rates = create_rate_data(period_from, period_to, [2, 4, 6]) consumption_key = 'consumption' latest_total_sum = 3 @@ -141,14 +141,14 @@ async def test_when_three_rates_available_then_total_peak_and_off_peak_available item = result["total"][int(index / 2)] expected_sum += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -166,14 +166,14 @@ async def test_when_three_rates_available_then_total_peak_and_off_peak_available expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) if (index % 2 == 1): - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) item = result["off_peak"][int(index / 2)] assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -191,14 +191,14 @@ async def test_when_three_rates_available_then_total_peak_and_off_peak_available expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) if index % 2 == 1: - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) item = result["peak"][int(index / 2)] assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -216,7 +216,7 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av period_from = datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") period_to = datetime.strptime("2022-03-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") current = datetime.strptime("2022-02-28T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z") - consumptions = create_consumption_data(period_from, period_to, False, "from", "to") + consumptions = create_consumption_data(period_from, period_to, False, "start", "end") rates = create_rate_data(period_from, period_to, expected_rates) consumption_key = 'consumption' latest_total_sum = 3 @@ -245,14 +245,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av item = result["total"][int(index / 2)] expected_sum += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum @@ -263,14 +263,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av assert "off_peak" in result for index in range(len(consumptions)): item = result["off_peak"][int(index / 2)] - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == 0 @@ -288,14 +288,14 @@ async def test_when_more_or_less_than_three_rates_available_then_off_peak_not_av expected_sum += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) expected_state += round((consumptions[index]["consumption"] * rates[index]["value_inc_vat"]) / 100, 2) - expected_start = consumptions[index]["from"].replace(minute=0, second=0, microsecond=0) + expected_start = consumptions[index]["start"].replace(minute=0, second=0, microsecond=0) if index % 2 == 1: assert "start" in item assert item["start"] == expected_start assert "last_reset" in item - assert item["last_reset"] == consumptions[0]["from"] + assert item["last_reset"] == consumptions[0]["start"] assert "sum" in item assert item["sum"] == expected_sum diff --git a/tests/unit/statistics/test_get_statistic_ids_to_remove.py b/tests/unit/statistics/test_get_statistic_ids_to_remove.py index 5da0097b..b6e021eb 100644 --- a/tests/unit/statistics/test_get_statistic_ids_to_remove.py +++ b/tests/unit/statistics/test_get_statistic_ids_to_remove.py @@ -10,8 +10,8 @@ def get_account_info(): "mpan": 'elec-mpan', "agreements": [ { - "valid_from": "2023-08-01T00:00:00+01:00", - "valid_to": "2023-08-14T00:00:00+01:00", + "start": "2023-08-01T00:00:00+01:00", + "end": "2023-08-14T00:00:00+01:00", "tariff_code": "E-1R-SUPER-GREEN-24M-21-07-30-C", "product": "SUPER-GREEN-24M-21-07-30" } @@ -29,8 +29,8 @@ def get_account_info(): "mprn": 'gas-mprn', "agreements": [ { - "valid_from": "2023-08-13T00:00:00+01:00", - "valid_to": "2023-09-01T00:00:00+01:00", + "start": "2023-08-13T00:00:00+01:00", + "end": "2023-09-01T00:00:00+01:00", "tariff_code": "G-1R-SUPER-GREEN-24M-21-07-30-C", "product": "SUPER-GREEN-24M-21-07-30" } diff --git a/tests/unit/target_rates/test_calculate_continuous_times.py b/tests/unit/target_rates/test_calculate_continuous_times.py index 7c9f93a1..7256bca0 100644 --- a/tests/unit/target_rates/test_calculate_continuous_times.py +++ b/tests/unit/target_rates/test_calculate_continuous_times.py @@ -85,12 +85,12 @@ async def test_when_continuous_times_present_then_next_continuous_times_returned # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.001 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(hours=1) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(hours=1) assert result[1]["value_inc_vat"] == 0.001 @pytest.mark.asyncio @@ -173,12 +173,12 @@ async def test_when_continuous_times_present_and_highest_price_required_then_nex # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.002 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(hours=1) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(hours=1) assert result[1]["value_inc_vat"] == 0.003 @pytest.mark.asyncio @@ -298,10 +298,10 @@ async def test_readme_examples(current_date, target_start_time, target_end_time, assert len(result) == 0 else: assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(minutes=60) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(minutes=60) @pytest.mark.asyncio async def test_when_current_time_has_not_enough_time_left_then_no_continuous_times_returned(): @@ -442,8 +442,8 @@ async def test_when_go_rates_supplied_once_a_day_set_and_cheapest_period_past_th start_time = datetime.strptime("2022-10-09T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") for index in range(8): end_time = start_time + timedelta(minutes=30) - assert result[index]["valid_from"] == start_time - assert result[index]["valid_to"] == end_time + assert result[index]["start"] == start_time + assert result[index]["end"] == end_time assert result[index]["value_inc_vat"] == round(rates[1]["value_inc_vat"] / 100, 6) assert result[index]["tariff_code"] == tariff_code @@ -477,8 +477,8 @@ async def test_when_last_rate_is_currently_active_and_target_is_rolling_then_rat # Assert assert result is not None assert len(result) == 1 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.18081 @pytest.mark.asyncio @@ -506,12 +506,12 @@ async def test_when_start_time_is_after_end_time_then_rates_are_overnight(): # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.14123 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(minutes=60) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(minutes=60) assert result[1]["value_inc_vat"] == 0.14123 @pytest.mark.asyncio @@ -539,12 +539,12 @@ async def test_when_start_time_and_end_time_is_same_then_rates_are_shifted(): # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.14123 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(minutes=60) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(minutes=60) assert result[1]["value_inc_vat"] == 0.14123 @@ -602,12 +602,12 @@ async def test_when_start_time_is_after_end_time_and_rolling_target_then_rates_a # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.161 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(minutes=60) + assert result[1]["start"] == expected_first_valid_from + timedelta(minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(minutes=60) assert result[1]["value_inc_vat"] == 0.161 @pytest.mark.asyncio @@ -670,8 +670,8 @@ async def test_when_start_time_and_end_time_is_same_and_rolling_target_then_rate # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.151 @pytest.mark.asyncio diff --git a/tests/unit/target_rates/test_calculate_intermittent_times.py b/tests/unit/target_rates/test_calculate_intermittent_times.py index 5e2b2f3b..f72dc4ac 100644 --- a/tests/unit/target_rates/test_calculate_intermittent_times.py +++ b/tests/unit/target_rates/test_calculate_intermittent_times.py @@ -86,12 +86,12 @@ async def test_when_intermittent_times_present_then_next_intermittent_times_retu # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.001 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(hours=1, minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(hours=2) + assert result[1]["start"] == expected_first_valid_from + timedelta(hours=1, minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(hours=2) assert result[1]["value_inc_vat"] == 0.001 @pytest.mark.asyncio @@ -174,12 +174,12 @@ async def test_when_intermittent_times_present_and_highest_prices_are_true_then_ # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == expected_first_valid_from - assert result[0]["valid_to"] == expected_first_valid_from + timedelta(minutes=30) + assert result[0]["start"] == expected_first_valid_from + assert result[0]["end"] == expected_first_valid_from + timedelta(minutes=30) assert result[0]["value_inc_vat"] == 0.003 - assert result[1]["valid_from"] == expected_first_valid_from + timedelta(hours=1, minutes=30) - assert result[1]["valid_to"] == expected_first_valid_from + timedelta(hours=2) + assert result[1]["start"] == expected_first_valid_from + timedelta(hours=1, minutes=30) + assert result[1]["end"] == expected_first_valid_from + timedelta(hours=2) assert result[1]["value_inc_vat"] == 0.003 @pytest.mark.asyncio @@ -272,12 +272,12 @@ async def test_when_start_time_is_after_end_time_then_rates_are_overnight(): # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == datetime.strptime("2022-10-21T20:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[0]["valid_to"] == datetime.strptime("2022-10-21T20:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["start"] == datetime.strptime("2022-10-21T20:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["end"] == datetime.strptime("2022-10-21T20:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[0]["value_inc_vat"] == 0.151 - assert result[1]["valid_from"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[1]["valid_to"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["start"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["end"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[1]["value_inc_vat"] == 0.141 @pytest.mark.asyncio @@ -350,12 +350,12 @@ async def test_when_start_time_and_end_time_is_same_then_rates_are_shifted(): # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == datetime.strptime("2022-10-21T22:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[0]["valid_to"] == datetime.strptime("2022-10-21T22:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["start"] == datetime.strptime("2022-10-21T22:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["end"] == datetime.strptime("2022-10-21T22:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[0]["value_inc_vat"] == 0.141 - assert result[1]["valid_from"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[1]["valid_to"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["start"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["end"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[1]["value_inc_vat"] == 0.141 @pytest.mark.asyncio @@ -422,12 +422,12 @@ async def test_when_start_time_is_after_end_time_and_rolling_target_then_rates_a # Assert assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == datetime.strptime("2022-10-21T21:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[0]["valid_to"] == datetime.strptime("2022-10-21T22:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["start"] == datetime.strptime("2022-10-21T21:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["end"] == datetime.strptime("2022-10-21T22:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[0]["value_inc_vat"] == 0.151 - assert result[1]["valid_from"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[1]["valid_to"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["start"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["end"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[1]["value_inc_vat"] == 0.141 @pytest.mark.asyncio @@ -501,12 +501,12 @@ async def test_when_start_time_and_end_time_is_same_and_rolling_target_then_rate assert result is not None assert len(result) == 2 - assert result[0]["valid_from"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[0]["valid_to"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["start"] == datetime.strptime("2022-10-22T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["end"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[0]["value_inc_vat"] == 0.141 - assert result[1]["valid_from"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[1]["valid_to"] == datetime.strptime("2022-10-22T03:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["start"] == datetime.strptime("2022-10-22T02:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["end"] == datetime.strptime("2022-10-22T03:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[1]["value_inc_vat"] == 0.151 @pytest.mark.asyncio @@ -533,28 +533,28 @@ async def test_when_using_agile_times_then_lowest_rates_are_picked(): assert result is not None assert len(result) == 6 - assert result[0]["valid_from"] == datetime.strptime("2022-10-21T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[0]["valid_to"] == datetime.strptime("2022-10-22T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["start"] == datetime.strptime("2022-10-21T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[0]["end"] == datetime.strptime("2022-10-22T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[0]["value_inc_vat"] == 0.14123 - assert result[1]["valid_from"] == datetime.strptime("2022-10-22T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[1]["valid_to"] == datetime.strptime("2022-10-22T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["start"] == datetime.strptime("2022-10-22T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[1]["end"] == datetime.strptime("2022-10-22T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[1]["value_inc_vat"] == 0.14123 - assert result[2]["valid_from"] == datetime.strptime("2022-10-22T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[2]["valid_to"] == datetime.strptime("2022-10-22T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[2]["start"] == datetime.strptime("2022-10-22T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[2]["end"] == datetime.strptime("2022-10-22T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[2]["value_inc_vat"] == 0.179025 - assert result[3]["valid_from"] == datetime.strptime("2022-10-22T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[3]["valid_to"] == datetime.strptime("2022-10-22T06:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[3]["start"] == datetime.strptime("2022-10-22T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[3]["end"] == datetime.strptime("2022-10-22T06:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[3]["value_inc_vat"] == 0.17136 - assert result[4]["valid_from"] == datetime.strptime("2022-10-22T06:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[4]["valid_to"] == datetime.strptime("2022-10-22T06:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[4]["start"] == datetime.strptime("2022-10-22T06:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[4]["end"] == datetime.strptime("2022-10-22T06:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[4]["value_inc_vat"] == 0.17136 - assert result[5]["valid_from"] == datetime.strptime("2022-10-22T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert result[5]["valid_to"] == datetime.strptime("2022-10-22T13:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[5]["start"] == datetime.strptime("2022-10-22T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert result[5]["end"] == datetime.strptime("2022-10-22T13:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert result[5]["value_inc_vat"] == 0.18081 @pytest.mark.asyncio diff --git a/tests/unit/target_rates/test_get_target_rate_info.py b/tests/unit/target_rates/test_get_target_rate_info.py index 5e49b883..409a99d9 100644 --- a/tests/unit/target_rates/test_get_target_rate_info.py +++ b/tests/unit/target_rates/test_get_target_rate_info.py @@ -9,18 +9,18 @@ async def test_when_called_before_rates_then_not_active_returned(): # Arrange rates = [ { - "valid_from": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 10 }, { - "valid_from": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 5 }, { - "valid_from": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 15 } ] @@ -46,7 +46,7 @@ async def test_when_called_before_rates_then_not_active_returned(): assert result["current_min_cost"] == None assert result["current_max_cost"] == None - assert result["next_time"] == rates[0]["valid_from"] + assert result["next_time"] == rates[0]["start"] assert result["next_duration_in_hours"] == 1 assert result["next_average_cost"] == 7.5 assert result["next_min_cost"] == 5 @@ -95,33 +95,33 @@ async def test_when_called_during_rates_then_active_returned(test): # Arrange rates = [ { - "valid_from": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 10, }, { - "valid_from": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 15, }, { - "valid_from": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T11:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T11:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 15, }, { - "valid_from": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 5, }, { - "valid_from": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T13:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T13:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 20, }, { - "valid_from": datetime.strptime("2022-02-09T14:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T14:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T14:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T14:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 10, } ] @@ -195,24 +195,24 @@ async def test_when_offset_set_then_active_at_correct_current_time(): rates = [ { - "valid_from": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 10, }, { - "valid_from": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T11:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 15, }, { - "valid_from": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), - "valid_to": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "start": datetime.strptime("2022-02-09T12:00:00Z", "%Y-%m-%dT%H:%M:%S%z"), + "end": datetime.strptime("2022-02-09T12:30:00Z", "%Y-%m-%dT%H:%M:%S%z"), "value_inc_vat": 5, } ] # Check where we're before the offset - current_date = rates[0]["valid_from"] - timedelta(hours=1, minutes=1) + current_date = rates[0]["start"] - timedelta(hours=1, minutes=1) result = get_target_rate_info( current_date, @@ -238,7 +238,7 @@ async def test_when_offset_set_then_active_at_correct_current_time(): # Check where's within our rates and our offset for minutes_to_add in range(60): - current_date = rates[0]["valid_from"] - timedelta(hours=1) + timedelta(minutes=minutes_to_add) + current_date = rates[0]["start"] - timedelta(hours=1) + timedelta(minutes=minutes_to_add) result = get_target_rate_info( current_date, @@ -263,7 +263,7 @@ async def test_when_offset_set_then_active_at_correct_current_time(): assert result["next_max_cost"] == 5 # Check when within rate but after offset - current_date = rates[0]["valid_from"] - timedelta(hours=1) + timedelta(minutes=61) + current_date = rates[0]["start"] - timedelta(hours=1) + timedelta(minutes=61) result = get_target_rate_info( current_date, diff --git a/tests/unit/utils/test_get_active_tariff_code.py b/tests/unit/utils/test_get_active_tariff_code.py index 867444ea..0f4bbd90 100644 --- a/tests/unit/utils/test_get_active_tariff_code.py +++ b/tests/unit/utils/test_get_active_tariff_code.py @@ -11,28 +11,28 @@ async def test_when_active_tariff_available_then_get_active_tariff_code_returns_ agreements = [ { 'tariff_code': 'G-1R-FIX-12M-18-02-14-G', - 'valid_from': '2018-04-02T00:00:00+01:00', - 'valid_to': '2019-04-02T00:00:00+01:00' + 'start': '2018-04-02T00:00:00+01:00', + 'end': '2019-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-18-12-21-G', - 'valid_from': '2019-04-02T00:00:00+01:00', - 'valid_to': '2020-04-02T00:00:00+01:00' + 'start': '2019-04-02T00:00:00+01:00', + 'end': '2020-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-SUPER-GREEN-12M-20-02-12-G', - 'valid_from': '2020-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2020-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-VAR-20-10-01-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-21-02-16-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2022-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2022-04-02T00:00:00+01:00' } ] @@ -51,28 +51,28 @@ async def test_when_agreements_ended_then_get_active_tariff_code_returns_none(): agreements = [ { 'tariff_code': 'G-1R-FIX-12M-18-02-14-G', - 'valid_from': '2018-04-02T00:00:00+01:00', - 'valid_to': '2019-04-02T00:00:00+01:00' + 'start': '2018-04-02T00:00:00+01:00', + 'end': '2019-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-18-12-21-G', - 'valid_from': '2019-04-02T00:00:00+01:00', - 'valid_to': '2020-04-02T00:00:00+01:00' + 'start': '2019-04-02T00:00:00+01:00', + 'end': '2020-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-SUPER-GREEN-12M-20-02-12-G', - 'valid_from': '2020-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2020-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-VAR-20-10-01-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-21-02-16-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2022-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2022-04-02T00:00:00+01:00' } ] @@ -90,28 +90,28 @@ async def test_when_agreements_not_started_then_get_active_tariff_code_returns_n agreements = [ { 'tariff_code': 'G-1R-FIX-12M-18-02-14-G', - 'valid_from': '2018-04-02T00:00:00+01:00', - 'valid_to': '2019-04-02T00:00:00+01:00' + 'start': '2018-04-02T00:00:00+01:00', + 'end': '2019-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-18-12-21-G', - 'valid_from': '2019-04-02T00:00:00+01:00', - 'valid_to': '2020-04-02T00:00:00+01:00' + 'start': '2019-04-02T00:00:00+01:00', + 'end': '2020-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-SUPER-GREEN-12M-20-02-12-G', - 'valid_from': '2020-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2020-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-VAR-20-10-01-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-21-02-16-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2022-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2022-04-02T00:00:00+01:00' } ] @@ -129,27 +129,27 @@ async def test_when_agreement_has_no_end_date_then_get_active_tariff_code_return agreements = [ { 'tariff_code': 'G-1R-FIX-12M-18-02-14-G', - 'valid_from': '2018-04-02T00:00:00+01:00', - 'valid_to': '2019-04-02T00:00:00+01:00' + 'start': '2018-04-02T00:00:00+01:00', + 'end': '2019-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-18-12-21-G', - 'valid_from': '2019-04-02T00:00:00+01:00', - 'valid_to': '2020-04-02T00:00:00+01:00' + 'start': '2019-04-02T00:00:00+01:00', + 'end': '2020-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-SUPER-GREEN-12M-20-02-12-G', - 'valid_from': '2020-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2020-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-VAR-20-10-01-G', - 'valid_from': '2021-04-02T00:00:00+01:00', - 'valid_to': '2021-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00', + 'end': '2021-04-02T00:00:00+01:00' }, { 'tariff_code': 'G-1R-FIX-12M-21-02-16-G', - 'valid_from': '2021-04-02T00:00:00+01:00' + 'start': '2021-04-02T00:00:00+01:00' } ] diff --git a/tests/unit/utils/test_get_current_rate_information.py b/tests/unit/utils/test_get_current_rate_information.py index b1029aef..6e592070 100644 --- a/tests/unit/utils/test_get_current_rate_information.py +++ b/tests/unit/utils/test_get_current_rate_information.py @@ -65,19 +65,19 @@ async def test_when_target_has_rates_and_gmt_then_rate_information_is_returned() max_target = min_target + timedelta(days=1) for index in range(len(rate_data)): - assert rate_information["all_rates"][index]["valid_from"] == expected_period_from - assert rate_information["all_rates"][index]["valid_to"] == expected_period_from + timedelta(minutes=30) + assert rate_information["all_rates"][index]["start"] == expected_period_from + assert rate_information["all_rates"][index]["end"] == expected_period_from + timedelta(minutes=30) assert rate_information["all_rates"][index]["value_inc_vat"] == round((expected_min_price if index % 4 == 0 else expected_max_price if index % 4 == 3 else expected_rate) / 100, 6) assert rate_information["all_rates"][index]["is_capped"] == False expected_period_from = expected_period_from + timedelta(minutes=30) - if rate_data[index]["valid_from"] >= min_target and rate_data[index]["valid_to"] <= max_target: + if rate_data[index]["start"] >= min_target and rate_data[index]["end"] <= max_target: total_rate_value = total_rate_value + rate_data[index]["value_inc_vat"] assert "current_rate" in rate_information - assert rate_information["current_rate"]["valid_from"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["current_rate"]["valid_to"] == rate_information["current_rate"]["valid_from"] + timedelta(minutes=60) + assert rate_information["current_rate"]["start"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["current_rate"]["end"] == rate_information["current_rate"]["start"] + timedelta(minutes=60) assert rate_information["current_rate"]["value_inc_vat"] == round(expected_rate / 100, 6) @@ -116,19 +116,19 @@ async def test_when_target_has_rates_and_bst_then_rate_information_is_returned() max_target = min_target + timedelta(days=1) for index in range(len(rate_data)): - assert rate_information["all_rates"][index]["valid_from"] == expected_period_from - assert rate_information["all_rates"][index]["valid_to"] == expected_period_from + timedelta(minutes=30) + assert rate_information["all_rates"][index]["start"] == expected_period_from + assert rate_information["all_rates"][index]["end"] == expected_period_from + timedelta(minutes=30) assert rate_information["all_rates"][index]["value_inc_vat"] == round((expected_min_price if index % 4 == 0 else expected_max_price if index % 4 == 3 else expected_rate) / 100, 6) assert rate_information["all_rates"][index]["is_capped"] == False expected_period_from = expected_period_from + timedelta(minutes=30) - if rate_information["all_rates"][index]["valid_from"] >= min_target and rate_information["all_rates"][index]["valid_to"] <= max_target: + if rate_information["all_rates"][index]["start"] >= min_target and rate_information["all_rates"][index]["end"] <= max_target: total_rate_value = total_rate_value + rate_data[index]["value_inc_vat"] assert "current_rate" in rate_information - assert rate_information["current_rate"]["valid_from"] == datetime.strptime("2022-02-28T00:30:00+01:00", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["current_rate"]["valid_to"] == rate_information["current_rate"]["valid_from"] + timedelta(minutes=60) + assert rate_information["current_rate"]["start"] == datetime.strptime("2022-02-28T00:30:00+01:00", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["current_rate"]["end"] == rate_information["current_rate"]["start"] + timedelta(minutes=60) assert rate_information["current_rate"]["value_inc_vat"] == round(expected_rate / 100, 6) @@ -165,19 +165,19 @@ async def test_when_all_rates_identical_costs_then_rate_information_is_returned( max_target = min_target + timedelta(days=1) for index in range(len(rate_data)): - assert rate_information["all_rates"][index]["valid_from"] == expected_period_from - assert rate_information["all_rates"][index]["valid_to"] == expected_period_from + timedelta(minutes=30) + assert rate_information["all_rates"][index]["start"] == expected_period_from + assert rate_information["all_rates"][index]["end"] == expected_period_from + timedelta(minutes=30) assert rate_information["all_rates"][index]["value_inc_vat"] == round(expected_rate / 100, 6) assert rate_information["all_rates"][index]["is_capped"] == False expected_period_from = expected_period_from + timedelta(minutes=30) - if rate_information["all_rates"][index]["valid_from"] >= min_target and rate_information["all_rates"][index]["valid_to"] <= max_target: + if rate_information["all_rates"][index]["start"] >= min_target and rate_information["all_rates"][index]["end"] <= max_target: total_rate_value = total_rate_value + rate_data[index]["value_inc_vat"] assert "current_rate" in rate_information - assert rate_information["current_rate"]["valid_from"] == period_from - assert rate_information["current_rate"]["valid_to"] == period_to + assert rate_information["current_rate"]["start"] == period_from + assert rate_information["current_rate"]["end"] == period_to assert rate_information["current_rate"]["value_inc_vat"] == round(expected_rate / 100, 6) @@ -252,12 +252,12 @@ async def test_when_agile_rates_then_rate_information_is_returned(now: datetime) assert "current_rate" in rate_information assert rate_information["current_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["current_rate"]["valid_from"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["current_rate"]["valid_to"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["current_rate"]["start"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["current_rate"]["end"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 1 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") diff --git a/tests/unit/utils/test_get_next_rate_information.py b/tests/unit/utils/test_get_next_rate_information.py index ea56365e..90e5b8ed 100644 --- a/tests/unit/utils/test_get_next_rate_information.py +++ b/tests/unit/utils/test_get_next_rate_information.py @@ -76,19 +76,19 @@ async def test_when_target_has_rates_and_gmt_then_rate_information_is_returned() assert "next_rate" in rate_information assert rate_information["next_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["next_rate"]["valid_from"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["next_rate"]["valid_to"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["start"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["end"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 2 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert rate_information["applicable_rates"][1]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][1]["valid_from"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][1]["valid_to"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["start"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["end"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") @pytest.mark.asyncio async def test_when_target_has_rates_and_bst_then_rate_information_is_returned(): @@ -106,19 +106,19 @@ async def test_when_target_has_rates_and_bst_then_rate_information_is_returned() assert "next_rate" in rate_information assert rate_information["next_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["next_rate"]["valid_from"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["next_rate"]["valid_to"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["start"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["end"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 2 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-10-21T03:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert rate_information["applicable_rates"][1]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][1]["valid_from"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][1]["valid_to"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["start"] == datetime.strptime("2022-10-21T04:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["end"] == datetime.strptime("2022-10-21T04:30:00Z", "%Y-%m-%dT%H:%M:%S%z") @pytest.mark.asyncio async def test_when_all_rates_different_then_rate_information_is_returned(): @@ -136,15 +136,15 @@ async def test_when_all_rates_different_then_rate_information_is_returned(): assert "next_rate" in rate_information assert rate_information["next_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["next_rate"]["valid_from"] == datetime.strptime("2022-10-21T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["next_rate"]["valid_to"] == datetime.strptime("2022-10-21T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["start"] == datetime.strptime("2022-10-21T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["end"] == datetime.strptime("2022-10-21T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 1 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-10-21T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-10-21T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-10-21T05:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-10-21T05:30:00Z", "%Y-%m-%dT%H:%M:%S%z") # Covering https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/441 @pytest.mark.asyncio @@ -208,12 +208,12 @@ async def test_when_agile_rates_then_rate_information_is_returned(now: datetime) assert "next_rate" in rate_information assert rate_information["next_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["next_rate"]["valid_from"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["next_rate"]["valid_to"] == datetime.strptime("2023-10-06T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["start"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["next_rate"]["end"] == datetime.strptime("2023-10-06T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 1 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2023-10-06T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2023-10-06T10:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2023-10-06T10:30:00Z", "%Y-%m-%dT%H:%M:%S%z") diff --git a/tests/unit/utils/test_get_off_peak_cost.py b/tests/unit/utils/test_get_off_peak_cost.py index 3eb61874..a831394a 100644 --- a/tests/unit/utils/test_get_off_peak_cost.py +++ b/tests/unit/utils/test_get_off_peak_cost.py @@ -45,44 +45,44 @@ async def test_bob(): { "value_exc_vat": 28.8068, "value_inc_vat": 30.24714, - "valid_from": "2023-11-06T04:30:00Z", - "valid_to": "2023-11-07T00:30:00Z" + "start": "2023-11-06T04:30:00Z", + "end": "2023-11-07T00:30:00Z" }, { "value_exc_vat": 8.5714, "value_inc_vat": 8.99997, - "valid_from": "2023-11-06T00:30:00Z", - "valid_to": "2023-11-06T04:30:00Z" + "start": "2023-11-06T00:30:00Z", + "end": "2023-11-06T04:30:00Z" }, { "value_exc_vat": 28.8068, "value_inc_vat": 30.24714, - "valid_from": "2023-11-05T04:30:00Z", - "valid_to": "2023-11-06T00:30:00Z" + "start": "2023-11-05T04:30:00Z", + "end": "2023-11-06T00:30:00Z" }, { "value_exc_vat": 8.5714, "value_inc_vat": 8.99997, - "valid_from": "2023-11-05T00:30:00Z", - "valid_to": "2023-11-05T04:30:00Z" + "start": "2023-11-05T00:30:00Z", + "end": "2023-11-05T04:30:00Z" }, { "value_exc_vat": 28.8068, "value_inc_vat": 30.24714, - "valid_from": "2023-11-04T04:30:00Z", - "valid_to": "2023-11-05T00:30:00Z" + "start": "2023-11-04T04:30:00Z", + "end": "2023-11-05T00:30:00Z" }, { "value_exc_vat": 8.5714, "value_inc_vat": 8.99997, - "valid_from": "2023-11-04T00:30:00Z", - "valid_to": "2023-11-04T04:30:00Z" + "start": "2023-11-04T00:30:00Z", + "end": "2023-11-04T04:30:00Z" }, { "value_exc_vat": 28.8068, "value_inc_vat": 30.24714, - "valid_from": "2023-11-03T04:30:00Z", - "valid_to": "2023-11-04T00:30:00Z" + "start": "2023-11-03T04:30:00Z", + "end": "2023-11-04T00:30:00Z" } ] rate_data = rates_to_thirty_minute_increments(data, period_from, period_to, 'tariff') diff --git a/tests/unit/utils/test_get_previous_rate_information.py b/tests/unit/utils/test_get_previous_rate_information.py index 90dc4029..4b27746d 100644 --- a/tests/unit/utils/test_get_previous_rate_information.py +++ b/tests/unit/utils/test_get_previous_rate_information.py @@ -75,7 +75,7 @@ async def test_when_target_has_rates_and_gmt_then_rate_information_is_returned() rate_data = create_rate_data(period_from, period_to, [10, 10, 20, 30, 30]) expected_current_rate = 10 for rate in rate_data: - if now >= rate["valid_from"] and now <= rate["valid_to"]: + if now >= rate["start"] and now <= rate["end"]: assert expected_current_rate == rate["value_inc_vat"] # Act @@ -86,19 +86,19 @@ async def test_when_target_has_rates_and_gmt_then_rate_information_is_returned() assert "previous_rate" in rate_information assert rate_information["previous_rate"]["value_inc_vat"] == round(30 / 100, 6) - assert rate_information["previous_rate"]["valid_from"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["previous_rate"]["valid_to"] == datetime.strptime("2022-02-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["start"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["end"] == datetime.strptime("2022-02-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 2 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(30 / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert rate_information["applicable_rates"][1]["value_inc_vat"] == round(30 / 100, 6) - assert rate_information["applicable_rates"][1]["valid_from"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][1]["valid_to"] == datetime.strptime("2022-02-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["start"] == datetime.strptime("2022-02-28T00:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["end"] == datetime.strptime("2022-02-28T01:00:00Z", "%Y-%m-%dT%H:%M:%S%z") @pytest.mark.asyncio async def test_when_target_has_rates_and_bst_then_rate_information_is_returned(): @@ -110,7 +110,7 @@ async def test_when_target_has_rates_and_bst_then_rate_information_is_returned() rate_data = create_rate_data(period_from, period_to, [10, 10, 20, 30, 30]) expected_current_rate = 20 for rate in rate_data: - if now >= rate["valid_from"] and now <= rate["valid_to"]: + if now >= rate["start"] and now <= rate["end"]: assert expected_current_rate == rate["value_inc_vat"] # Act @@ -121,19 +121,19 @@ async def test_when_target_has_rates_and_bst_then_rate_information_is_returned() assert "previous_rate" in rate_information assert rate_information["previous_rate"]["value_inc_vat"] == round(10 / 100, 6) - assert rate_information["previous_rate"]["valid_from"] == datetime.strptime("2022-02-27T23:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["previous_rate"]["valid_to"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["start"] == datetime.strptime("2022-02-27T23:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["end"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 2 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(10 / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-02-27T23:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-02-27T23:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert rate_information["applicable_rates"][1]["value_inc_vat"] == round(10 / 100, 6) - assert rate_information["applicable_rates"][1]["valid_from"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][1]["valid_to"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["start"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][1]["end"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") @pytest.mark.asyncio async def test_when_all_rates_different_then_rate_information_is_returned(): @@ -145,7 +145,7 @@ async def test_when_all_rates_different_then_rate_information_is_returned(): rate_data = create_rate_data(period_from, period_to, [10, 20, 30]) expected_current_rate = 30 for rate in rate_data: - if now >= rate["valid_from"] and now <= rate["valid_to"]: + if now >= rate["start"] and now <= rate["end"]: assert expected_current_rate == rate["value_inc_vat"] # Act @@ -156,15 +156,15 @@ async def test_when_all_rates_different_then_rate_information_is_returned(): assert "previous_rate" in rate_information assert rate_information["previous_rate"]["value_inc_vat"] == round(20 / 100, 6) - assert rate_information["previous_rate"]["valid_from"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["previous_rate"]["valid_to"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["start"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["end"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 1 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(20 / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2022-02-27T23:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2022-02-28T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") # Covering https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/441 @pytest.mark.asyncio @@ -228,12 +228,12 @@ async def test_when_agile_rates_then_rate_information_is_returned(now: datetime) assert "previous_rate" in rate_information assert rate_information["previous_rate"]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["previous_rate"]["valid_from"] == datetime.strptime("2023-10-06T09:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["previous_rate"]["valid_to"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["start"] == datetime.strptime("2023-10-06T09:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["previous_rate"]["end"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") assert "applicable_rates" in rate_information assert len(rate_information["applicable_rates"]) == 1 assert rate_information["applicable_rates"][0]["value_inc_vat"] == round(expected_current_rate / 100, 6) - assert rate_information["applicable_rates"][0]["valid_from"] == datetime.strptime("2023-10-06T09:00:00Z", "%Y-%m-%dT%H:%M:%S%z") - assert rate_information["applicable_rates"][0]["valid_to"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["start"] == datetime.strptime("2023-10-06T09:00:00Z", "%Y-%m-%dT%H:%M:%S%z") + assert rate_information["applicable_rates"][0]["end"] == datetime.strptime("2023-10-06T09:30:00Z", "%Y-%m-%dT%H:%M:%S%z") diff --git a/tests/unit/utils/test_is_off_peak.py b/tests/unit/utils/test_is_off_peak.py index 37dae7b1..b39ab66f 100644 --- a/tests/unit/utils/test_is_off_peak.py +++ b/tests/unit/utils/test_is_off_peak.py @@ -2,7 +2,7 @@ import pytest from custom_components.octopus_energy.utils import is_off_peak -from tests.integration import create_rate_data +from tests.unit import create_rate_data @pytest.mark.asyncio async def test_when_off_peak_not_available_then_false_returned(): diff --git a/tests/unit/utils/test_rates_to_thirty_minute_increments.py b/tests/unit/utils/test_rates_to_thirty_minute_increments.py index 34c21630..d4b5e916 100644 --- a/tests/unit/utils/test_rates_to_thirty_minute_increments.py +++ b/tests/unit/utils/test_rates_to_thirty_minute_increments.py @@ -72,8 +72,8 @@ async def test_go_rates_bst(): start_time = as_utc(parse_datetime("2022-10-09T00:00+01:00")) for index in range(48): end_time = start_time + timedelta(minutes=30) - assert result[index]["valid_from"] == start_time - assert result[index]["valid_to"] == end_time + assert result[index]["start"] == start_time + assert result[index]["end"] == end_time rates_index = 6 if index < 1: