|
6 | 6 | # pylint: disable=duplicate-code |
7 | 7 |
|
8 | 8 | import asyncio |
| 9 | +import logging |
9 | 10 | import re |
10 | 11 | from datetime import datetime, timedelta, timezone |
11 | 12 |
|
@@ -397,6 +398,45 @@ async def test_matryoshka_with_excl_3() -> None: |
397 | 398 | tester.bounds(priority=0, expected_power=-50.0, expected_bounds=(-60.0, 5.0)) |
398 | 399 |
|
399 | 400 |
|
| 401 | +@pytest.mark.parametrize( |
| 402 | + ("requested_power", "exclusion_bounds", "expected_power"), |
| 403 | + [ |
| 404 | + (-3.0, (-35.0, 7.0), 0.0), |
| 405 | + (3.0, (-7.0, 35.0), 0.0), |
| 406 | + (-30.0, (-35.0, 7.0), -35.0), |
| 407 | + ], |
| 408 | +) |
| 409 | +async def test_matryoshka_avoids_opposite_direction_outside_exclusion_bounds( |
| 410 | + caplog: pytest.LogCaptureFixture, |
| 411 | + requested_power: float, |
| 412 | + exclusion_bounds: tuple[float, float], |
| 413 | + expected_power: float, |
| 414 | +) -> None: |
| 415 | + """Avoid targets that would snap to the opposite direction.""" |
| 416 | + batteries = frozenset({ComponentId(2), ComponentId(5)}) |
| 417 | + system_bounds = _base_types.SystemBounds( |
| 418 | + timestamp=datetime.now(tz=timezone.utc), |
| 419 | + inclusion_bounds=timeseries.Bounds( |
| 420 | + lower=Power.from_watts(-200.0), upper=Power.from_watts(200.0) |
| 421 | + ), |
| 422 | + exclusion_bounds=timeseries.Bounds( |
| 423 | + lower=Power.from_watts(exclusion_bounds[0]), |
| 424 | + upper=Power.from_watts(exclusion_bounds[1]), |
| 425 | + ), |
| 426 | + ) |
| 427 | + tester = StatefulTester(batteries, system_bounds) |
| 428 | + |
| 429 | + with caplog.at_level(logging.INFO): |
| 430 | + tester.tgt_power( |
| 431 | + priority=1, |
| 432 | + power=requested_power, |
| 433 | + bounds=(-200.0, 200.0), |
| 434 | + expected=expected_power, |
| 435 | + ) |
| 436 | + |
| 437 | + assert f"target power: {expected_power:g} W" in caplog.messages[-1] |
| 438 | + |
| 439 | + |
400 | 440 | async def test_matryoshka_drop_old_proposals() -> None: |
401 | 441 | """Tests for the power managing actor. |
402 | 442 |
|
|
0 commit comments