frequenz-client-microgrid 0.6.0__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/PKG-INFO +42 -3
  2. frequenz_client_microgrid-0.7.0/RELEASE_NOTES.md +14 -0
  3. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/pyproject.toml +24 -21
  4. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/__init__.py +4 -1
  5. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_client.py +34 -25
  6. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_component.py +6 -3
  7. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_component_data.py +6 -5
  8. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_connection.py +5 -3
  9. frequenz_client_microgrid-0.7.0/src/frequenz/client/microgrid/_id.py +107 -0
  10. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_metadata.py +3 -1
  11. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz_client_microgrid.egg-info/PKG-INFO +42 -3
  12. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz_client_microgrid.egg-info/SOURCES.txt +1 -0
  13. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz_client_microgrid.egg-info/requires.txt +19 -19
  14. frequenz-client-microgrid-0.6.0/RELEASE_NOTES.md +0 -17
  15. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/LICENSE +0 -0
  16. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/MANIFEST.in +0 -0
  17. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/README.md +0 -0
  18. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/setup.cfg +0 -0
  19. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_component_error.py +0 -0
  20. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_component_states.py +0 -0
  21. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_constants.py +0 -0
  22. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/_exception.py +0 -0
  23. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/conftest.py +0 -0
  24. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz/client/microgrid/py.typed +0 -0
  25. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz_client_microgrid.egg-info/dependency_links.txt +0 -0
  26. {frequenz-client-microgrid-0.6.0 → frequenz_client_microgrid-0.7.0}/src/frequenz_client_microgrid.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: frequenz-client-microgrid
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Microgrid API client for Python
5
5
  Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
6
6
  License: MIT
@@ -20,15 +20,54 @@ Classifier: Topic :: Software Development :: Libraries
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: <4,>=3.11
22
22
  Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.3
25
+ Requires-Dist: frequenz-channels<2.0.0,>=1.0.0-rc1
26
+ Requires-Dist: frequenz-client-base<0.10.0,>=0.8.0
27
+ Requires-Dist: grpcio<2,>=1.54.2
28
+ Requires-Dist: protobuf<6,>=4.21.6
29
+ Requires-Dist: timezonefinder<7,>=6.2.0
30
+ Requires-Dist: typing-extensions<5,>=4.5.0
23
31
  Provides-Extra: dev-flake8
32
+ Requires-Dist: flake8==7.1.2; extra == "dev-flake8"
33
+ Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
34
+ Requires-Dist: flake8-pyproject==1.2.3; extra == "dev-flake8"
35
+ Requires-Dist: pydoclint==0.6.2; extra == "dev-flake8"
36
+ Requires-Dist: pydocstyle==6.3.0; extra == "dev-flake8"
24
37
  Provides-Extra: dev-formatting
38
+ Requires-Dist: black==25.1.0; extra == "dev-formatting"
39
+ Requires-Dist: isort==6.0.1; extra == "dev-formatting"
25
40
  Provides-Extra: dev-mkdocs
41
+ Requires-Dist: black==25.1.0; extra == "dev-mkdocs"
42
+ Requires-Dist: Markdown==3.7; extra == "dev-mkdocs"
43
+ Requires-Dist: mike==2.1.3; extra == "dev-mkdocs"
44
+ Requires-Dist: mkdocs-gen-files==0.5.0; extra == "dev-mkdocs"
45
+ Requires-Dist: mkdocs-literate-nav==0.6.1; extra == "dev-mkdocs"
46
+ Requires-Dist: mkdocs-macros-plugin==1.3.7; extra == "dev-mkdocs"
47
+ Requires-Dist: mkdocs-material==9.6.7; extra == "dev-mkdocs"
48
+ Requires-Dist: mkdocstrings[python]==0.28.2; extra == "dev-mkdocs"
49
+ Requires-Dist: mkdocstrings-python==1.16.2; extra == "dev-mkdocs"
50
+ Requires-Dist: frequenz-repo-config[lib]==0.12.3; extra == "dev-mkdocs"
26
51
  Provides-Extra: dev-mypy
52
+ Requires-Dist: mypy==1.15.0; extra == "dev-mypy"
53
+ Requires-Dist: grpc-stubs==1.53.0.5; extra == "dev-mypy"
54
+ Requires-Dist: types-Markdown==3.7.0.20241204; extra == "dev-mypy"
55
+ Requires-Dist: types-protobuf==5.29.1.20250208; extra == "dev-mypy"
56
+ Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
27
57
  Provides-Extra: dev-noxfile
58
+ Requires-Dist: nox==2025.2.9; extra == "dev-noxfile"
59
+ Requires-Dist: frequenz-repo-config[lib]==0.12.3; extra == "dev-noxfile"
28
60
  Provides-Extra: dev-pylint
61
+ Requires-Dist: pylint==3.3.4; extra == "dev-pylint"
62
+ Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
29
63
  Provides-Extra: dev-pytest
