Skip to content

Commit 8d82f90

Browse files
Fetch metadata when connecting to the microgrid
The ConnectionManager retrieves the metadata at initialization when connecting to the microgrid. Signed-off-by: Daniel Zullo <[email protected]>
1 parent bd02b9d commit 8d82f90

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/frequenz/sdk/microgrid/connection_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .client import MicrogridApiClient
1717
from .client._client import MicrogridGrpcClient
1818
from .component_graph import ComponentGraph, _MicrogridComponentGraph
19+
from .metadata import Metadata
1920

2021
# Not public default host and port
2122
_DEFAULT_MICROGRID_HOST = "[::1]"
@@ -103,6 +104,9 @@ def __init__(
103104
# So create empty graph here, and update it in `run` method.
104105
self._graph = _MicrogridComponentGraph()
105106

107+
self._metadata: Metadata
108+
"""The metadata of the microgrid."""
109+
106110
@property
107111
def api_client(self) -> MicrogridApiClient:
108112
"""Get MicrogridApiClient.
@@ -133,9 +137,11 @@ async def _update_api(self, host: str, port: int) -> None:
133137
target = f"{host}:{port}"
134138
grpc_channel = grpcaio.insecure_channel(target)
135139
self._api = MicrogridGrpcClient(grpc_channel, target)
140+
self._metadata = await self._api.metadata()
136141
await self._graph.refresh_from_api(self._api)
137142

138143
async def _initialize(self) -> None:
144+
self._metadata = await self._api.metadata()
139145
await self._graph.refresh_from_api(self._api)
140146

141147

0 commit comments

Comments
 (0)