|
30 | 30 | }
|
31 | 31 | }
|
32 | 32 |
|
| 33 | +EXPECTED_PRICES_BEFORE_JANUARY_2025 = { |
| 34 | + "electrohold": { |
| 35 | + "day": 0.265656, |
| 36 | + "night": 0.156384 |
| 37 | + }, |
| 38 | + "evn": { |
| 39 | + "day": 0.261648, |
| 40 | + "night": 0.152532 |
| 41 | + }, |
| 42 | + "energo_pro": { |
| 43 | + "day": 0.268344, |
| 44 | + "night": 0.151884 |
| 45 | + }, |
| 46 | + "custom": { |
| 47 | + "day": 0.25, |
| 48 | + "night": 0.15 |
| 49 | + } |
| 50 | +} |
| 51 | + |
33 | 52 | EXPECTED_PRICES = {
|
34 | 53 | "electrohold": {
|
35 |
| - "day": 0.265644, |
36 |
| - "night": 0.156372 |
| 54 | + "day": 0.287856, |
| 55 | + "night": 0.169464 |
37 | 56 | },
|
38 | 57 | "evn": {
|
39 |
| - "day": 0.261636, |
40 |
| - "night": 0.15252 |
| 58 | + "day": 0.283596, |
| 59 | + "night": 0.16536 |
41 | 60 | },
|
42 | 61 | "energo_pro": {
|
43 |
| - "day": 0.268332, |
44 |
| - "night": 0.151872 |
| 62 | + "day": 0.291228, |
| 63 | + "night": 0.16506 |
45 | 64 | },
|
46 | 65 | "custom": {
|
47 | 66 | "day": 0.25,
|
|
54 | 73 | "until": 1719777600, # midnight 2024-07-01 UTC+2
|
55 | 74 | "prices": EXPECTED_PRICES_BEFORE_JULY_2024
|
56 | 75 | },
|
| 76 | + { |
| 77 | + "until": 1735682400, # midnight 2025-01-01 UTC+2 |
| 78 | + "prices": EXPECTED_PRICES_BEFORE_JANUARY_2025 |
| 79 | + }, |
57 | 80 | {
|
58 | 81 | "prices": EXPECTED_PRICES
|
59 | 82 | }
|
60 | 83 | ]
|
61 | 84 |
|
62 | 85 |
|
63 | 86 | @pytest.mark.parametrize("provider", ("electrohold", "evn", "energo_pro", "custom"))
|
64 |
| -async def test_setup_and_remove_config_entry(hass: HomeAssistant, |
65 |
| - provider: str) -> None: |
66 |
| - """Test setting up and removing a config entry.""" |
67 |
| - for mp in [[mock_time, EXPECTED_PRICES], [mock_time_before_july_2024, EXPECTED_PRICES_BEFORE_JULY_2024]]: |
68 |
| - mock = mp[0] |
69 |
| - expected_prices = mp[1] |
70 |
| - with mock(21, 59): |
71 |
| - await do_setup_test(hass, provider, "dual", "day", |
72 |
| - expected_prices) |
73 |
| - await do_setup_test(hass, provider, "single", "day", |
74 |
| - expected_prices) |
75 |
| - |
76 |
| - with mock(22, 0): |
77 |
| - await do_setup_test(hass, provider, "dual", "night", |
78 |
| - expected_prices) |
79 |
| - await do_setup_test(hass, provider, "single", "day", |
80 |
| - expected_prices) |
81 |
| - |
82 |
| - with mock(5, 59): |
83 |
| - await do_setup_test(hass, provider, "dual", "night", |
84 |
| - expected_prices) |
85 |
| - await do_setup_test(hass, provider, "single", "day", |
86 |
| - expected_prices) |
87 |
| - |
88 |
| - with mock(6, 0): |
89 |
| - await do_setup_test(hass, provider, "dual", "day", |
90 |
| - expected_prices) |
91 |
| - await do_setup_test(hass, provider, "single", "day", |
92 |
| - expected_prices) |
93 |
| - |
94 |
| - # Meter clock is 30 minutes ahead |
95 |
| - with mock(21, 30): |
96 |
| - await do_setup_test(hass, provider, "dual", "night", |
97 |
| - expected_prices, 30) |
98 |
| - await do_setup_test(hass, provider, "single", "day", |
99 |
| - expected_prices, 30) |
100 |
| - |
101 |
| - with mock(5, 30): |
102 |
| - await do_setup_test(hass, provider, "dual", "day", |
103 |
| - expected_prices, 30) |
104 |
| - await do_setup_test(hass, provider, "single", "day", |
105 |
| - expected_prices, 30) |
106 |
| - |
107 |
| - # Meter clock is 30 minutes behind |
108 |
| - with mock(22, 29): |
109 |
| - await do_setup_test(hass, provider, "dual", "day", |
110 |
| - expected_prices, -30) |
111 |
| - await do_setup_test(hass, provider, "single", "day", |
112 |
| - expected_prices, -30) |
113 |
| - |
114 |
| - with mock(6, 29): |
115 |
| - await do_setup_test(hass, provider, "dual", "night", |
116 |
| - expected_prices, -30) |
117 |
| - await do_setup_test(hass, provider, "single", "day", |
118 |
| - expected_prices, -30) |
119 |
| - |
120 |
| - # Meter clock is 10 hours ahead |
121 |
| - with mock(12, 0): |
122 |
| - await do_setup_test(hass, provider, "dual", "night", |
123 |
| - expected_prices, 600) |
124 |
| - await do_setup_test(hass, provider, "single", "day", |
125 |
| - expected_prices, 600) |
126 |
| - |
127 |
| - with mock(20, 0): |
128 |
| - await do_setup_test(hass, provider, "dual", "day", |
129 |
| - expected_prices, 600) |
130 |
| - await do_setup_test(hass, provider, "single", "day", |
131 |
| - expected_prices, 600) |
132 |
| - |
133 |
| - # Meter clock is 10 hours behind |
134 |
| - with mock(8, 0): |
135 |
| - await do_setup_test(hass, provider, "dual", "night", |
136 |
| - expected_prices, -600) |
137 |
| - await do_setup_test(hass, provider, "single", "day", |
138 |
| - expected_prices, -600) |
139 |
| - |
140 |
| - with mock(16, 0): |
141 |
| - await do_setup_test(hass, provider, "dual", "day", |
142 |
| - expected_prices, -600) |
143 |
| - await do_setup_test(hass, provider, "single", "day", |
144 |
| - expected_prices, -600) |
| 87 | +async def test_prices_before_july_2024(hass: HomeAssistant, provider: str) -> None: |
| 88 | + """Test setting up and removing a config entry before July 2024.""" |
| 89 | + await do_setup_test_with_mock(hass, provider, mock_time_before_july_2024, |
| 90 | + EXPECTED_PRICES_BEFORE_JULY_2024) |
| 91 | + |
| 92 | + |
| 93 | +@pytest.mark.parametrize("provider", ("electrohold", "evn", "energo_pro", "custom")) |
| 94 | +async def test_prices_before_january_2025(hass: HomeAssistant, provider: str) -> None: |
| 95 | + """Test setting up and removing a config entry before January 2025.""" |
| 96 | + await do_setup_test_with_mock(hass, provider, mock_time_before_january_2025, |
| 97 | + EXPECTED_PRICES_BEFORE_JANUARY_2025) |
| 98 | + |
| 99 | + |
| 100 | +@pytest.mark.parametrize("provider", ("electrohold", "evn", "energo_pro", "custom")) |
| 101 | +async def test_prices_current(hass: HomeAssistant, provider: str) -> None: |
| 102 | + """Test setting up and removing a config entry with current prices.""" |
| 103 | + await do_setup_test_with_mock(hass, provider, mock_time, |
| 104 | + EXPECTED_PRICES) |
| 105 | + |
| 106 | + |
| 107 | +async def do_setup_test_with_mock(hass: HomeAssistant, |
| 108 | + provider: str, mock, expected_prices) -> None: |
| 109 | + with mock(21, 59): |
| 110 | + await do_setup_test(hass, provider, "dual", "day", |
| 111 | + expected_prices) |
| 112 | + await do_setup_test(hass, provider, "single", "day", |
| 113 | + expected_prices) |
| 114 | + |
| 115 | + with mock(22, 0): |
| 116 | + await do_setup_test(hass, provider, "dual", "night", |
| 117 | + expected_prices) |
| 118 | + await do_setup_test(hass, provider, "single", "day", |
| 119 | + expected_prices) |
| 120 | + |
| 121 | + with mock(5, 59): |
| 122 | + await do_setup_test(hass, provider, "dual", "night", |
| 123 | + expected_prices) |
| 124 | + await do_setup_test(hass, provider, "single", "day", |
| 125 | + expected_prices) |
| 126 | + |
| 127 | + with mock(6, 0): |
| 128 | + await do_setup_test(hass, provider, "dual", "day", |
| 129 | + expected_prices) |
| 130 | + await do_setup_test(hass, provider, "single", "day", |
| 131 | + expected_prices) |
| 132 | + |
| 133 | + # Meter clock is 30 minutes ahead |
| 134 | + with mock(21, 30): |
| 135 | + await do_setup_test(hass, provider, "dual", "night", |
| 136 | + expected_prices, 30) |
| 137 | + await do_setup_test(hass, provider, "single", "day", |
| 138 | + expected_prices, 30) |
| 139 | + |
| 140 | + with mock(5, 30): |
| 141 | + await do_setup_test(hass, provider, "dual", "day", |
| 142 | + expected_prices, 30) |
| 143 | + await do_setup_test(hass, provider, "single", "day", |
| 144 | + expected_prices, 30) |
| 145 | + |
| 146 | + # Meter clock is 30 minutes behind |
| 147 | + with mock(22, 29): |
| 148 | + await do_setup_test(hass, provider, "dual", "day", |
| 149 | + expected_prices, -30) |
| 150 | + await do_setup_test(hass, provider, "single", "day", |
| 151 | + expected_prices, -30) |
| 152 | + |
| 153 | + with mock(6, 29): |
| 154 | + await do_setup_test(hass, provider, "dual", "night", |
| 155 | + expected_prices, -30) |
| 156 | + await do_setup_test(hass, provider, "single", "day", |
| 157 | + expected_prices, -30) |
| 158 | + |
| 159 | + # Meter clock is 10 hours ahead |
| 160 | + with mock(12, 0): |
| 161 | + await do_setup_test(hass, provider, "dual", "night", |
| 162 | + expected_prices, 600) |
| 163 | + await do_setup_test(hass, provider, "single", "day", |
| 164 | + expected_prices, 600) |
| 165 | + |
| 166 | + with mock(20, 0): |
| 167 | + await do_setup_test(hass, provider, "dual", "day", |
| 168 | + expected_prices, 600) |
| 169 | + await do_setup_test(hass, provider, "single", "day", |
| 170 | + expected_prices, 600) |
| 171 | + |
| 172 | + # Meter clock is 10 hours behind |
| 173 | + with mock(8, 0): |
| 174 | + await do_setup_test(hass, provider, "dual", "night", |
| 175 | + expected_prices, -600) |
| 176 | + await do_setup_test(hass, provider, "single", "day", |
| 177 | + expected_prices, -600) |
| 178 | + |
| 179 | + with mock(16, 0): |
| 180 | + await do_setup_test(hass, provider, "dual", "day", |
| 181 | + expected_prices, -600) |
| 182 | + await do_setup_test(hass, provider, "single", "day", |
| 183 | + expected_prices, -600) |
145 | 184 |
|
146 | 185 |
|
147 | 186 | async def do_setup_test(hass: HomeAssistant, provider: str, tariff_type: str,
|
@@ -215,10 +254,19 @@ def mock_time_before_july_2024(hour: int, minute: int):
|
215 | 254 | return_value=datetime(2023, 12, 23, hour, minute, 0, 0, pytz.UTC))
|
216 | 255 |
|
217 | 256 |
|
| 257 | +def mock_time_before_january_2025(hour: int, minute: int): |
| 258 | + hour -= 2 |
| 259 | + if hour < 0: |
| 260 | + hour += 24 |
| 261 | + return mock.patch( |
| 262 | + "custom_components.bg_electricity_regulated_pricing.sensor.now_utc", |
| 263 | + return_value=datetime(2024, 12, 30, hour, minute, 0, 0, pytz.UTC)) |
| 264 | + |
| 265 | + |
218 | 266 | def mock_time(hour: int, minute: int):
|
219 | 267 | hour -= 2
|
220 | 268 | if hour < 0:
|
221 | 269 | hour += 24
|
222 | 270 | return mock.patch(
|
223 | 271 | "custom_components.bg_electricity_regulated_pricing.sensor.now_utc",
|
224 |
| - return_value=datetime(2024, 7, 1, hour, minute, 0, 0, pytz.UTC)) |
| 272 | + return_value=datetime(2025, 1, 1, hour, minute, 0, 0, pytz.UTC)) |
0 commit comments