diff --git a/custom_components/peaqhvac/test/test_offsets.py b/custom_components/peaqhvac/test/test_offsets.py index 6f35790..f53d95d 100644 --- a/custom_components/peaqhvac/test/test_offsets.py +++ b/custom_components/peaqhvac/test/test_offsets.py @@ -6,32 +6,31 @@ from ..service.hvac.offset.peakfinder import smooth_transitions from ..service.models.enums.hvac_presets import HvacPresets -P231213 = [1.17, 1.14, 1.14, 1.11, 1.11, 1.14, 1.25, 1.59, 2.09, 2.09, 2.13, 2.14, - 2.14, 1.61, 1.59, 1.62, 1.61, 1.68, 1.61, 1.52, 1.44, 1.36, 1.38, 1.27] -P231214 = [1.17, 1.15, 1.16, 1.16, 1.19, 1.24, 1.47, 1.81, 1.97, 2.19, 2.19, 1.92, - 1.81, 1.99, 2.19, 2.73, 2.73, 2.63, 2.11, 1.81, 1.62, 1.43, 1.41, 1.28] +P231213 = [1.17, 1.14, 1.14, 1.11, 1.11, 1.14, 1.25, 1.59, 2.09, 2.09, 2.13, 2.14,2.14, 1.61, 1.59, 1.62, 1.61, 1.68, 1.61, 1.52, 1.44, 1.36, 1.38, 1.27] +P231214 = [1.17, 1.15, 1.16, 1.16, 1.19, 1.24, 1.47, 1.81, 1.97, 2.19, 2.19, 1.92,1.81, 1.99, 2.19, 2.73, 2.73, 2.63, 2.11, 1.81, 1.62, 1.43, 1.41, 1.28] P231215 =[1.28,1.24,1.2,1.15,1.13,1.2,1.42,1.57,1.78,1.72,1.61,1.51,1.39,1.31,1.28,1.3,1.42,1.37,1.26,1.19,1.15,1.14,0.93,1.05] P231216 = [0.69,0.62,0.56,0.45,0.38,0.32,0.31,0.31,0.31,0.3,0.3,0.27,0.26,0.25,0.26,0.27,0.28,0.27,0.24,0.23,0.15,0.11,0.08,0.08] P231217 = [0.06,0.06,0.06,0.06,0.07,0.08,0.08,0.08,0.1,0.11,0.11,0.13,0.11,0.13,0.11,0.14,0.16,0.24,0.27,0.27,0.25,0.24,0.17,0.16] P231218 = [0.22, 0.2, 0.17, 0.15, 0.16, 0.22, 0.3, 0.38, 0.43, 0.4, 0.38, 0.36, 0.32, 0.32, 0.32, 0.33, 0.36, 0.4, 0.39, 0.35, 0.32, 0.29, 0.26, 0.22] P231219 = [0.19, 0.15, 0.11, 0.1, 0.14, 0.2, 0.28, 0.41, 0.51, 0.52, 0.54, 0.51, 0.45, 0.41, 0.41, 0.4, 0.37, 0.36, 0.37, 0.32, 0.3, 0.27, 0.25, 0.24] - -def test_offsets_cent_and_normal_match(): +@pytest.mark.asyncio +async def test_offsets_cent_and_normal_match(): prices = P231213 + P231214 now_dt = datetime(2023,12,13,20,43,0) - r1 = set_offset_dict(prices, now_dt, 0, {}) - r2 = set_offset_dict([p*100 for p in prices], now_dt, 0, {}) + r1 = await set_offset_dict(prices, now_dt, 0, {}) + r2 = await set_offset_dict([p*100 for p in prices], now_dt, 0, {}) assert r1 == r2 -def test_assert_cheaper_hours_tomorrow_not_lower_offset_than_today(): +@pytest.mark.asyncio +async def test_assert_cheaper_hours_tomorrow_not_lower_offset_than_today(): """error with 231217 last hours having another offset than the same price for 231216""" _tolerance = 3 indoors_preset = HvacPresets.Normal prices = P231218 prices_tomorrow = P231219 now_dt = datetime(2023, 12, 18, 20, 43, 0) - offset_dict = set_offset_dict(prices + prices_tomorrow, now_dt, 0, {}) + offset_dict = await set_offset_dict(prices + prices_tomorrow, now_dt, 0, {}) offs2 = offset_per_day( all_prices=prices + prices_tomorrow, day_values=offset_dict, @@ -50,57 +49,14 @@ def test_assert_cheaper_hours_tomorrow_not_lower_offset_than_today(): #assert 1 > 2 - -# def test_offsets_correct_curve_over_night_cached_today(): -# _tolerance = 3 -# indoors_preset = HvacPresets.Normal -# prices = P231215 -# prices_tomorrow = P231216 -# now_dt = datetime(2023,12,15,0,3,0) -# offset_dict1 = set_offset_dict(prices, now_dt, 0, {}) -# today1 = offset_per_day( -# all_prices=prices, -# day_values=offset_dict1, -# tolerance=_tolerance, -# indoors_preset=indoors_preset, -# ) -# -# ret1 = smooth_transitions( -# vals=today1, -# tolerance=_tolerance, -# ) -# key_today_only = [1,1, 2, 2, 3, 2, -2, -# -4, -7, -6, -4, -3, -1, 0, 1, 0, -# -2, -1, 1, 2, 2, 3, 6, 4] -# assert [v for k,v in ret1.items()] == key_today_only -# -# now_dt = datetime(2023,12,15,13,3,0) -# offset_dict2 = set_offset_dict(prices+prices_tomorrow, now_dt, 0, ret1) -# today2 = offset_per_day( -# all_prices=prices + prices_tomorrow, -# day_values=offset_dict2, -# tolerance=_tolerance, -# indoors_preset=indoors_preset, -# ) -# -# ret2 = smooth_transitions( -# vals=today2, -# tolerance=_tolerance, -# ) -# -# key_today = [-3, -2, -2, -2, -2, -2, -# -3, -4, -5, -5, -4, -4, -3, -2, -2, -2, -3, -3, -2, -2, -2, -2, -1, -2, -# 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2] -# -# assert [v for k, v in ret2.items()] == key_today - -def test_smooth_transistions_no_weather_prog_nothing_exceeds_tolerance(): +@pytest.mark.asyncio +async def test_smooth_transistions_no_weather_prog_nothing_exceeds_tolerance(): _tolerance = 3 indoors_preset = HvacPresets.Normal prices = P231213 prices_tomorrow = P231214 now_dt = datetime(2023, 12, 13, 20, 43, 0) - offset_dict = set_offset_dict(prices+prices_tomorrow, now_dt, 0, {}) + offset_dict = await set_offset_dict(prices+prices_tomorrow, now_dt, 0, {}) print(offset_dict) offsets = offset_per_day( @@ -117,13 +73,14 @@ def test_smooth_transistions_no_weather_prog_nothing_exceeds_tolerance(): assert all([abs(v) <= _tolerance for k, v in ret.items()]) -def test_adjust_to_treshold_no_exceeding_values(): +@pytest.mark.asyncio +async def test_adjust_to_treshold_no_exceeding_values(): _tolerance = 3 indoors_preset = HvacPresets.Normal prices = P231213 prices_tomorrow = P231214 now_dt = datetime(2023, 12, 13, 20, 43, 0) - offset_dict = set_offset_dict(prices + prices_tomorrow, now_dt, 0, {}) + offset_dict = await set_offset_dict(prices + prices_tomorrow, now_dt, 0, {}) offsets = offset_per_day( all_prices=prices + prices_tomorrow, @@ -140,5 +97,4 @@ def test_adjust_to_treshold_no_exceeding_values(): for k,v in smooth.items(): model = CalculatedOffsetModel(current_offset=v, current_tempdiff=random.uniform(-1, 1), current_temp_trend_offset=random.uniform(-1, 1)) adj = adjust_to_threshold(model, 0, _tolerance) - assert abs(adj) <= _tolerance - + assert abs(adj) <= _tolerance \ No newline at end of file diff --git a/custom_components/peaqhvac/test/test_water_heater_next_start.py b/custom_components/peaqhvac/test/test_water_heater_next_start.py deleted file mode 100644 index fbb4ce7..0000000 --- a/custom_components/peaqhvac/test/test_water_heater_next_start.py +++ /dev/null @@ -1,46 +0,0 @@ -import pytest -from datetime import datetime, timedelta -from ..service.hvac.water_heater.water_heater_next_start import NextWaterBoost -from ..service.models.enums.hvac_presets import HvacPresets - -P230830 = [0.76,0.57,0.59,0.64,0.97,1.5,1.97,2.22,2.16,1.93,1.72,1.55,1.53,1.5,1.48,1.52,1.5,1.79,2.16,2.59,2.58,2.08,1.81,1.43] -P230831 = [1.42,0.8,0.61,0.59,0.6,1.4,1.64,2.17,1.97,1.77,1.51,1.44,1.41,1.38,1.36,1.37,1.4,1.55,1.84,2.28,2.14,1.94,1.62,1.47] -P230901 = [0.38,0.37,0.36,0.36,0.36,0.37,0.4,1.17,1.95,1.69,1.56,1.47,1.41,0.5,0.47,0.52,0.53,0.55,0.55,0.52,0.47,0.43,0.4,0.38] -P230902=[0.36,0.35,0.34,0.33,0.33,0.32,0.35,0.37,0.37,0.38,0.38,0.38,0.37,0.37,0.37,0.38,0.4,0.43,0.44,0.45,0.45,0.43,0.4,0.39] -P230903=[0.37,0.37,0.36,0.36,0.37,0.37,0.37,0.39,0.41,0.42,0.44,0.44,0.39,0.25,0.15,0.31,0.45,0.45,0.44,0.42,0.37,0.32,0.22,0.1] -P231214 =[1.17,1.15,1.16,1.16,1.19,1.24,1.47,1.81,1.97,2.19,2.19,1.92,1.81,1.99,2.19,2.73,2.73,2.63,2.11,1.81,1.62,1.43,1.41,1.28] -P231215 =[1.28,1.24,1.2,1.15,1.13,1.2,1.42,1.57,1.78,1.72,1.61,1.51,1.39,1.31,1.28,1.3,1.42,1.37,1.26,1.19,1.15,1.14,0.93,1.05] -MIN_DEMAND = 26 - -# def test_start_time_water_is_cold_no_non_hours(): -# now_dt = datetime(2023,8,26,18,43,0) -# wb = NextWaterBoost() -# tt = wb.next_predicted_demand(prices_today=P230830, prices_tomorrow=P230831, temp=35, temp_trend=0, target_temp=40, preset=HvacPresets.Normal, now_dt=now_dt, latest_boost=now_dt-timedelta(hours=1)) -# assert tt[0] == datetime(2023, 8, 26, 23, 47, 0) -# -# -# def test_start_time_water_is_cold_blocked_by_non_hours(): -# now_dt = datetime(2023,8,26,18,43,0) -# wb = NextWaterBoost(non_hours=[23]) -# tt = wb.next_predicted_demand(prices_today=P230830, prices_tomorrow=P230831, temp=35, temp_trend=0, target_temp=40, preset=HvacPresets.Normal, now_dt=now_dt, latest_boost=now_dt-timedelta(hours=1)) -# assert tt[0] == datetime(2023, 8, 27, 0, 47, 0) -# -# -# def test_start_time_water_not_cold_no_non_hours(): -# now_dt = datetime(2023,8,26,18,43,0) -# wb = NextWaterBoost() -# tt = wb.next_predicted_demand(prices_today=P230830, prices_tomorrow=P230831, temp=44, temp_trend=0, target_temp=40, preset=HvacPresets.Normal, now_dt=now_dt, latest_boost=now_dt-timedelta(hours=1)) -# assert tt[0] == datetime(2023, 8, 27, 3, 50, 0) -# -# -# def test_start_time_water_not_cold_blocked_by_non_hours(): -# now_dt = datetime(2023,8,26,18,43,0) -# wb = NextWaterBoost(non_hours=[2,3]) -# tt = wb.next_predicted_demand(prices_today=P230830, prices_tomorrow=P230831, temp=44, temp_trend=0, target_temp=40, preset=HvacPresets.Normal, now_dt=now_dt, latest_boost=now_dt-timedelta(hours=1)) -# assert tt[0] == datetime(2023, 8, 27, 4, 50, 0) -# -# def test_start_time_water_demand_hour_dont_start_directly(): -# now_dt = datetime(2023,8,26,19,50,0) -# wb = NextWaterBoost(non_hours=[2,3],demand_hours=[20,21]) -# tt = wb.next_predicted_demand(prices_today=P231214, prices_tomorrow=P231215, temp=49, temp_trend=0, target_temp=40, preset=HvacPresets.Normal, now_dt=now_dt, latest_boost=now_dt-timedelta(minutes=12)) -# assert tt[0] > now_dt + timedelta(minutes=48)