64
+ Requires-Dist: pytest==8.3.5; extra == "dev-pytest"
65
+ Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.12.3; extra == "dev-pytest"
66
+ Requires-Dist: pytest-mock==3.14.0; extra == "dev-pytest"
67
+ Requires-Dist: pytest-asyncio==0.25.3; extra == "dev-pytest"
68
+ Requires-Dist: async-solipsism==0.7; extra == "dev-pytest"
30
69
  Provides-Extra: dev
31
- License-File: LICENSE
70
+ Requires-Dist: frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
32
71
 
33
72
  # Frequenz Microgrid API Client
34
73
 
@@ -0,0 +1,14 @@
1
+ # Frequenz Microgrid API Client Release Notes
2
+
3
+ ## Upgrading
4
+
5
+ - Now component and microgrid IDs are wrapped in new classes: `ComponentId` and `MicrogridId` respectively.
6
+
7
+ These classes provide type safety and prevent accidental errors by:
8
+
9
+ - Making it impossible to mix up microgrid and component IDs (equality comparisons between different ID types always return false).
10
+ - Preventing accidental math operations on IDs.
11
+ - Providing clear string representations for debugging (MID42, CID42).
12
+ - Ensuring proper hash behavior in collections.
13
+
14
+ To migrate you just need to wrap your `int` IDs with the appropriate class: `0` -> `ComponentId(0)` / `MicrogridId(0)`.
@@ -3,9 +3,9 @@
3
3
 
4
4
  [build-system]
5
5
  requires = [
6
- "setuptools == 68.1.0",
7
- "setuptools_scm[toml] == 7.1.0",
8
- "frequenz-repo-config[lib] == 0.9.1",
6
+ "setuptools == 75.8.2",
7
+ "setuptools_scm[toml] == 8.2.0",
8
+ "frequenz-repo-config[lib] == 0.12.3",
9
9
  ]
10
10
  build-backend = "setuptools.build_meta"
11
11
 
