frequenz-client-microgrid 0.5.2__tar.gz → 0.6.1__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.
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/PKG-INFO +42 -3
- frequenz_client_microgrid-0.6.1/RELEASE_NOTES.md +5 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/pyproject.toml +24 -21
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/__init__.py +2 -2
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_client.py +95 -116
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz_client_microgrid.egg-info/PKG-INFO +42 -3
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz_client_microgrid.egg-info/requires.txt +19 -19
- frequenz-client-microgrid-0.5.2/RELEASE_NOTES.md +0 -5
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/LICENSE +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/MANIFEST.in +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/README.md +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/setup.cfg +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_component.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_component_data.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_component_error.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_component_states.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_connection.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_constants.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_exception.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/_metadata.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/conftest.py +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz/client/microgrid/py.typed +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz_client_microgrid.egg-info/SOURCES.txt +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz_client_microgrid.egg-info/dependency_links.txt +0 -0
- {frequenz-client-microgrid-0.5.2 → frequenz_client_microgrid-0.6.1}/src/frequenz_client_microgrid.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: frequenz-client-microgrid
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.1
|
|
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.1; 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.0; 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.0; 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.2; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==0.28.0; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==1.14.6; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.12.2; extra == "dev-mkdocs"
|
|
26
51
|
Provides-Extra: dev-mypy
|
|
52
|
+
Requires-Dist: mypy==1.14.1; 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.20241207; 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==2024.10.9; extra == "dev-noxfile"
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.12.2; 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.4; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.12.2; 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
|
-
|
|
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
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
[build-system]
|
|
5
5
|
requires = [
|
|
6
|
-
"setuptools ==
|
|
7
|
-
"setuptools_scm[toml] ==
|
|
8
|
-
"frequenz-repo-config[lib] == 0.
|
|
6
|
+
"setuptools == 75.8.0",
|
|
7
|
+
"setuptools_scm[toml] == 8.1.0",
|
|
8
|
+
"frequenz-repo-config[lib] == 0.12.2",
|
|
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.
|
|
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",
|
|
@@ -54,42 +54,42 @@ email = "floss@frequenz.com"
|
|
|
54
54
|
dev-flake8 = [
|
|
55
55
|
"flake8 == 7.1.1",
|
|
56
56
|
"flake8-docstrings == 1.7.0",
|
|
57
|
-
"flake8-pyproject == 1.2.3",
|
|
58
|
-
"pydoclint == 0.
|
|
57
|
+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
|
|
58
|
+
"pydoclint == 0.6.0",
|
|
59
59
|
"pydocstyle == 6.3.0",
|
|
60
60
|
]
|
|
61
|
-
dev-formatting = ["black ==
|
|
61
|
+
dev-formatting = ["black == 25.1.0", "isort == 6.0.0"]
|
|
62
62
|
dev-mkdocs = [
|
|
63
|
-
"black ==
|
|
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
|
-
"mkdocs-macros-plugin == 1.
|
|
69
|
-
"mkdocs-material == 9.
|
|
70
|
-
"mkdocstrings[python] == 0.
|
|
71
|
-
"mkdocstrings-python == 1.
|
|
72
|
-
"frequenz-repo-config[lib] == 0.
|
|
68
|
+
"mkdocs-macros-plugin == 1.3.7",
|
|
69
|
+
"mkdocs-material == 9.6.2",
|
|
70
|
+
"mkdocstrings[python] == 0.28.0",
|
|
71
|
+
"mkdocstrings-python == 1.14.6",
|
|
72
|
+
"frequenz-repo-config[lib] == 0.12.2",
|
|
73
73
|
]
|
|
74
74
|
dev-mypy = [
|
|
75
|
-
"mypy == 1.
|
|
75
|
+
"mypy == 1.14.1",
|
|
76
76
|
"grpc-stubs == 1.53.0.5",
|
|
77
|
-
"types-Markdown == 3.7.0.
|
|
78
|
-
"types-protobuf == 5.
|
|
77
|
+
"types-Markdown == 3.7.0.20241204",
|
|
78
|
+
"types-protobuf == 5.29.1.20241207",
|
|
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.
|
|
82
|
+
dev-noxfile = ["nox == 2024.10.9", "frequenz-repo-config[lib] == 0.12.2"]
|
|
83
83
|
dev-pylint = [
|
|
84
|
-
"pylint == 3.
|
|
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.
|
|
90
|
-
"frequenz-repo-config[extra-lint-examples] == 0.
|
|
89
|
+
"pytest == 8.3.4",
|
|
90
|
+
"frequenz-repo-config[extra-lint-examples] == 0.12.2",
|
|
91
91
|
"pytest-mock == 3.14.0",
|
|
92
|
-
"pytest-asyncio == 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]
|
|
@@ -7,7 +7,7 @@ This package provides a low-level interface for interacting with the microgrid A
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
from ._client import
|
|
10
|
+
from ._client import MicrogridApiClient
|
|
11
11
|
from ._component import (
|
|
12
12
|
Component,
|
|
13
13
|
ComponentCategory,
|
|
@@ -65,7 +65,7 @@ from ._exception import (
|
|
|
65
65
|
from ._metadata import Location, Metadata
|
|
66
66
|
|
|
67
67
|
__all__ = [
|
|
68
|
-
"
|
|
68
|
+
"MicrogridApiClient",
|
|
69
69
|
"ApiClientError",
|
|
70
70
|
"BatteryComponentState",
|
|
71
71
|
"BatteryData",
|
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
"""Client for requests to the Microgrid API."""
|
|
5
5
|
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
6
8
|
import asyncio
|
|
7
9
|
import logging
|
|
8
|
-
from collections.abc import
|
|
10
|
+
from collections.abc import Callable, Iterable, Set
|
|
9
11
|
from dataclasses import replace
|
|
10
|
-
from typing import Any, TypeVar
|
|
12
|
+
from typing import Any, TypeVar
|
|
11
13
|
|
|
12
|
-
import grpc.aio
|
|
13
14
|
from frequenz.api.common import components_pb2, metrics_pb2
|
|
14
15
|
from frequenz.api.microgrid import microgrid_pb2, microgrid_pb2_grpc
|
|
15
16
|
from frequenz.channels import Receiver
|
|
16
|
-
from frequenz.client.base import channel, retry, streaming
|
|
17
|
+
from frequenz.client.base import channel, client, retry, streaming
|
|
17
18
|
from google.protobuf.empty_pb2 import Empty
|
|
18
|
-
from google.protobuf.timestamp_pb2 import Timestamp
|
|
19
19
|
|
|
20
20
|
from ._component import (
|
|
21
21
|
Component,
|
|
@@ -33,7 +33,7 @@ from ._component_data import (
|
|
|
33
33
|
)
|
|
34
34
|
from ._connection import Connection
|
|
35
35
|
from ._constants import RECEIVER_MAX_SIZE
|
|
36
|
-
from ._exception import ApiClientError
|
|
36
|
+
from ._exception import ApiClientError, ClientNotConnected
|
|
37
37
|
from ._metadata import Location, Metadata
|
|
38
38
|
|
|
39
39
|
DEFAULT_GRPC_CALL_TIMEOUT = 60.0
|
|
@@ -55,14 +55,15 @@ microgrid API does not use SSL by default.
|
|
|
55
55
|
"""
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
class
|
|
58
|
+
class MicrogridApiClient(client.BaseApiClient[microgrid_pb2_grpc.MicrogridStub]):
|
|
59
59
|
"""A microgrid API client."""
|
|
60
60
|
|
|
61
61
|
def __init__(
|
|
62
62
|
self,
|
|
63
63
|
server_url: str,
|
|
64
64
|
*,
|
|
65
|
-
|
|
65
|
+
channel_defaults: channel.ChannelOptions = DEFAULT_CHANNEL_OPTIONS,
|
|
66
|
+
connect: bool = True,
|
|
66
67
|
retry_strategy: retry.Strategy | None = None,
|
|
67
68
|
) -> None:
|
|
68
69
|
"""Initialize the class instance.
|
|
@@ -74,29 +75,39 @@ class ApiClient:
|
|
|
74
75
|
where the `port` should be an int between 0 and 65535 (defaulting to
|
|
75
76
|
9090) and `ssl` should be a boolean (defaulting to `false`).
|
|
76
77
|
For example: `grpc://localhost:1090?ssl=true`.
|
|
77
|
-
|
|
78
|
+
channel_defaults: The default options use to create the channel when not
|
|
78
79
|
specified in the URL.
|
|
80
|
+
connect: Whether to connect to the server as soon as a client instance is
|
|
81
|
+
created. If `False`, the client will not connect to the server until
|
|
82
|
+
[connect()][frequenz.client.base.client.BaseApiClient.connect] is
|
|
83
|
+
called.
|
|
79
84
|
retry_strategy: The retry strategy to use to reconnect when the connection
|
|
80
85
|
to the streaming method is lost. By default a linear backoff strategy
|
|
81
86
|
is used.
|
|
82
87
|
"""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
super().__init__(
|
|
89
|
+
server_url,
|
|
90
|
+
microgrid_pb2_grpc.MicrogridStub,
|
|
91
|
+
connect=connect,
|
|
92
|
+
channel_defaults=channel_defaults,
|
|
88
93
|
)
|
|
89
|
-
"""The gRPC stub for the microgrid API."""
|
|
90
|
-
|
|
91
94
|
self._broadcasters: dict[int, streaming.GrpcStreamBroadcaster[Any, Any]] = {}
|
|
92
95
|
self._retry_strategy = retry_strategy
|
|
93
96
|
|
|
94
97
|
@property
|
|
95
|
-
def
|
|
96
|
-
"""The
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
def stub(self) -> microgrid_pb2_grpc.MicrogridAsyncStub:
|
|
99
|
+
"""The gRPC stub for the API."""
|
|
100
|
+
if self.channel is None or self._stub is None:
|
|
101
|
+
raise ClientNotConnected(server_url=self.server_url, operation="stub")
|
|
102
|
+
# This type: ignore is needed because we need to cast the sync stub to
|
|
103
|
+
# the async stub, but we can't use cast because the async stub doesn't
|
|
104
|
+
# actually exists to the eyes of the interpreter, it only exists for the
|
|
105
|
+
# type-checker, so it can only be used for type hints.
|
|
106
|
+
return self._stub # type: ignore
|
|
107
|
+
|
|
108
|
+
async def components( # noqa: DOC502 (raises ApiClientError indirectly)
|
|
109
|
+
self,
|
|
110
|
+
) -> Iterable[Component]:
|
|
100
111
|
"""Fetch all the components present in the microgrid.
|
|
101
112
|
|
|
102
113
|
Returns:
|
|
@@ -107,22 +118,14 @@ class ApiClient:
|
|
|
107
118
|
most likely a subclass of
|
|
108
119
|
[GrpcError][frequenz.client.microgrid.GrpcError].
|
|
109
120
|
"""
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
),
|
|
119
|
-
)
|
|
120
|
-
except grpc.aio.AioRpcError as grpc_error:
|
|
121
|
-
raise ApiClientError.from_grpc_error(
|
|
122
|
-
server_url=self._server_url,
|
|
123
|
-
operation="ListComponents",
|
|
124
|
-
grpc_error=grpc_error,
|
|
125
|
-
) from grpc_error
|
|
121
|
+
component_list = await client.call_stub_method(
|
|
122
|
+
self,
|
|
123
|
+
lambda: self.stub.ListComponents(
|
|
124
|
+
microgrid_pb2.ComponentFilter(),
|
|
125
|
+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
126
|
+
),
|
|
127
|
+
method_name="ListComponents",
|
|
128
|
+
)
|
|
126
129
|
|
|
127
130
|
components_only = filter(
|
|
128
131
|
lambda c: c.category
|
|
@@ -152,14 +155,15 @@ class ApiClient:
|
|
|
152
155
|
"""
|
|
153
156
|
microgrid_metadata: microgrid_pb2.MicrogridMetadata | None = None
|
|
154
157
|
try:
|
|
155
|
-
microgrid_metadata = await
|
|
156
|
-
|
|
157
|
-
self.
|
|
158
|
+
microgrid_metadata = await client.call_stub_method(
|
|
159
|
+
self,
|
|
160
|
+
lambda: self.stub.GetMicrogridMetadata(
|
|
158
161
|
Empty(),
|
|
159
162
|
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
160
163
|
),
|
|
164
|
+
method_name="GetMicrogridMetadata",
|
|
161
165
|
)
|
|
162
|
-
except
|
|
166
|
+
except ApiClientError:
|
|
163
167
|
_logger.exception("The microgrid metadata is not available.")
|
|
164
168
|
|
|
165
169
|
if not microgrid_metadata:
|
|
@@ -174,7 +178,7 @@ class ApiClient:
|
|
|
174
178
|
|
|
175
179
|
return Metadata(microgrid_id=microgrid_metadata.microgrid_id, location=location)
|
|
176
180
|
|
|
177
|
-
async def connections(
|
|
181
|
+
async def connections( # noqa: DOC502 (raises ApiClientError indirectly)
|
|
178
182
|
self,
|
|
179
183
|
starts: Set[int] = frozenset(),
|
|
180
184
|
ends: Set[int] = frozenset(),
|
|
@@ -196,25 +200,18 @@ class ApiClient:
|
|
|
196
200
|
[GrpcError][frequenz.client.microgrid.GrpcError].
|
|
197
201
|
"""
|
|
198
202
|
connection_filter = microgrid_pb2.ConnectionFilter(starts=starts, ends=ends)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
self.api.ListConnections(
|
|
207
|
-
connection_filter,
|
|
208
|
-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
209
|
-
),
|
|
203
|
+
valid_components, all_connections = await asyncio.gather(
|
|
204
|
+
self.components(),
|
|
205
|
+
client.call_stub_method(
|
|
206
|
+
self,
|
|
207
|
+
lambda: self.stub.ListConnections(
|
|
208
|
+
connection_filter,
|
|
209
|
+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
210
210
|
),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
operation="ListConnections",
|
|
216
|
-
grpc_error=grpc_error,
|
|
217
|
-
) from grpc_error
|
|
211
|
+
method_name="ListConnections",
|
|
212
|
+
),
|
|
213
|
+
)
|
|
214
|
+
|
|
218
215
|
# Filter out the components filtered in `components` method.
|
|
219
216
|
# id=0 is an exception indicating grid component.
|
|
220
217
|
valid_ids = {c.component_id for c in valid_components}
|
|
@@ -263,18 +260,16 @@ class ApiClient:
|
|
|
263
260
|
if broadcaster is None:
|
|
264
261
|
broadcaster = streaming.GrpcStreamBroadcaster(
|
|
265
262
|
f"raw-component-data-{component_id}",
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
# AsyncIterator, but it is a grpc.aio.UnaryStreamCall[...,
|
|
269
|
-
# microgrid_pb2.ComponentData], which it is.
|
|
270
|
-
lambda: cast(
|
|
271
|
-
AsyncIterator[microgrid_pb2.ComponentData],
|
|
272
|
-
self.api.StreamComponentData(
|
|
263
|
+
lambda: aiter(
|
|
264
|
+
self.stub.StreamComponentData(
|
|
273
265
|
microgrid_pb2.ComponentIdParam(id=component_id)
|
|
274
|
-
)
|
|
266
|
+
)
|
|
275
267
|
),
|
|
276
268
|
transform,
|
|
277
269
|
retry_strategy=self._retry_strategy,
|
|
270
|
+
# We don't expect any data stream to end, so if it is exhausted for any
|
|
271
|
+
# reason we want to keep retrying
|
|
272
|
+
retry_on_exhausted_stream=True,
|
|
278
273
|
)
|
|
279
274
|
self._broadcasters[component_id] = broadcaster
|
|
280
275
|
return broadcaster.new_receiver(maxsize=maxsize)
|
|
@@ -407,7 +402,9 @@ class ApiClient:
|
|
|
407
402
|
maxsize=maxsize,
|
|
408
403
|
)
|
|
409
404
|
|
|
410
|
-
async def set_power(
|
|
405
|
+
async def set_power( # noqa: DOC502 (raises ApiClientError indirectly)
|
|
406
|
+
self, component_id: int, power_w: float
|
|
407
|
+
) -> None:
|
|
411
408
|
"""Send request to the Microgrid to set power for component.
|
|
412
409
|
|
|
413
410
|
If power > 0, then component will be charged with this power.
|
|
@@ -424,22 +421,16 @@ class ApiClient:
|
|
|
424
421
|
most likely a subclass of
|
|
425
422
|
[GrpcError][frequenz.client.microgrid.GrpcError].
|
|
426
423
|
"""
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
component_id=component_id, power=power_w
|
|
433
|
-
),
|
|
434
|
-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
424
|
+
await client.call_stub_method(
|
|
425
|
+
self,
|
|
426
|
+
lambda: self.stub.SetPowerActive(
|
|
427
|
+
microgrid_pb2.SetPowerActiveParam(
|
|
428
|
+
component_id=component_id, power=power_w
|
|
435
429
|
),
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
operation="SetPowerActive",
|
|
441
|
-
grpc_error=grpc_error,
|
|
442
|
-
) from grpc_error
|
|
430
|
+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
431
|
+
),
|
|
432
|
+
method_name="SetPowerActive",
|
|
433
|
+
)
|
|
443
434
|
|
|
444
435
|
async def set_reactive_power( # noqa: DOC502 (raises ApiClientError indirectly)
|
|
445
436
|
self, component_id: int, reactive_power_var: float
|
|
@@ -458,22 +449,16 @@ class ApiClient:
|
|
|
458
449
|
most likely a subclass of
|
|
459
450
|
[GrpcError][frequenz.client.microgrid.GrpcError].
|
|
460
451
|
"""
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
component_id=component_id, power=reactive_power_var
|
|
467
|
-
),
|
|
468
|
-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
452
|
+
await client.call_stub_method(
|
|
453
|
+
self,
|
|
454
|
+
lambda: self.stub.SetPowerReactive(
|
|
455
|
+
microgrid_pb2.SetPowerReactiveParam(
|
|
456
|
+
component_id=component_id, power=reactive_power_var
|
|
469
457
|
),
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
operation="SetPowerReactive",
|
|
475
|
-
grpc_error=grpc_error,
|
|
476
|
-
) from grpc_error
|
|
458
|
+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
459
|
+
),
|
|
460
|
+
method_name="SetPowerReactive",
|
|
461
|
+
)
|
|
477
462
|
|
|
478
463
|
async def set_bounds( # noqa: DOC503 (raises ApiClientError indirectly)
|
|
479
464
|
self,
|
|
@@ -503,21 +488,15 @@ class ApiClient:
|
|
|
503
488
|
target_metric = (
|
|
504
489
|
microgrid_pb2.SetBoundsParam.TargetMetric.TARGET_METRIC_POWER_ACTIVE
|
|
505
490
|
)
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
bounds=metrics_pb2.Bounds(lower=lower, upper=upper),
|
|
514
|
-
),
|
|
515
|
-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
491
|
+
await client.call_stub_method(
|
|
492
|
+
self,
|
|
493
|
+
lambda: self.stub.AddInclusionBounds(
|
|
494
|
+
microgrid_pb2.SetBoundsParam(
|
|
495
|
+
component_id=component_id,
|
|
496
|
+
target_metric=target_metric,
|
|
497
|
+
bounds=metrics_pb2.Bounds(lower=lower, upper=upper),
|
|
516
498
|
),
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
operation="AddInclusionBounds",
|
|
522
|
-
grpc_error=grpc_error,
|
|
523
|
-
) from grpc_error
|
|
499
|
+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
|
|
500
|
+
),
|
|
501
|
+
method_name="AddInclusionBounds",
|
|
502
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: frequenz-client-microgrid
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.1
|
|
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.1; 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.0; 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.0; 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.2; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==0.28.0; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==1.14.6; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.12.2; extra == "dev-mkdocs"
|
|
26
51
|
Provides-Extra: dev-mypy
|
|
52
|
+
Requires-Dist: mypy==1.14.1; 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.20241207; 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==2024.10.9; extra == "dev-noxfile"
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.12.2; 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.4; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.12.2; 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
|
-
|
|
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
|
|
|
@@ -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.
|
|
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
|
|
@@ -13,43 +13,43 @@ frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxf
|
|
|
13
13
|
flake8==7.1.1
|
|
14
14
|
flake8-docstrings==1.7.0
|
|
15
15
|
flake8-pyproject==1.2.3
|
|
16
|
-
pydoclint==0.
|
|
16
|
+
pydoclint==0.6.0
|
|
17
17
|
pydocstyle==6.3.0
|
|
18
18
|
|
|
19
19
|
[dev-formatting]
|
|
20
|
-
black==
|
|
21
|
-
isort==
|
|
20
|
+
black==25.1.0
|
|
21
|
+
isort==6.0.0
|
|
22
22
|
|
|
23
23
|
[dev-mkdocs]
|
|
24
|
-
black==
|
|
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
|
-
mkdocs-macros-plugin==1.
|
|
30
|
-
mkdocs-material==9.
|
|
31
|
-
mkdocstrings[python]==0.
|
|
32
|
-
mkdocstrings-python==1.
|
|
33
|
-
frequenz-repo-config[lib]==0.
|
|
29
|
+
mkdocs-macros-plugin==1.3.7
|
|
30
|
+
mkdocs-material==9.6.2
|
|
31
|
+
mkdocstrings[python]==0.28.0
|
|
32
|
+
mkdocstrings-python==1.14.6
|
|
33
|
+
frequenz-repo-config[lib]==0.12.2
|
|
34
34
|
|
|
35
35
|
[dev-mypy]
|
|
36
|
-
mypy==1.
|
|
36
|
+
mypy==1.14.1
|
|
37
37
|
grpc-stubs==1.53.0.5
|
|
38
|
-
types-Markdown==3.7.0.
|
|
39
|
-
types-protobuf==5.
|
|
38
|
+
types-Markdown==3.7.0.20241204
|
|
39
|
+
types-protobuf==5.29.1.20241207
|
|
40
40
|
frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]
|
|
41
41
|
|
|
42
42
|
[dev-noxfile]
|
|
43
|
-
nox==2024.
|
|
44
|
-
frequenz-repo-config[lib]==0.
|
|
43
|
+
nox==2024.10.9
|
|
44
|
+
frequenz-repo-config[lib]==0.12.2
|
|
45
45
|
|
|
46
46
|
[dev-pylint]
|
|
47
|
-
pylint==3.
|
|
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.
|
|
52
|
-
frequenz-repo-config[extra-lint-examples]==0.
|
|
51
|
+
pytest==8.3.4
|
|
52
|
+
frequenz-repo-config[extra-lint-examples]==0.12.2
|
|
53
53
|
pytest-mock==3.14.0
|
|
54
|
-
pytest-asyncio==0.
|
|
54
|
+
pytest-asyncio==0.25.3
|
|
55
55
|
async-solipsism==0.7
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|