Skip to content

Commit

Permalink
Fix exit-on-timeout issue in PowerDistributor (#1035)
Browse files Browse the repository at this point in the history
This is a backport of #1020 to 1.0.0-rc-6xx
  • Loading branch information
shsms authored Aug 9, 2024
2 parents aa259ec + c8cf967 commit 956823f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
## Bug Fixes

- Fixes a bug in the ring buffer in case the updated value is missing and creates a gap in time.

- Fixed a bug that was causing the `PowerDistributor` to exit if power requests to PV inverters or EV chargers timeout.
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,29 @@ async def _set_api_power(
succeeded_components: set[int] = set()
failed_power = Power.zero()
for component_id, task in tasks.items():
exc = task.exception()
if exc is not None:
failed_components.add(component_id)
failed_power += target_power_changes[component_id]
try:
task.result()
except asyncio.CancelledError:
_logger.warning(
"Timeout while setting power to EV charger %s", component_id
)
except grpc.aio.AioRpcError as exc:
_logger.warning(
"Error while setting power to EV charger %s: %s",
component_id,
exc,
)
except Exception: # pylint: disable=broad-except
_logger.exception(
"Unknown error while setting power to EV charger: %s", component_id
)
else:
succeeded_components.add(component_id)
continue

failed_components.add(component_id)
failed_power += target_power_changes[component_id]

match task.exception():
case asyncio.CancelledError():
_logger.warning(
"Timeout while setting power to EV charger %s", component_id
)
case grpc.aio.AioRpcError() as err:
_logger.warning(
"Error while setting power to EV charger %s: %s",
component_id,
err,
)
case Exception():
_logger.exception(
"Unknown error while setting power to EV charger: %s",
component_id,
)
if failed_components:
return PartialFailure(
failed_components=failed_components,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,30 @@ async def _set_api_power( # pylint: disable=too-many-locals
succeeded_components: set[int] = set()
failed_power = Power.zero()
for component_id, task in tasks.items():
exc = task.exception()
if exc is not None:
failed_components.add(component_id)
failed_power += allocations[component_id]
try:
task.result()
except asyncio.CancelledError:
_logger.warning(
"Timeout while setting power to PV inverter %s", component_id
)
except grpc.aio.AioRpcError as exc:
_logger.warning(
"Error while setting power to PV inverter %s: %s",
component_id,
exc,
)
except Exception: # pylint: disable=broad-except
_logger.exception(
"Unknown error while setting power to PV inverter: %s",
component_id,
)
else:
succeeded_components.add(component_id)
continue

failed_components.add(component_id)
failed_power += allocations[component_id]

match task.exception():
case asyncio.CancelledError():
_logger.warning(
"Timeout while setting power to PV inverter %s", component_id
)
case grpc.aio.AioRpcError() as err:
_logger.warning(
"Error while setting power to PV inverter %s: %s",
component_id,
err,
)
case Exception():
_logger.exception(
"Unknown error while setting power to PV inverter: %s",
component_id,
)
if failed_components:
await self._results_sender.send(
PartialFailure(
Expand Down

0 comments on commit 956823f

Please sign in to comment.