Skip to content

Commit 1e5f079

Browse files
committed
Use the new MicrogridInfo object
The name in the microgrid API will be changed again to `Microgrid` in the near future, so internally we just use `microgrid` instead of `microgrid_info`. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0198a42 commit 1e5f079

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/frequenz/sdk/microgrid/connection_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from abc import ABC, abstractmethod
1313

1414
from frequenz.client.common.microgrid import MicrogridId
15-
from frequenz.client.microgrid import Location, Metadata, MicrogridApiClient
15+
from frequenz.client.microgrid import Location, MicrogridApiClient, MicrogridInfo
1616

1717
from .component_graph import ComponentGraph, _MicrogridComponentGraph
1818

@@ -103,8 +103,8 @@ def __init__(self, server_url: str) -> None:
103103
# So create empty graph here, and update it in `run` method.
104104
self._graph = _MicrogridComponentGraph()
105105

106-
self._metadata: Metadata
107-
"""The metadata of the microgrid."""
106+
self._microgrid: MicrogridInfo
107+
"""The microgrid information."""
108108

109109
@property
110110
def api_client(self) -> MicrogridApiClient:
@@ -118,7 +118,7 @@ def microgrid_id(self) -> MicrogridId | None:
118118
Returns:
119119
the ID of the microgrid if available, None otherwise.
120120
"""
121-
return self._metadata.microgrid_id
121+
return self._microgrid.id
122122

123123
@property
124124
def location(self) -> Location | None:
@@ -127,7 +127,7 @@ def location(self) -> Location | None:
127127
Returns:
128128
the location of the microgrid if available, None otherwise.
129129
"""
130-
return self._metadata.location
130+
return self._microgrid.location
131131

132132
@property
133133
def component_graph(self) -> ComponentGraph:
@@ -155,7 +155,7 @@ async def _update_client(self, server_url: str) -> None:
155155
await self._initialize()
156156

157157
async def _initialize(self) -> None:
158-
self._metadata = await self._client.get_microgrid_info()
158+
self._microgrid = await self._client.get_microgrid_info()
159159
await self._graph.refresh_from_client(self._client)
160160

161161

tests/microgrid/test_microgrid_api.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
ComponentCategory,
1818
Connection,
1919
Location,
20-
Metadata,
20+
MicrogridInfo,
2121
)
2222

2323
from frequenz.sdk.microgrid import connection_manager
2424

25+
_MICROGRID_ID = MicrogridId(1)
26+
2527

2628
class TestMicrogridApi:
2729
"""Test for MicropgridApi."""
@@ -91,17 +93,25 @@ def connections(self) -> list[list[Connection]]:
9193
return connections
9294

9395
@pytest.fixture
94-
def metadata(self) -> Metadata:
95-
"""Fetch the microgrid metadata.
96+
def microgrid(self) -> MicrogridInfo:
97+
"""Fetch the microgrid information.
9698
9799
Returns:
98-
the microgrid metadata.
100+
the information about the microgrid
99101
"""
100-
return Metadata(
101-
microgrid_id=MicrogridId(8),
102+
return MicrogridInfo(
103+
id=_MICROGRID_ID,
104+
enterprise_id=EnterpriseId(1),
105+
name="test",
106+
delivery_area=DeliveryArea(
107+
code="test", code_type=EnergyMarketCodeType.EUROPE_EIC
108+
),
109+
status=MicrogridStatus.ACTIVE,
110+
create_timestamp=datetime.now(tz=timezone.utc),
102111
location=Location(
103112
latitude=52.520008,
104113
longitude=13.404954,
114+
country_code="DE",
105115
),
106116
)
107117

@@ -111,15 +121,15 @@ async def test_connection_manager(
111121
_insecure_channel_mock: MagicMock,
112122
components: list[list[Component]],
113123
connections: list[list[Connection]],
114-
metadata: Metadata,
124+
microgrid: MicrogridInfo,
115125
) -> None:
116126
"""Test microgrid api.
117127
118128
Args:
119129
_insecure_channel_mock: insecure channel mock from `mock.patch`
120130
components: components
121131
connections: connections
122-
metadata: the metadata of the microgrid
132+
microgrid: the information about the microgrid
123133
"""
124134
microgrid_client = MagicMock()
125135
microgrid_client.list_components = AsyncMock(side_effect=components)
@@ -167,8 +177,8 @@ async def test_connection_manager(
167177
assert set(graph.components()) == set(components[0])
168178
assert set(graph.connections()) == set(connections[0])
169179

170-
assert api.microgrid_id == metadata.microgrid_id
171-
assert api.location == metadata.location
180+
assert api.microgrid_id == microgrid.id
181+
assert api.location == microgrid.location
172182

173183
# It should not be possible to initialize method once again
174184
with pytest.raises(AssertionError):
@@ -181,24 +191,24 @@ async def test_connection_manager(
181191
assert set(graph.components()) == set(components[0])
182192
assert set(graph.connections()) == set(connections[0])
183193

184-
assert api.microgrid_id == metadata.microgrid_id
185-
assert api.location == metadata.location
194+
assert api.microgrid_id == microgrid.id
195+
assert api.location == microgrid.location
186196

187197
@mock.patch("grpc.aio.insecure_channel")
188198
async def test_connection_manager_another_method(
189199
self,
190200
_insecure_channel_mock: MagicMock,
191201
components: list[list[Component]],
192202
connections: list[list[Connection]],
193-
metadata: Metadata,
203+
microgrid: MicrogridInfo,
194204
) -> None:
195205
"""Test if the api was not deallocated.
196206
197207
Args:
198208
_insecure_channel_mock: insecure channel mock
199209
components: components
200210
connections: connections
201-
metadata: the metadata of the microgrid
211+
microgrid: the information about the microgrid
202212
"""
203213
microgrid_client = MagicMock()
204214
microgrid_client.components = AsyncMock(return_value=[])
@@ -210,5 +220,5 @@ async def test_connection_manager_another_method(
210220
assert set(graph.components()) == set(components[0])
211221
assert set(graph.connections()) == set(connections[0])
212222

213-
assert api.microgrid_id == metadata.microgrid_id
214-
assert api.location == metadata.location
223+
assert api.microgrid_id == microgrid.id
224+
assert api.location == microgrid.location

0 commit comments

Comments
 (0)