Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set resent_latest=True for BatteryPool.power_status's channels #743

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ This version ships an experimental version of the **Power Manager**, adds prelim

This means that one or more inverters can be connected to one or more batteries.

- A `PowerManagingActor` implementation
- A `PowerManagingActor` implementation.

- Allow configuration of the `resend_latest` flag in channels owned by the `ChannelRegistry`.

## Bug Fixes

Expand Down
23 changes: 23 additions & 0 deletions src/frequenz/sdk/actor/_channel_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ def __init__(self, *, name: str) -> None:
self._name = name
self._channels: dict[str, Broadcast[typing.Any]] = {}

def set_resend_latest(self, key: str, resend_latest: bool) -> None:
"""Set the `resend_latest` flag for a given channel.

This flag controls whether the latest value of the channel should be resent to
new receivers, in slow streams.

`resend_latest` is `False` by default. It is safe to be set in data/reporting
channels, but is not recommended for use in channels that stream control
instructions.

Args:
key: The key to identify the channel.
resend_latest: Whether to resend the latest value to new receivers, for the
given channel.
"""
if key not in self._channels:
self._channels[key] = Broadcast(f"{self._name}-{key}")
# This attribute is protected in the current version of the channels library,
# but that will change in the future.
self._channels[ # pylint: disable=protected-access
key
]._resend_latest = resend_latest

def new_sender(self, key: str) -> Sender[typing.Any]:
"""Get a sender to a dynamically created channel with the given key.

Expand Down
3 changes: 3 additions & 0 deletions src/frequenz/sdk/timeseries/battery_pool/_battery_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def power_status(self) -> ReceiverFetcher[_power_managing.Report]:
] = asyncio.create_task(
self._battery_pool._power_manager_bounds_subscription_sender.send(sub)
)
self._battery_pool._channel_registry.set_resend_latest(
sub.get_channel_name(), True
)
return self._battery_pool._channel_registry.new_receiver_fetcher(
sub.get_channel_name()
)
Expand Down