|
3 | 3 |
|
4 | 4 | """Interactions with pools of PV inverters.""" |
5 | 5 |
|
| 6 | +import asyncio |
| 7 | +import typing |
6 | 8 | import uuid |
7 | 9 |
|
8 | 10 | from ..._internal._channels import ReceiverFetcher |
| 11 | +from ...actor import _power_managing |
9 | 12 | from .._base_types import SystemBounds |
10 | 13 | from ._pv_pool_reference_store import PVPoolReferenceStore |
| 14 | +from ._result_types import PVPoolReport |
11 | 15 |
|
12 | 16 |
|
13 | 17 | class PVPoolError(Exception): |
@@ -47,9 +51,41 @@ def __init__( # pylint: disable=too-many-arguments |
47 | 51 | """ |
48 | 52 | self._pv_pool_ref = pv_pool_ref |
49 | 53 | unique_id = uuid.uuid4() |
50 | | - self._source_id = unique_id if name is None else f"{name}-{unique_id}" |
| 54 | + self._source_id = str(unique_id) if name is None else f"{name}-{unique_id}" |
51 | 55 | self._priority = priority |
52 | 56 |
|
| 57 | + @property |
| 58 | + def power_status(self) -> ReceiverFetcher[PVPoolReport]: |
| 59 | + """Get a receiver to receive new power status reports when they change. |
| 60 | +
|
| 61 | + These include |
| 62 | + - the current inclusion/exclusion bounds available for the pool's priority, |
| 63 | + - the current target power for the pool's set of batteries, |
| 64 | + - the result of the last distribution request for the pool's set of batteries. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + A receiver that will stream power status reports for the pool's priority. |
| 68 | + """ |
| 69 | + sub = _power_managing.ReportRequest( |
| 70 | + source_id=self._source_id, |
| 71 | + priority=self._priority, |
| 72 | + component_ids=self._pv_pool_ref.component_ids, |
| 73 | + ) |
| 74 | + self._pv_pool_ref.power_bounds_subs[sub.get_channel_name()] = ( |
| 75 | + asyncio.create_task( |
| 76 | + self._pv_pool_ref.power_manager_bounds_subs_sender.send(sub) |
| 77 | + ) |
| 78 | + ) |
| 79 | + channel = self._pv_pool_ref.channel_registry.get_or_create( |
| 80 | + _power_managing._Report, # pylint: disable=protected-access |
| 81 | + sub.get_channel_name(), |
| 82 | + ) |
| 83 | + channel.resend_latest = True |
| 84 | + |
| 85 | + # More details on why the cast is needed here: |
| 86 | + # https://github.com/frequenz-floss/frequenz-sdk-python/issues/823 |
| 87 | + return typing.cast(ReceiverFetcher[PVPoolReport], channel) |
| 88 | + |
53 | 89 | @property |
54 | 90 | def _system_power_bounds(self) -> ReceiverFetcher[SystemBounds]: |
55 | 91 | """Return a receiver fetcher for the system power bounds.""" |
|
0 commit comments