|  | 
|  | 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 | +    ) | 
0 commit comments