|
4 | 4 | """System bounds tracker for PV inverters."""
|
5 | 5 |
|
6 | 6 | import asyncio
|
7 |
| -import logging |
8 | 7 | from collections import abc
|
9 | 8 |
|
10 | 9 | from frequenz.channels import Receiver, Sender, merge, select, selected_from
|
11 | 10 | from frequenz.client.microgrid import InverterData
|
12 | 11 |
|
| 12 | +from ..._internal._asyncio import run_forever |
13 | 13 | from ...actor import BackgroundService
|
14 | 14 | from ...microgrid import connection_manager
|
15 | 15 | from ...microgrid._power_distributing._component_status import ComponentPoolStatus
|
16 | 16 | from .._base_types import Bounds, SystemBounds
|
17 | 17 | from .._quantities import Power
|
18 | 18 |
|
19 |
| -_logger = logging.getLogger(__name__) |
20 |
| - |
21 | 19 |
|
22 | 20 | class PVSystemBoundsTracker(BackgroundService):
|
23 | 21 | """Track the system bounds for PV inverters.
|
@@ -54,7 +52,7 @@ def __init__(
|
54 | 52 |
|
55 | 53 | def start(self) -> None:
|
56 | 54 | """Start the PV inverter system bounds tracker."""
|
57 |
| - self._tasks.add(asyncio.create_task(self._run_forever())) |
| 55 | + self._tasks.add(asyncio.create_task(run_forever(self._run))) |
58 | 56 |
|
59 | 57 | async def _send_bounds(self) -> None:
|
60 | 58 | """Calculate and send the aggregate system bounds if they have changed."""
|
@@ -103,17 +101,6 @@ async def _send_bounds(self) -> None:
|
103 | 101 | )
|
104 | 102 | await self._bounds_sender.send(self._last_sent_bounds)
|
105 | 103 |
|
106 |
| - async def _run_forever(self) -> None: |
107 |
| - """Run the system bounds tracker.""" |
108 |
| - while True: |
109 |
| - try: |
110 |
| - await self._run() |
111 |
| - except Exception: # pylint: disable=broad-except |
112 |
| - _logger.exception( |
113 |
| - "Restarting after exception in PVSystemBoundsTracker.run()" |
114 |
| - ) |
115 |
| - await asyncio.sleep(1.0) |
116 |
| - |
117 | 104 | async def _run(self) -> None:
|
118 | 105 | """Run the system bounds tracker."""
|
119 | 106 | api_client = connection_manager.get().api_client
|
|
0 commit comments