Skip to content

Commit 42b012e

Browse files
Initial client
Signed-off-by: Flora <[email protected]>
1 parent 0218917 commit 42b012e

File tree

5 files changed

+452
-4
lines changed

5 files changed

+452
-4
lines changed

RELEASE_NOTES.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release introduces the initial version of the Assets API client, enabling retrieval of asset-related data.
66

77
## Upgrading
88

99
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
Introducing the initial version of the Assets API client, designed to streamline access to asset-related data.
14+
15+
* Supports querying asset components and retrieving their metrics efficiently.
16+
* Provides a structured data representation while retaining raw protobuf responses.
17+
* Currently focused on retrieving asset data for individual components.
18+
* Examples are provided to guide users through the basic usage of the client.
1419

1520
## Bug Fixes
1621

examples/client.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Examples usage of PlatformAssets API."""
5+
6+
import argparse
7+
import asyncio
8+
from pprint import pprint
9+
10+
from frequenz.client.assets._client import AssetsApiClient
11+
12+
13+
async def main(
14+
microgrid_id: int,
15+
component_ids: list[int],
16+
categories: list[int] | None,
17+
source_component_ids: list[int] | None,
18+
destination_component_ids: list[int] | None,
19+
) -> None:
20+
"""Test the AssetsApiClient.
21+
22+
Args:
23+
microgrid_id: The ID of the microgrid to query.
24+
component_ids: List of component IDs to filter.
25+
categories: List of component categories to filter.
26+
source_component_ids: List of source component IDs to filter.
27+
destination_component_ids: List of destination component IDs to filter.
28+
"""
29+
server_url = "localhost:50052"
30+
client = AssetsApiClient(server_url)
31+
32+
print("########################################################")
33+
print("Fetching microgrid details")
34+
35+
microgrid_details = await client.get_microgrid_details(microgrid_id)
36+
pprint(microgrid_details)
37+
38+
print("########################################################")
39+
print("Listing microgrid components")
40+
41+
components = await client.list_microgrid_component_connections(
42+
microgrid_id, component_ids, categories
43+
)
44+
pprint(components)
45+
46+
print("########################################################")
47+
print("Listing microgrid component connections")
48+
49+
connections = await client.list_microgrid_component_connections(
50+
microgrid_id, source_component_ids, destination_component_ids
51+
)
52+
pprint(connections)
53+
54+
55+
if __name__ == "__main__":
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument("microgrid_id", type=int, help="Microgrid ID")
58+
parser.add_argument(
59+
"component_ids", nargs="*", type=int, help="List of component IDs to filter"
60+
)
61+
parser.add_argument(
62+
"categories", nargs="*", type=str, help="List of component categories to filter"
63+
)
64+
parser.add_argument(
65+
"source_component_ids",
66+
nargs="*",
67+
type=int,
68+
help="List of source component IDs to filter",
69+
)
70+
parser.add_argument(
71+
"destination_component_ids",
72+
nargs="*",
73+
type=int,
74+
help="List of destination component IDs to filter",
75+
)
76+
77+
args = parser.parse_args()
78+
asyncio.run(
79+
main(
80+
args.microgrid_id,
81+
args.component_ids,
82+
args.categories,
83+
args.source_component_ids,
84+
args.destination_component_ids,
85+
)
86+
)

pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
dependencies = [
2929
"typing-extensions >= 4.12.2, < 5",
30+
"frequenz-api-assets @ git+https://github.com/frequenz-floss/[email protected]",
31+
"frequenz-client-common >= 0.3.0, < 1",
32+
"frequenz-client-base >= 0.11.0, < 1",
3033
]
3134
dynamic = ["version"]
3235

@@ -82,6 +85,10 @@ dev = [
8285
"frequenz-client-assets[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
8386
]
8487

88+
examples = [
89+
"grpcio >= 1.51.1, < 2",
90+
]
91+
8592
[project.urls]
8693
Documentation = "https://frequenz-floss.github.io/frequenz-client-assets-python/"
8794
Changelog = "https://github.com/frequenz-floss/frequenz-client-assets-python/releases"
@@ -146,7 +153,15 @@ disable = [
146153
]
147154

148155
[tool.pytest.ini_options]
149-
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
156+
addopts = "-vv"
157+
filterwarnings = [
158+
"error",
159+
"once::DeprecationWarning",
160+
"once::PendingDeprecationWarning",
161+
# We use a raw string (single quote) to avoid the need to escape special
162+
# chars as this is a regex
163+
'ignore:Protobuf gencode version .*exactly one major version older.*:UserWarning',
164+
]
150165
testpaths = ["tests", "src"]
151166
asyncio_mode = "auto"
152167
asyncio_default_fixture_loop_scope = "function"

src/frequenz/client/assets/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def delete_me(*, blow_up: bool = False) -> bool:
1313
1414
Returns:
1515
True if no exception was raised.
16-
1716
Raises:
1817
RuntimeError: if blow_up is True.
1918
"""

0 commit comments

Comments
 (0)