3636from frequenz .client .base .exception import ClientNotConnected
3737from frequenz .client .base .retry import LinearBackoff
3838from frequenz .client .base .streaming import GrpcStreamBroadcaster
39+ from frequenz .client .common .microgrid import MicrogridId
3940
4041from ._internal_types import DispatchCreateRequest
4142from .recurrence import RecurrenceRule
4243from .types import (
4344 Dispatch ,
4445 DispatchEvent ,
46+ DispatchId ,
4547 TargetComponents ,
4648 _target_components_to_protobuf ,
4749)
@@ -114,7 +116,7 @@ def stub(self) -> dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub:
114116 # pylint: disable=too-many-arguments, too-many-locals
115117 async def list (
116118 self ,
117- microgrid_id : int ,
119+ microgrid_id : MicrogridId ,
118120 * ,
119121 target_components : Iterator [TargetComponents ] = iter (()),
120122 start_from : datetime | None = None ,
@@ -185,7 +187,7 @@ def to_interval(
185187 )
186188
187189 request = ListMicrogridDispatchesRequest (
188- microgrid_id = microgrid_id ,
190+ microgrid_id = int ( microgrid_id ) ,
189191 filter = filters ,
190192 pagination_params = (
191193 PaginationParams (page_size = page_size ) if page_size else None
@@ -211,7 +213,7 @@ def to_interval(
211213 else :
212214 break
213215
214- def stream (self , microgrid_id : int ) -> channels .Receiver [DispatchEvent ]:
216+ def stream (self , microgrid_id : MicrogridId ) -> channels .Receiver [DispatchEvent ]:
215217 """Receive a stream of dispatch events.
216218
217219 This function returns a receiver channel that can be used to receive
@@ -238,15 +240,15 @@ def stream(self, microgrid_id: int) -> channels.Receiver[DispatchEvent]:
238240 return self ._get_stream (microgrid_id ).new_receiver ()
239241
240242 def _get_stream (
241- self , microgrid_id : int
243+ self , microgrid_id : MicrogridId
242244 ) -> GrpcStreamBroadcaster [StreamMicrogridDispatchesResponse , DispatchEvent ]:
243245 """Get an instance to the streaming helper."""
244246 broadcaster = self ._streams .get (microgrid_id )
245247 if broadcaster is not None and not broadcaster .is_running :
246248 del self ._streams [microgrid_id ]
247249 broadcaster = None
248250 if broadcaster is None :
249- request = StreamMicrogridDispatchesRequest (microgrid_id = microgrid_id )
251+ request = StreamMicrogridDispatchesRequest (microgrid_id = int ( microgrid_id ) )
250252 broadcaster = GrpcStreamBroadcaster (
251253 stream_name = "StreamMicrogridDispatches" ,
252254 stream_method = lambda : cast (
@@ -266,7 +268,7 @@ def _get_stream(
266268
267269 async def create ( # pylint: disable=too-many-positional-arguments
268270 self ,
269- microgrid_id : int ,
271+ microgrid_id : MicrogridId ,
270272 type : str , # pylint: disable=redefined-builtin
271273 start_time : datetime | Literal ["NOW" ],
272274 duration : timedelta | None ,
@@ -334,8 +336,8 @@ async def create( # pylint: disable=too-many-positional-arguments
334336 async def update (
335337 self ,
336338 * ,
337- microgrid_id : int ,
338- dispatch_id : int ,
339+ microgrid_id : MicrogridId ,
340+ dispatch_id : DispatchId ,
339341 new_fields : dict [str , Any ],
340342 ) -> Dispatch :
341343 """Update a dispatch.
@@ -423,7 +425,9 @@ async def update(
423425
424426 return Dispatch .from_protobuf (response .dispatch )
425427
426- async def get (self , * , microgrid_id : int , dispatch_id : int ) -> Dispatch :
428+ async def get (
429+ self , * , microgrid_id : MicrogridId , dispatch_id : DispatchId
430+ ) -> Dispatch :
427431 """Get a dispatch.
428432
429433 Args:
@@ -434,7 +438,7 @@ async def get(self, *, microgrid_id: int, dispatch_id: int) -> Dispatch:
434438 Dispatch: The dispatch.
435439 """
436440 request = GetMicrogridDispatchRequest (
437- dispatch_id = dispatch_id , microgrid_id = microgrid_id
441+ dispatch_id = int ( dispatch_id ) , microgrid_id = int ( microgrid_id )
438442 )
439443 response = await cast (
440444 Awaitable [GetMicrogridDispatchResponse ],
@@ -444,15 +448,17 @@ async def get(self, *, microgrid_id: int, dispatch_id: int) -> Dispatch:
444448 )
445449 return Dispatch .from_protobuf (response .dispatch )
446450
447- async def delete (self , * , microgrid_id : int , dispatch_id : int ) -> None :
451+ async def delete (
452+ self , * , microgrid_id : MicrogridId , dispatch_id : DispatchId
453+ ) -> None :
448454 """Delete a dispatch.
449455
450456 Args:
451457 microgrid_id: The microgrid_id to delete the dispatch for.
452458 dispatch_id: The dispatch_id to delete.
453459 """
454460 request = DeleteMicrogridDispatchRequest (
455- dispatch_id = dispatch_id , microgrid_id = microgrid_id
461+ dispatch_id = int ( dispatch_id ) , microgrid_id = int ( microgrid_id )
456462 )
457463 await cast (
458464 Awaitable [None ],
0 commit comments