11"""Test the models."""
22
33from datetime import datetime , timedelta , timezone
4+ from zoneinfo import ZoneInfo
45
56import pytest
67from aiohttp import ClientSession
@@ -140,10 +141,10 @@ async def test_model_se1_15_minute_resolution(aresponses: ResponsesMockServer) -
140141 assert energy .highest_price_tomorrow == 0.0059
141142 assert energy .lowest_price_today == 0.00001
142143 assert energy .lowest_price_tomorrow == 0.00005
143- assert energy .average_price_today == 0.00113
144- assert energy .average_price_tomorrow == 0.00249
144+ assert energy .average_price_today == 0.00121
145+ assert energy .average_price_tomorrow == 0.00232
145146 assert energy .current_price == 0.00128
146- assert energy .intervals_priced_equal_or_lower == 57
147+ assert energy .intervals_priced_equal_or_lower == 51
147148 # The price for another interval
148149 another_interval = datetime (2025 , 10 , 4 , 18 , 0 , tzinfo = timezone .utc )
149150 assert energy .price_at_time (another_interval ) == 0.00242
@@ -166,6 +167,26 @@ async def test_model_se1_15_minute_resolution(aresponses: ResponsesMockServer) -
166167 assert isinstance (energy .timestamp_prices , list )
167168
168169
170+ @pytest .mark .freeze_time ("2025-10-04 16:00:00+02:00" )
171+ async def test_prices_today_uses_region_local_date_for_utc_timestamps () -> None :
172+ """Use local date boundaries for SE1 even when source timestamps are UTC."""
173+ start_utc = datetime (2025 , 10 , 3 , 22 , 0 , tzinfo = timezone .utc )
174+ prices = {start_utc + i * timedelta (minutes = 15 ): i / 100000 for i in range (96 )}
175+ energy = Electricity (
176+ prices = prices ,
177+ resolution = timedelta (minutes = 15 ),
178+ time_zone = ZoneInfo ("Europe/Stockholm" ),
179+ )
180+
181+ prices_today = energy .prices_today ()
182+ assert len (prices_today ) == 96
183+ assert energy .current_price == 0.00064
184+ assert energy .lowest_price_today == 0.0
185+ assert energy .highest_price_today == 0.00095
186+ assert energy .average_price_today == 0.00047
187+ assert energy .prices_tomorrow () == {}
188+
189+
169190@pytest .mark .freeze_time ("2023-05-06 15:00:00+03:00" )
170191async def test_model_no_prices_for_tomorrow (aresponses : ResponsesMockServer ) -> None :
171192 """Test the model for usage at 15:00:00 UTC+3 with no prices for tomorrow."""
0 commit comments