diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 42b8440c9..445c8589e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -30,3 +30,5 @@ ## Bug Fixes - When using the new wall clock timer in the resampmler, it will now resync to the system time if it drifts away for more than a resample period, and do dynamic adjustments to the timer if the monotonic clock has a small drift compared to the wall clock. + +- A power distributor logging issue is fixed, that was causing the power for multiple batteries connected to the same inverter to be reported incorrectly. diff --git a/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py b/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py index 7f29fab6a..8215bce33 100644 --- a/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py +++ b/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_battery_manager.py @@ -266,17 +266,26 @@ async def _distribute_power( Result from the microgrid API. """ distributed_power_value = request.power - distribution.remaining_power - battery_distribution: dict[ComponentId, Power] = {} + battery_distribution: dict[frozenset[ComponentId], Power] = {} + battery_ids: set[ComponentId] = set() for inverter_id, dist in distribution.distribution.items(): for battery_id in self._inv_bats_map[inverter_id]: - battery_distribution[battery_id] = ( - battery_distribution.get(battery_id, Power.zero()) + dist - ) - _logger.debug( - "Distributing power %s between the batteries %s", - distributed_power_value, - str(battery_distribution), - ) + battery_ids.add(battery_id) + battery_distribution[self._inv_bats_map[inverter_id]] = dist + if _logger.isEnabledFor(logging.DEBUG): + _logger.debug( + "Distributing power %s between the batteries: %s", + distributed_power_value, + ", ".join( + ( + str(next(iter(cids))) + if len(cids) == 1 + else f"({', '.join(str(cid) for cid in cids)})" + ) + + f": {power}" + for cids, power in battery_distribution.items() + ), + ) failed_power, failed_batteries = await self._set_distributed_power( distribution, self._api_power_request_timeout @@ -284,7 +293,7 @@ async def _distribute_power( response: Success | PartialFailure if len(failed_batteries) > 0: - succeed_batteries = set(battery_distribution.keys()) - failed_batteries + succeed_batteries = battery_ids - failed_batteries response = PartialFailure( request=request, succeeded_power=distributed_power_value - failed_power, @@ -294,7 +303,7 @@ async def _distribute_power( excess_power=distribution.remaining_power, ) else: - succeed_batteries = set(battery_distribution.keys()) + succeed_batteries = battery_ids response = Success( request=request, succeeded_power=distributed_power_value,