diff --git a/examples/energy.py b/examples/energy.py index 530b3ff..c74a486 100644 --- a/examples/energy.py +++ b/examples/energy.py @@ -32,7 +32,7 @@ async def print_prices(client: SpotHinta, region: Region) -> None: print(f"Current price: {energy_today.current_price}") print(f"Next hour price: {energy_today.price_at_time(utc_next_hour)}") - lower_hours: int = energy_today.hours_priced_equal_or_lower + lower_hours: int = energy_today.intervals_priced_equal_or_lower print(f"Lower hours: {lower_hours}") diff --git a/spothinta_api/models.py b/spothinta_api/models.py index 4548585..1f89261 100644 --- a/spothinta_api/models.py +++ b/spothinta_api/models.py @@ -26,7 +26,7 @@ def _timed_value(moment: datetime, prices: dict[datetime, float]) -> float | Non """ value = None for timestamp, price in prices.items(): - future_dt = timestamp + timedelta(hours=1) + future_dt = timestamp + timedelta(minutes=15) if timestamp <= moment < future_dt: value = round(price, 5) return value @@ -63,11 +63,11 @@ class Electricity: @property def current_price(self) -> float | None: - """Return the price for the current hour. + """Return the price for the current interval. Returns ------- - The price for the current hour or None if no price is available. + The price for the current interval or None if no price is available. """ return self.price_at_time(self.now_in_timezone()) @@ -237,12 +237,12 @@ def timestamp_prices_today(self) -> list[dict[str, float | datetime]]: return self.generate_timestamp_list(self.prices_today()) @property - def hours_priced_equal_or_lower(self) -> int: - """Return the number of hours with the current price or better. + def intervals_priced_equal_or_lower(self) -> int: + """Return the number of intervals with the current price or better. Returns ------- - The number of hours with the current price or better. + The number of intervals with the current price or better. """ current = self.current_price or 0 diff --git a/tests/test_models.py b/tests/test_models.py index 8754161..0d60ae4 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -42,10 +42,10 @@ async def test_model(aresponses: ResponsesMockServer) -> None: assert energy.average_price_today == 0.08935 assert energy.average_price_tomorrow == 0.07284 assert energy.current_price == 0.062 - assert energy.hours_priced_equal_or_lower == 1 - # The price for another hour - another_hour = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) - assert energy.price_at_time(another_hour) == 0.1055 + assert energy.intervals_priced_equal_or_lower == 1 + # The price for another interval + another_interval = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) + assert energy.price_at_time(another_interval) == 0.1055 assert energy.lowest_price_time_today == datetime.strptime( "2023-05-06 15:00:00+03:00", "%Y-%m-%d %H:%M:%S%z", @@ -92,10 +92,10 @@ async def test_model_15_minute_resolution(aresponses: ResponsesMockServer) -> No assert energy.average_price_today == 0.00131 assert energy.average_price_tomorrow == 0.00239 assert energy.current_price == 0.00157 - assert energy.hours_priced_equal_or_lower == 63 - # The price for another hour - another_hour = datetime(2025, 10, 4, 17, 0, tzinfo=timezone.utc) - assert energy.price_at_time(another_hour) == 0.0033 + assert energy.intervals_priced_equal_or_lower == 63 + # The price for another interval + another_interval = datetime(2025, 10, 4, 17, 0, tzinfo=timezone.utc) + assert energy.price_at_time(another_interval) == 0.0033 assert energy.lowest_price_time_today == datetime.strptime( "2025-10-04 5:00:00+03:00", "%Y-%m-%d %H:%M:%S%z", @@ -143,10 +143,10 @@ async def test_model_se1_15_minute_resolution(aresponses: ResponsesMockServer) - assert energy.average_price_today == 0.00113 assert energy.average_price_tomorrow == 0.00249 assert energy.current_price == 0.00128 - assert energy.hours_priced_equal_or_lower == 57 - # The price for another hour - another_hour = datetime(2025, 10, 4, 18, 0, tzinfo=timezone.utc) - assert energy.price_at_time(another_hour) == 0.00242 + assert energy.intervals_priced_equal_or_lower == 57 + # The price for another interval + another_interval = datetime(2025, 10, 4, 18, 0, tzinfo=timezone.utc) + assert energy.price_at_time(another_interval) == 0.00242 assert energy.lowest_price_time_today == datetime.strptime( "2025-10-04 03:00:00+00:00", "%Y-%m-%d %H:%M:%S%z", @@ -191,10 +191,10 @@ async def test_model_no_prices_for_tomorrow(aresponses: ResponsesMockServer) -> assert energy.average_price_today == 0.08935 assert energy.average_price_tomorrow is None assert energy.current_price == 0.062 - assert energy.hours_priced_equal_or_lower == 1 - # The price for another hour - another_hour = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) - assert energy.price_at_time(another_hour) == 0.1055 + assert energy.intervals_priced_equal_or_lower == 1 + # The price for another interval + another_interval = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) + assert energy.price_at_time(another_interval) == 0.1055 assert energy.lowest_price_time_today == datetime.strptime( "2023-05-06 15:00:00+03:00", "%Y-%m-%d %H:%M:%S%z", @@ -273,10 +273,10 @@ async def test_only_data_for_tomorrow(aresponses: ResponsesMockServer) -> None: assert energy.average_price_today is None assert energy.highest_price_today is None assert energy.lowest_price_today is None - assert energy.hours_priced_equal_or_lower == 0 - # The price for another hour - another_hour = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) - assert energy.price_at_time(another_hour) is None + assert energy.intervals_priced_equal_or_lower == 0 + # The price for another interval + another_interval = datetime(2023, 5, 6, 17, 0, tzinfo=timezone.utc) + assert energy.price_at_time(another_interval) is None assert energy.lowest_price_time_today is None assert energy.highest_price_time_today is None assert isinstance(energy.timestamp_prices, list)