@@ -107,74 +107,6 @@ class PowerDistributingActor(Actor):
107107 overlap (they have at least one common battery), then then both batteries
108108 will be processed. However it is not expected so the proper error log will be
109109 printed.
110-
111- Example:
112- ```python
113- from frequenz.sdk import microgrid
114- from frequenz.sdk.microgrid.component import ComponentCategory
115- from frequenz.sdk.actor import ResamplerConfig
116- from frequenz.sdk.actor.power_distributing import (
117- PowerDistributingActor,
118- Request,
119- Result,
120- Success,
121- Error,
122- PartialFailure,
123- Ignored,
124- )
125- from frequenz.channels import Broadcast, Receiver, Sender
126- from datetime import timedelta
127-
128- HOST = "localhost"
129- PORT = 50051
130-
131- await microgrid.initialize(
132- HOST,
133- PORT,
134- ResamplerConfig(resampling_period=timedelta(seconds=1))
135- )
136-
137- graph = microgrid.connection_manager.get().component_graph
138-
139- batteries = graph.components(component_category={ComponentCategory.BATTERY})
140- batteries_ids = {c.component_id for c in batteries}
141-
142- battery_status_channel = Broadcast[BatteryStatus]("battery-status")
143-
144- channel = Broadcast[Request]("power_distributor")
145- channel_registry = ChannelRegistry(name="power_distributor")
146- async with PowerDistributingActor(
147- requests_receiver=channel.new_receiver(),
148- channel_registry=channel_registry,
149- battery_status_sender=battery_status_channel.new_sender(),
150- ):
151- sender = channel.new_sender()
152- namespace: str = "namespace"
153- # Set power 1200W to given batteries.
154- request = Request(
155- namespace=namespace,
156- power=1200.0,
157- batteries=batteries_ids,
158- request_timeout_sec=10.0
159- )
160- await sender.send(request)
161- result_rx = channel_registry.new_receiver(namespace)
162-
163- # It is recommended to use timeout when waiting for the response!
164- result: Result = await asyncio.wait_for(result_rx.receive(), timeout=10)
165-
166- if isinstance(result, Success):
167- print("Command succeed")
168- elif isinstance(result, PartialFailure):
169- print(
170- f"Batteries {result.failed_batteries} failed, total failed power" \
171- f"{result.failed_power}"
172- )
173- elif isinstance(result, Ignored):
174- print("Request was ignored, because of newer request")
175- elif isinstance(result, Error):
176- print(f"Request failed with error: {result.msg}")
177- ```
178110 """
179111
180112 def __init__ (
0 commit comments