@@ -38,7 +38,7 @@ requires-python = ">= 3.11, < 4"
38
38
  dependencies = [
39
39
  "frequenz-api-microgrid >= 0.15.3, < 0.16.0",
40
40
  "frequenz-channels >= 1.0.0-rc1, < 2.0.0",
41
- "frequenz-client-base >= 0.8.0, < 0.9",
41
+ "frequenz-client-base >= 0.8.0, < 0.10.0",
42
42
  "grpcio >= 1.54.2, < 2",
43
43
  "protobuf >= 4.21.6, < 6",
44
44
  "timezonefinder >= 6.2.0, < 7",
@@ -52,44 +52,44 @@ email = "floss@frequenz.com"
52
52
 
53
53
  [project.optional-dependencies]
54
54
  dev-flake8 = [
55
- "flake8 == 7.1.1",
55
+ "flake8 == 7.1.2",
56
56
  "flake8-docstrings == 1.7.0",
57
- "flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
58
- "pydoclint == 0.5.9",
57
+ "flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
58
+ "pydoclint == 0.6.2",
59
59
  "pydocstyle == 6.3.0",
60
60
  ]
61
- dev-formatting = ["black == 24.10.0", "isort == 5.13.2"]
61
+ dev-formatting = ["black == 25.1.0", "isort == 6.0.1"]
62
62
  dev-mkdocs = [
63
- "black == 24.10.0",
63
+ "black == 25.1.0",
64
64
  "Markdown==3.7",
65
65
  "mike == 2.1.3",
66
66
  "mkdocs-gen-files == 0.5.0",
67
67
  "mkdocs-literate-nav == 0.6.1",
68
68
  "mkdocs-macros-plugin == 1.3.7",
69
- "mkdocs-material == 9.5.43",
70
- "mkdocstrings[python] == 0.26.2",
71
- "mkdocstrings-python == 1.12.2",
72
- "frequenz-repo-config[lib] == 0.10.0",
69
+ "mkdocs-material == 9.6.7",
70
+ "mkdocstrings[python] == 0.28.2",
71
+ "mkdocstrings-python == 1.16.2",
72
+ "frequenz-repo-config[lib] == 0.12.3",
73
73
  ]
74
74
  dev-mypy = [
75
- "mypy == 1.13.0",
75
+ "mypy == 1.15.0",
76
76
  "grpc-stubs == 1.53.0.5",
77
- "types-Markdown == 3.7.0.20240822",
78
- "types-protobuf == 5.28.3.20241030",
77
+ "types-Markdown == 3.7.0.20241204",
78
+ "types-protobuf == 5.29.1.20250208",
79
79
  # For checking the noxfile, docs/ script, and tests
80
80
  "frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]",
81
81
  ]
82
- dev-noxfile = ["nox == 2024.10.9", "frequenz-repo-config[lib] == 0.10.0"]
82
+ dev-noxfile = ["nox == 2025.2.9", "frequenz-repo-config[lib] == 0.12.3"]
83
83
  dev-pylint = [
84
- "pylint == 3.3.1",
84
+ "pylint == 3.3.4",
85
85
  # For checking the noxfile, docs/ script, and tests
86
86
  "frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]",
87
87
  ]
88
88
  dev-pytest = [
89
- "pytest == 8.3.3",
90
- "frequenz-repo-config[extra-lint-examples] == 0.10.0",
89
+ "pytest == 8.3.5",
90
+ "frequenz-repo-config[extra-lint-examples] == 0.12.3",
91
91
  "pytest-mock == 3.14.0",
92
- "pytest-asyncio == 0.24.0",
92
+ "pytest-asyncio == 0.25.3",
93
93
  "async-solipsism == 0.7",
94
94
  ]
95
95
  dev = [
@@ -148,6 +148,7 @@ disable = [
148
148
  "unsubscriptable-object",
149
149
  # Checked by mypy
150
150
  "no-member",
151
+ "possibly-used-before-assignment",
151
152
  "no-name-in-module",
152
153
  # Checked by flake8
153
154
  "f-string-without-interpolation",
@@ -160,8 +161,10 @@ disable = [
160
161
  ]
161
162
 
162
163
  [tool.pytest.ini_options]
164
+ addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
163
165
  testpaths = ["tests", "src"]
164
166
  asyncio_mode = "auto"
167
+ asyncio_default_fixture_loop_scope = "function"
165
168
  required_plugins = ["pytest-asyncio", "pytest-mock"]
166
169
 
167
170
  [tool.mypy]
@@ -62,10 +62,10 @@ from ._exception import (
62
62
  UnknownError,
63
63
  UnrecognizedGrpcStatus,
64
64
  )
65
+ from ._id import ComponentId, MicrogridId
65
66
  from ._metadata import Location, Metadata
66
67
 
67
68
  __all__ = [
68
- "MicrogridApiClient",
69
69
  "ApiClientError",
70
70
  "BatteryComponentState",
71
71
  "BatteryData",
@@ -76,6 +76,7 @@ __all__ = [
76
76
  "Component",
77
77
  "ComponentCategory",
78
78
  "ComponentData",
79
+ "ComponentId",
79
80
  "ComponentMetadata",
80
81
  "ComponentMetricId",
81
82
  "ComponentType",
@@ -100,6 +101,8 @@ __all__ = [
100
101
  "Location",
101
102
  "Metadata",
102
103
  "MeterData",
104
+ "MicrogridApiClient",
105
+ "MicrogridId",
103
106
  "OperationAborted",
104
107
  "OperationCancelled",
105
108
  "OperationNotImplemented",
@@ -34,6 +34,7 @@ from ._component_data import (
34
34
  from ._connection import Connection
35
35
  from ._constants import RECEIVER_MAX_SIZE
36
36
  from ._exception import ApiClientError, ClientNotConnected
37
+ from ._id import ComponentId, MicrogridId
37
38
  from ._metadata import Location, Metadata
38
39
 
39
40
  DEFAULT_GRPC_CALL_TIMEOUT = 60.0
@@ -91,7 +92,9 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
91
92
  connect=connect,
92
93
  channel_defaults=channel_defaults,
93
94
  )
94
- self._broadcasters: dict[int, streaming.GrpcStreamBroadcaster[Any, Any]] = {}
95
+ self._broadcasters: dict[
96
+ ComponentId, streaming.GrpcStreamBroadcaster[Any, Any]
97
+ ] = {}
95
98
  self._retry_strategy = retry_strategy
96
99
 
97
100
  @property
@@ -134,7 +137,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
134
137
  )
135
138
  result: Iterable[Component] = map(
136
139
  lambda c: Component(
137
- c.id,
140
+ ComponentId(c.id),
138
141
  component_category_from_protobuf(c.category),
139
142
  component_type_from_protobuf(c.category, c.inverter),
140
143
  component_metadata_from_protobuf(c.category, c.grid),
@@ -176,12 +179,14 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
176
179
  longitude=microgrid_metadata.location.longitude,
177
180
  )
178
181
 
179
- return Metadata(microgrid_id=microgrid_metadata.microgrid_id, location=location)
182
+ return Metadata(
183
+ microgrid_id=MicrogridId(microgrid_metadata.microgrid_id), location=location
184
+ )
180
185
 
181
186
  async def connections( # noqa: DOC502 (raises ApiClientError indirectly)
182
187
  self,
183
- starts: Set[int] = frozenset(),
184
- ends: Set[int] = frozenset(),
188
+ starts: Set[ComponentId] = frozenset(),
189
+ ends: Set[ComponentId] = frozenset(),
185
190
  ) -> Iterable[Connection]:
186
191
  """Fetch the connections between components in the microgrid.
187
192
 
@@ -199,7 +204,13 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
199
204
  most likely a subclass of
200
205
  [GrpcError][frequenz.client.microgrid.GrpcError].
201
206
  """
202
- connection_filter = microgrid_pb2.ConnectionFilter(starts=starts, ends=ends)
207
+ # Convert ComponentId to raw int for the API call
208
+ start_ids = {int(start) for start in starts}
209
+ end_ids = {int(end) for end in ends}
210
+
211
+ connection_filter = microgrid_pb2.ConnectionFilter(
212
+ starts=start_ids, ends=end_ids
213
+ )
203
214
  valid_components, all_connections = await asyncio.gather(
204
215
  self.components(),
205
216
  client.call_stub_method(
@@ -214,7 +225,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
214
225
 
215
226
  # Filter out the components filtered in `components` method.
216
227
  # id=0 is an exception indicating grid component.
217
- valid_ids = {c.component_id for c in valid_components}
228
+ valid_ids = {int(c.component_id) for c in valid_components}
218
229
  valid_ids.add(0)
219
230
 
220
231
  connections = filter(
@@ -223,7 +234,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
223
234
  )
224
235
 
225
236
  result: Iterable[Connection] = map(
226
- lambda c: Connection(c.start, c.end), connections
237
+ lambda c: Connection(ComponentId(c.start), ComponentId(c.end)), connections
227
238
  )
228
239
 
229
240
  return result
@@ -231,7 +242,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
231
242
  async def _new_component_data_receiver(
232
243
  self,
233
244
  *,
234
- component_id: int,
245
+ component_id: ComponentId,
235
246
  expected_category: ComponentCategory,
236
247
  transform: Callable[[microgrid_pb2.ComponentData], _ComponentDataT],
237
248
  maxsize: int,
@@ -262,7 +273,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
262
273
  f"raw-component-data-{component_id}",
263
274
  lambda: aiter(
264
275
  self.stub.StreamComponentData(
265
- microgrid_pb2.ComponentIdParam(id=component_id)
276
+ microgrid_pb2.ComponentIdParam(id=int(component_id))
266
277
  )
267
278
  ),
268
279
  transform,
@@ -276,7 +287,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
276
287
 
277
288
  async def _expect_category(
278
289
  self,
279
- component_id: int,
290
+ component_id: ComponentId,
280
291
  expected_category: ComponentCategory,
281
292
  ) -> None:
282
293
  """Check if the given component_id is of the expected type.
@@ -296,19 +307,17 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
296
307
  if comp.component_id == component_id
297
308
  )
298
309
  except StopIteration as exc:
299
- raise ValueError(
300
- f"Unable to find component with id {component_id}"
301
- ) from exc
310
+ raise ValueError(f"Unable to find {component_id}") from exc
302
311
 
303
312
  if comp.category != expected_category:
304
313
  raise ValueError(
305
- f"Component id {component_id} is a {comp.category.name.lower()}"
314
+ f"{component_id} is a {comp.category.name.lower()}"
306
315
  f", not a {expected_category.name.lower()}."
307
316
  )
308
317
 
309
318
  async def meter_data( # noqa: DOC502 (ValueError is raised indirectly by _expect_category)
310
319
  self,
311
- component_id: int,
320
+ component_id: ComponentId,
312
321
  maxsize: int = RECEIVER_MAX_SIZE,
313
322
  ) -> Receiver[MeterData]:
314
323
  """Return a channel receiver that provides a `MeterData` stream.
@@ -332,7 +341,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
332
341
 
333
342
  async def battery_data( # noqa: DOC502 (ValueError is raised indirectly by _expect_category)
334
343
  self,
335
- component_id: int,
344
+ component_id: ComponentId,
336
345
  maxsize: int = RECEIVER_MAX_SIZE,
337
346
  ) -> Receiver[BatteryData]:
338
347
  """Return a channel receiver that provides a `BatteryData` stream.
@@ -356,7 +365,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
356
365
 
357
366
  async def inverter_data( # noqa: DOC502 (ValueError is raised indirectly by _expect_category)
358
367
  self,
359
- component_id: int,
368
+ component_id: ComponentId,
360
369
  maxsize: int = RECEIVER_MAX_SIZE,
361
370
  ) -> Receiver[InverterData]:
362
371
  """Return a channel receiver that provides an `InverterData` stream.
@@ -380,7 +389,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
380
389
 
381
390
  async def ev_charger_data( # noqa: DOC502 (ValueError is raised indirectly by _expect_category)
382
391
  self,
383
- component_id: int,
392
+ component_id: ComponentId,
384
393
  maxsize: int = RECEIVER_MAX_SIZE,
385
394
  ) -> Receiver[EVChargerData]:
386
395
  """Return a channel receiver that provides an `EvChargeData` stream.
@@ -403,7 +412,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
403
412
  )
404
413
 
405
414
  async def set_power( # noqa: DOC502 (raises ApiClientError indirectly)
406
- self, component_id: int, power_w: float
415
+ self, component_id: ComponentId, power_w: float
407
416
  ) -> None:
408
417
  """Send request to the Microgrid to set power for component.
409
418
 
@@ -425,7 +434,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
425
434
  self,
426
435
  lambda: self.stub.SetPowerActive(
427
436
  microgrid_pb2.SetPowerActiveParam(
428
- component_id=component_id, power=power_w
437
+ component_id=int(component_id), power=power_w
429
438
  ),
430
439
  timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
431
440
  ),
@@ -433,7 +442,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
433
442
  )
434
443
 
435
444
  async def set_reactive_power( # noqa: DOC502 (raises ApiClientError indirectly)
436
- self, component_id: int, reactive_power_var: float
445
+ self, component_id: ComponentId, reactive_power_var: float
437
446
  ) -> None:
438
447
  """Send request to the Microgrid to set reactive power for component.
439
448
 
@@ -453,7 +462,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
453
462
  self,
454
463
  lambda: self.stub.SetPowerReactive(
455
464
  microgrid_pb2.SetPowerReactiveParam(
456
- component_id=component_id, power=reactive_power_var
465
+ component_id=int(component_id), power=reactive_power_var
457
466
  ),
458
467
  timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
459
468
  ),
@@ -462,7 +471,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
462
471
 
463
472
  async def set_bounds( # noqa: DOC503 (raises ApiClientError indirectly)
464
473
  self,
465
- component_id: int,
474
+ component_id: ComponentId,
466
475
  lower: float,
467
476
  upper: float,
468
477
  ) -> None:
@@ -492,7 +501,7 @@ class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub])
492
501
  self,
493
502
  lambda: self.stub.AddInclusionBounds(
494
503
  microgrid_pb2.SetBoundsParam(
495
- component_id=component_id,
504
+ component_id=int(component_id),
496
505
  target_metric=target_metric,
497
506
  bounds=metrics_pb2.Bounds(lower=lower, upper=upper),
498
507
  ),
@@ -9,6 +9,8 @@ from enum import Enum
9
9
  from frequenz.api.common import components_pb2
10
10
  from frequenz.api.microgrid import grid_pb2, inverter_pb2
11
11
 
12
+ from ._id import ComponentId
13
+
12
14
 
13
15
  class ComponentType(Enum):
14
16
  """A base class from which individual component types are derived."""
@@ -160,7 +162,7 @@ def component_metadata_from_protobuf(
160
162
  class Component:
161
163
  """Metadata for a single microgrid component."""
162
164
 
163
- component_id: int
165
+ component_id: ComponentId
164
166
  """The ID of this component."""
165
167
 
166
168
  category: ComponentCategory
@@ -180,8 +182,9 @@ class Component:
180
182
  == 0` and `type` is `GRID`, `False` otherwise
181
183
  """
182
184
  return (
183
- self.component_id > 0 and any(t == self.category for t in ComponentCategory)
184
- ) or (self.component_id == 0 and self.category == ComponentCategory.GRID)
185
+ int(self.component_id) > 0
186
+ and any(t == self.category for t in ComponentCategory)
187
+ ) or (int(self.component_id) == 0 and self.category == ComponentCategory.GRID)
185
188
 
186
189
  def __hash__(self) -> int:
187
190
  """Compute a hash of this instance, obtained by hashing the `component_id` field.
@@ -18,13 +18,14 @@ from ._component_states import (
18
18
  EVChargerComponentState,
19
19
  InverterComponentState,
20
20
  )
21
+ from ._id import ComponentId
21
22
 
22
23
 
23
24
  @dataclass(frozen=True)
24
25
  class ComponentData(ABC):
25
26
  """A private base class for strongly typed component data classes."""
26
27
 
27
- component_id: int
28
+ component_id: ComponentId
28
29
  """The ID identifying this component in the microgrid."""
29
30
 
30
31
  timestamp: datetime
@@ -129,7 +130,7 @@ class MeterData(ComponentData):
129
130
  Instance of MeterData created from the protobuf message.
130
131
  """
131
132
  meter_data = cls(
132
- component_id=raw.id,
133
+ component_id=ComponentId(raw.id),
133
134
  timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
134
135
  active_power=raw.meter.data.ac.power_active.value,
135
136
  active_power_per_phase=(
@@ -247,7 +248,7 @@ class BatteryData(ComponentData): # pylint: disable=too-many-instance-attribute
247
248
  """
248
249
  raw_power = raw.battery.data.dc.power
249
250
  battery_data = cls(
250
- component_id=raw.id,
251
+ component_id=ComponentId(raw.id),
251
252
  timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
252
253
  soc=raw.battery.data.soc.avg,
253
254
  soc_lower_bound=raw.battery.data.soc.system_inclusion_bounds.lower,
@@ -385,7 +386,7 @@ class InverterData(ComponentData): # pylint: disable=too-many-instance-attribut
385
386
  """
386
387
  raw_power = raw.inverter.data.ac.power_active
387
388
  inverter_data = cls(
388
- component_id=raw.id,
389
+ component_id=ComponentId(raw.id),
389
390
  timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
390
391
  active_power=raw.inverter.data.ac.power_active.value,
391
392
  active_power_per_phase=(
@@ -541,7 +542,7 @@ class EVChargerData(ComponentData): # pylint: disable=too-many-instance-attribu
541
542
  """
542
543
  raw_power = raw.ev_charger.data.ac.power_active
543
544
  ev_charger_data = cls(
544
- component_id=raw.id,
545
+ component_id=ComponentId(raw.id),
545
546
  timestamp=raw.ts.ToDatetime(tzinfo=timezone.utc),
546
547
  active_power=raw_power.value,
547
548
  active_power_per_phase=(
@@ -6,15 +6,17 @@
6
6
 
7
7
  from dataclasses import dataclass
8
8
 
9
+ from ._id import ComponentId
10
+
9
11
 
10
12
  @dataclass(frozen=True)
11
13
  class Connection:
12
14
  """Metadata for a connection between microgrid components."""
13
15
 
14
- start: int
16
+ start: ComponentId
15
17
  """The component ID that represents the start component of the connection."""
16
18
 
17
- end: int
19
+ end: ComponentId
18
20
  """The component ID that represents the end component of the connection."""
19
21
 
20
22
  def is_valid(self) -> bool:
@@ -24,4 +26,4 @@ class Connection:
24
26
  `True` if `start >= 0`, `end > 0`, and `start != end`, `False`
25
27
  otherwise.
26
28
  """
27
- return self.start >= 0 and self.end > 0 and self.start != self.end
29
+ return int(self.start) >= 0 and int(self.end) > 0 and self.start != self.end
@@ -0,0 +1,107 @@
1
+ # License: MIT
2
+ # Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Strongly typed IDs for microgrids and components."""
5
+
6
+
7
+ from typing import final
8
+
9
+
10
+ @final
11
+ class MicrogridId:
12
+ """A unique identifier for a microgrid."""
13
+
14
+ def __init__(self, id_: int, /) -> None:
15
+ """Initialize this instance.
16
+
17
+ Args:
18
+ id_: The numeric unique identifier of the microgrid.
19
+
20
+ Raises:
21
+ ValueError: If the ID is negative.
22
+ """
23
+ if id_ < 0:
24
+ raise ValueError("Microgrid ID can't be negative.")
25
+ self._id = id_
26
+
27
+ def __int__(self) -> int:
28
+ """Return the numeric ID of this instance."""
29
+ return self._id
30
+
31
+ def __eq__(self, other: object) -> bool:
32
+ """Check if this instance is equal to another object."""
33
+ # This is not an unidiomatic typecheck, that's an odd name for the check.
34
+ # isinstance() returns True for subclasses, which is not what we want here.
35
+ # pylint: disable-next=unidiomatic-typecheck
36
+ return type(other) is MicrogridId and self._id == other._id
37
+
38
+ def __lt__(self, other: object) -> bool:
39
+ """Check if this instance is less than another object."""
40
+ # pylint: disable-next=unidiomatic-typecheck
41
+ if type(other) is MicrogridId:
42
+ return self._id < other._id
43
+ return NotImplemented
44
+
45
+ def __hash__(self) -> int:
46
+ """Return the hash of this instance."""
47
+ # We include the class because we explicitly want to avoid the same ID to give
48
+ # the same hash for different classes of IDs
49
+ return hash((MicrogridId, self._id))
50
+
51
+ def __repr__(self) -> str:
52
+ """Return the string representation of this instance."""
53
+ return f"{type(self).__name__}({self._id!r})"
54
+
55
+ def __str__(self) -> str:
56
+ """Return the short string representation of this instance."""
57
+ return f"MID{self._id}"
58
+
59
+
60
+ @final
61
+ class ComponentId:
62
+ """A unique identifier for a microgrid component."""
63
+
64
+ def __init__(self, id_: int, /) -> None:
65
+ """Initialize this instance.
66
+
67
+ Args:
68
+ id_: The numeric unique identifier of the microgrid component.
69
+
70
+ Raises:
71
+ ValueError: If the ID is negative.
72
+ """
73
+ if id_ < 0:
74
+ raise ValueError("Component ID can't be negative.")
75
+ self._id = id_
76
+
77
+ def __int__(self) -> int:
78
+ """Return the numeric ID of this instance."""
79
+ return self._id
80
+
81
+ def __eq__(self, other: object) -> bool:
82
+ """Check if this instance is equal to another object."""
83
+ # This is not an unidiomatic typecheck, that's an odd name for the check.
84
+ # isinstance() returns True for subclasses, which is not what we want here.
85
+ # pylint: disable-next=unidiomatic-typecheck
86
+ return type(other) is ComponentId and self._id == other._id
87
+
88
+ def __lt__(self, other: object) -> bool:
89
+ """Check if this instance is less than another object."""
90
+ # pylint: disable-next=unidiomatic-typecheck
91
+ if type(other) is ComponentId:
92
+ return self._id < other._id
93
+ return NotImplemented
94
+
95
+ def __hash__(self) -> int:
96
+ """Return the hash of this instance."""
97
+ # We include the class because we explicitly want to avoid the same ID to give
98
+ # the same hash for different classes of IDs
99
+ return hash((ComponentId, self._id))
100
+
101
+ def __repr__(self) -> str:
102
+ """Return the string representation of this instance."""
103
+ return f"{type(self).__name__}({self._id!r})"
104
+
105
+ def __str__(self) -> str:
106
+ """Return the short string representation of this instance."""
107
+ return f"CID{self._id}"
@@ -8,6 +8,8 @@ from zoneinfo import ZoneInfo
8
8
 
9
9
  from timezonefinder import TimezoneFinder
10
10
 
11
+ from ._id import MicrogridId
12
+
11
13
  _timezone_finder = TimezoneFinder()
12
14
 
13
15
 
@@ -45,7 +47,7 @@ class Location:
45
47
  class Metadata:
46
48
  """Metadata for the microgrid."""
47
49
 
48
- microgrid_id: int | None = None
50
+ microgrid_id: MicrogridId | None = None
49
51
  """The ID of the microgrid."""
50
52
 
51
53
  location: Location | None = None
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: frequenz-client-microgrid
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Microgrid API client for Python
5
5
  Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
6
6
  License: MIT
@@ -20,15 +20,54 @@ Classifier: Topic :: Software Development :: Libraries
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: <4,>=3.11
22
22
  Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.3
25
+ Requires-Dist: frequenz-channels<2.0.0,>=1.0.0-rc1
26
+ Requires-Dist: frequenz-client-base<0.10.0,>=0.8.0
27
+ Requires-Dist: grpcio<2,>=1.54.2
28
+ Requires-Dist: protobuf<6,>=4.21.6
29
+ Requires-Dist: timezonefinder<7,>=6.2.0
30
+ Requires-Dist: typing-extensions<5,>=4.5.0
23
31
  Provides-Extra: dev-flake8
32
+ Requires-Dist: flake8==7.1.2; extra == "dev-flake8"
33
+ Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
34
+ Requires-Dist: flake8-pyproject==1.2.3; extra == "dev-flake8"
35
+ Requires-Dist: pydoclint==0.6.2; extra == "dev-flake8"
36
+ Requires-Dist: pydocstyle==6.3.0; extra == "dev-flake8"
24
37
  Provides-Extra: dev-formatting
38
+ Requires-Dist: black==25.1.0; extra == "dev-formatting"
39
+ Requires-Dist: isort==6.0.1; extra == "dev-formatting"
25
40
  Provides-Extra: dev-mkdocs
41
+ Requires-Dist: black==25.1.0; extra == "dev-mkdocs"
42
+ Requires-Dist: Markdown==3.7; extra == "dev-mkdocs"
43
+ Requires-Dist: mike==2.1.3; extra == "dev-mkdocs"
44
+ Requires-Dist: mkdocs-gen-files==0.5.0; extra == "dev-mkdocs"
45
+ Requires-Dist: mkdocs-literate-nav==0.6.1; extra == "dev-mkdocs"
46
+ Requires-Dist: mkdocs-macros-plugin==1.3.7; extra == "dev-mkdocs"
47
+ Requires-Dist: mkdocs-material==9.6.7; extra == "dev-mkdocs"
48
+ Requires-Dist: mkdocstrings[python]==0.28.2; extra == "dev-mkdocs"
49
+ Requires-Dist: mkdocstrings-python==1.16.2; extra == "dev-mkdocs"
50
+ Requires-Dist: frequenz-repo-config[lib]==0.12.3; extra == "dev-mkdocs"
26
51
  Provides-Extra: dev-mypy
52
+ Requires-Dist: mypy==1.15.0; extra == "dev-mypy"
53
+ Requires-Dist: grpc-stubs==1.53.0.5; extra == "dev-mypy"
54
+ Requires-Dist: types-Markdown==3.7.0.20241204; extra == "dev-mypy"
55
+ Requires-Dist: types-protobuf==5.29.1.20250208; extra == "dev-mypy"
56
+ Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
27
57
  Provides-Extra: dev-noxfile
58
+ Requires-Dist: nox==2025.2.9; extra == "dev-noxfile"
59
+ Requires-Dist: frequenz-repo-config[lib]==0.12.3; extra == "dev-noxfile"
28
60
  Provides-Extra: dev-pylint
61
+ Requires-Dist: pylint==3.3.4; extra == "dev-pylint"
62
+ Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
29
63
  Provides-Extra: dev-pytest
64
+ Requires-Dist: pytest==8.3.5; extra == "dev-pytest"
65
+ Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.12.3; extra == "dev-pytest"
66
+ Requires-Dist: pytest-mock==3.14.0; extra == "dev-pytest"
67
+ Requires-Dist: pytest-asyncio==0.25.3; extra == "dev-pytest"
68
+ Requires-Dist: async-solipsism==0.7; extra == "dev-pytest"
30
69
  Provides-Extra: dev
31
- License-File: LICENSE
70
+ Requires-Dist: frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
32
71
 
33
72
  # Frequenz Microgrid API Client
34
73
 
@@ -12,6 +12,7 @@ src/frequenz/client/microgrid/_component_states.py
12
12
  src/frequenz/client/microgrid/_connection.py
13
13
  src/frequenz/client/microgrid/_constants.py
14
14
  src/frequenz/client/microgrid/_exception.py
15
+ src/frequenz/client/microgrid/_id.py
15
16
  src/frequenz/client/microgrid/_metadata.py
16
17
  src/frequenz/client/microgrid/conftest.py
17
18
  src/frequenz/client/microgrid/py.typed
@@ -1,6 +1,6 @@
1
1
  frequenz-api-microgrid<0.16.0,>=0.15.3
2
2
  frequenz-channels<2.0.0,>=1.0.0-rc1
3
- frequenz-client-base<0.9,>=0.8.0
3
+ frequenz-client-base<0.10.0,>=0.8.0
4
4
  grpcio<2,>=1.54.2
5
5
  protobuf<6,>=4.21.6
6
6
  timezonefinder<7,>=6.2.0
@@ -10,46 +10,46 @@ typing-extensions<5,>=4.5.0
10
10
  frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]
11
11
 
12
12
  [dev-flake8]
13
- flake8==7.1.1
13
+ flake8==7.1.2
14
14
  flake8-docstrings==1.7.0
15
15
  flake8-pyproject==1.2.3
16
- pydoclint==0.5.9
16
+ pydoclint==0.6.2
17
17
  pydocstyle==6.3.0
18
18
 
19
19
  [dev-formatting]
20
- black==24.10.0
21
- isort==5.13.2
20
+ black==25.1.0
21
+ isort==6.0.1
22
22
 
23
23
  [dev-mkdocs]
24
- black==24.10.0
24
+ black==25.1.0
25
25
  Markdown==3.7
26
26
  mike==2.1.3
27
27
  mkdocs-gen-files==0.5.0
28
28
  mkdocs-literate-nav==0.6.1
29
29
  mkdocs-macros-plugin==1.3.7
30
- mkdocs-material==9.5.43
31
- mkdocstrings[python]==0.26.2
32
- mkdocstrings-python==1.12.2
33
- frequenz-repo-config[lib]==0.10.0
30
+ mkdocs-material==9.6.7
31
+ mkdocstrings[python]==0.28.2
32
+ mkdocstrings-python==1.16.2
33
+ frequenz-repo-config[lib]==0.12.3
34
34
 
35
35
  [dev-mypy]
36
- mypy==1.13.0
36
+ mypy==1.15.0
37
37
  grpc-stubs==1.53.0.5
38
- types-Markdown==3.7.0.20240822
39
- types-protobuf==5.28.3.20241030
38
+ types-Markdown==3.7.0.20241204
39
+ types-protobuf==5.29.1.20250208
40
40
  frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]
41
41
 
42
42
  [dev-noxfile]
43
- nox==2024.10.9
44
- frequenz-repo-config[lib]==0.10.0
43
+ nox==2025.2.9
44
+ frequenz-repo-config[lib]==0.12.3
45
45
 
46
46
  [dev-pylint]
47
- pylint==3.3.1
47
+ pylint==3.3.4
48
48
  frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]
49
49
 
50
50
  [dev-pytest]
51
- pytest==8.3.3
52
- frequenz-repo-config[extra-lint-examples]==0.10.0
51
+ pytest==8.3.5
52
+ frequenz-repo-config[extra-lint-examples]==0.12.3
53
53
  pytest-mock==3.14.0
54
- pytest-asyncio==0.24.0
54
+ pytest-asyncio==0.25.3
55
55
  async-solipsism==0.7
@@ -1,17 +0,0 @@
1
- # Frequenz Microgrid API Client Release Notes
2
-
3
- ## Upgrading
4
-
5
- - `ApiClient`:
6
-
7
- * The class was renamed to `MicrogridApiClient`.
8
- * The `api` attribute was renamed to `stub`.
9
- * The constructor parameter `channel_options` was renamed to `channels_defaults` to match the name used in `BaseApiClient`.
10
- * The constructor now accepts a `connect` parameter, which is `True` by default. If set to `False`, the client will not connect to the server upon instantiation. You can connect later by calling the `connect()` method.
11
-
12
- * The `frequenz-client-base` dependency was bumped to v0.8.0.
13
-
14
- ## New Features
15
-
16
- - The client now inherits from `frequenz.client.base.BaseApiClient`, so it provides a few new features, like `disconnect()`ing or using it as a context manager. Please refer to the [`BaseApiClient` documentation](https://frequenz-floss.github.io/frequenz-client-base-python/latest/reference/frequenz/client/base/client/#frequenz.client.base.client.BaseApiClient) for more information on these features.
17
- - The client now supports setting reactive power for components through the new `set_reactive_power` method.