|
5 | 5 |
|
6 | 6 | Useful for testing. |
7 | 7 | """ |
8 | | - |
9 | 8 | import dataclasses |
10 | 9 | from dataclasses import dataclass |
11 | 10 | from datetime import datetime, timezone |
|
29 | 28 | from frequenz.api.dispatch.v1.dispatch_pb2 import DispatchUpdateRequest |
30 | 29 | from google.protobuf.empty_pb2 import Empty |
31 | 30 |
|
| 31 | +# pylint: enable=no-name-in-module |
32 | 32 | from frequenz.client.base.conversion import to_datetime as _to_dt |
33 | 33 |
|
34 | | -# pylint: enable=no-name-in-module |
35 | | -from frequenz.client.dispatch._internal_types import DispatchCreateRequest |
36 | | -from frequenz.client.dispatch.types import Dispatch |
| 34 | +from .._internal_types import DispatchCreateRequest |
| 35 | +from ..types import Dispatch |
37 | 36 |
|
38 | 37 |
|
39 | 38 | @dataclass |
@@ -124,12 +123,15 @@ async def UpdateMicrogridDispatch( |
124 | 123 | request: DispatchUpdateRequest, |
125 | 124 | ) -> Empty: |
126 | 125 | """Update a dispatch.""" |
127 | | - dispatch = next((d for d in self.dispatches if d.id == request.id), None) |
| 126 | + index = next( |
| 127 | + (i for i, d in enumerate(self.dispatches) if d.id == request.id), |
| 128 | + None, |
| 129 | + ) |
128 | 130 |
|
129 | | - if dispatch is None: |
| 131 | + if index is None: |
130 | 132 | return Empty() |
131 | 133 |
|
132 | | - pb_dispatch = dispatch.to_protobuf() |
| 134 | + pb_dispatch = self.dispatches[index].to_protobuf() |
133 | 135 |
|
134 | 136 | # Go through the paths in the update mask and update the dispatch |
135 | 137 | for path in request.update_mask.paths: |
@@ -175,6 +177,8 @@ async def UpdateMicrogridDispatch( |
175 | 177 | dispatch = Dispatch.from_protobuf(pb_dispatch) |
176 | 178 | dispatch.update_time = datetime.now(tz=timezone.utc) |
177 | 179 |
|
| 180 | + self.dispatches[index] = dispatch |
| 181 | + |
178 | 182 | return Empty() |
179 | 183 |
|
180 | 184 | async def GetMicrogridDispatch( |
|
0 commit comments