From 40f7e64b5ca07b4b8b876d5a7437cf4c25c562d9 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Mon, 18 Nov 2024 19:25:43 +0100 Subject: [PATCH] Update microgrid client to latest version Signed-off-by: Mathias L. Baumann --- RELEASE_NOTES.md | 2 +- pyproject.toml | 2 +- .../_ev_charger_manager/_ev_charger_manager.py | 4 ++-- src/frequenz/sdk/microgrid/component_graph.py | 4 ++-- src/frequenz/sdk/microgrid/connection_manager.py | 14 +++++++------- tests/microgrid/test_graph.py | 4 ++-- tests/microgrid/test_microgrid_api.py | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 61ee6f2ad..3175d54d4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,7 +10,7 @@ ## New Features - +* The `MicrogridApiClient` was updated to the latest version. ## Bug Fixes diff --git a/pyproject.toml b/pyproject.toml index e44241596..8abaef3c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ # Make sure to update the mkdocs.yml file when # changing the version # (plugins.mkdocstrings.handlers.python.import) - "frequenz-client-microgrid >= 0.5.1, < 0.6.0", + "frequenz-client-microgrid >= 0.6.0, < 0.7.0", "frequenz-channels >= 1.2.0, < 2.0.0", "frequenz-quantities == 1.0.0rc3", "networkx >= 2.8, < 4", diff --git a/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py b/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py index 19ad9b146..05e276ebf 100644 --- a/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py +++ b/src/frequenz/sdk/microgrid/_power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py @@ -17,10 +17,10 @@ selected_from, ) from frequenz.client.microgrid import ( - ApiClient, ApiClientError, ComponentCategory, EVChargerData, + MicrogridApiClient, ) from frequenz.quantities import Power, Voltage from typing_extensions import override @@ -292,7 +292,7 @@ async def _run(self) -> None: # pylint: disable=too-many-locals async def _set_api_power( self, - api: ApiClient, + api: MicrogridApiClient, target_power_changes: dict[int, Power], api_request_timeout: timedelta, ) -> Result: diff --git a/src/frequenz/sdk/microgrid/component_graph.py b/src/frequenz/sdk/microgrid/component_graph.py index 3498c2da8..f5cdc081e 100644 --- a/src/frequenz/sdk/microgrid/component_graph.py +++ b/src/frequenz/sdk/microgrid/component_graph.py @@ -28,11 +28,11 @@ import networkx as nx from frequenz.client.microgrid import ( - ApiClient, Component, ComponentCategory, Connection, InverterType, + MicrogridApiClient, ) _logger = logging.getLogger(__name__) @@ -559,7 +559,7 @@ def refresh_from( async def refresh_from_api( self, - api: ApiClient, + api: MicrogridApiClient, correct_errors: Callable[["_MicrogridComponentGraph"], None] | None = None, ) -> None: """Refresh the contents of a component graph from the remote API. diff --git a/src/frequenz/sdk/microgrid/connection_manager.py b/src/frequenz/sdk/microgrid/connection_manager.py index 9d5c3e35b..afc69ddf7 100644 --- a/src/frequenz/sdk/microgrid/connection_manager.py +++ b/src/frequenz/sdk/microgrid/connection_manager.py @@ -11,7 +11,7 @@ import logging from abc import ABC, abstractmethod -from frequenz.client.microgrid import ApiClient, Location, Metadata +from frequenz.client.microgrid import Location, Metadata, MicrogridApiClient from .component_graph import ComponentGraph, _MicrogridComponentGraph @@ -41,8 +41,8 @@ def server_url(self) -> str: @property @abstractmethod - def api_client(self) -> ApiClient: - """Get ApiClient. + def api_client(self) -> MicrogridApiClient: + """Get the MicrogridApiClient. Returns: api client @@ -97,7 +97,7 @@ def __init__(self, server_url: str) -> None: `grpc://localhost:1090?ssl=true`. """ super().__init__(server_url) - self._api = ApiClient(server_url) + self._api = MicrogridApiClient(server_url) # To create graph from the api we need await. # So create empty graph here, and update it in `run` method. self._graph = _MicrogridComponentGraph() @@ -106,8 +106,8 @@ def __init__(self, server_url: str) -> None: """The metadata of the microgrid.""" @property - def api_client(self) -> ApiClient: - """Get ApiClient. + def api_client(self) -> MicrogridApiClient: + """Get the MicrogridApiClient. Returns: api client @@ -154,7 +154,7 @@ async def _update_api(self, server_url: str) -> None: """ await super()._update_api(server_url) # pylint: disable=protected-access - self._api = ApiClient(server_url) + self._api = MicrogridApiClient(server_url) await self._initialize() async def _initialize(self) -> None: diff --git a/tests/microgrid/test_graph.py b/tests/microgrid/test_graph.py index 69ac0f2a9..cd522a788 100644 --- a/tests/microgrid/test_graph.py +++ b/tests/microgrid/test_graph.py @@ -11,13 +11,13 @@ import pytest from frequenz.client.microgrid import ( - ApiClient, Component, ComponentCategory, ComponentMetadata, Connection, Fuse, InverterType, + MicrogridApiClient, ) import frequenz.sdk.microgrid.component_graph as gr @@ -899,7 +899,7 @@ async def test_refresh_from_api(self) -> None: with pytest.raises(gr.InvalidGraphError): graph.validate() - client = mock.MagicMock(name="client", spec=ApiClient) + client = mock.MagicMock(name="client", spec=MicrogridApiClient) client.components = mock.AsyncMock(name="client.components()", return_value=[]) client.connections = mock.AsyncMock( name="client.connections()", return_value=[] diff --git a/tests/microgrid/test_microgrid_api.py b/tests/microgrid/test_microgrid_api.py index c5363ef16..430605207 100644 --- a/tests/microgrid/test_microgrid_api.py +++ b/tests/microgrid/test_microgrid_api.py @@ -126,7 +126,7 @@ async def test_connection_manager( microgrid_client.metadata = AsyncMock(return_value=metadata) with mock.patch( - "frequenz.sdk.microgrid.connection_manager.ApiClient", + "frequenz.sdk.microgrid.connection_manager.MicrogridApiClient", return_value=microgrid_client, ): # Get instance without initializing git first.