Skip to content

Commit

Permalink
Upgrade client-base to v0.2.0 (#20)
Browse files Browse the repository at this point in the history
- **Bump mkdocs-material from 9.5.11 to 9.5.12**
- **Upgrade `client-base` to v0.2.0**
- **Rename `retry_spec` to `retry_strategy`**
  • Loading branch information
llucax authored Mar 4, 2024
2 parents b8aa419 + 150099c commit adde8c2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ Code import from the [SDK v1.0.0-rc5](https://github.com/frequenz-floss/frequenz
Changes compared to the code in the SDK v1.0.0-rc5 release:

* The `MicrogridGrpcClient` class was renamed to `ApiClient`.

* The `retry_spec` constructor argument was renamed to `retry_strategy`.

* The `MicrogridApiClient` abstract base class was removed, use `ApiClient` instead.

* The `Connection` class is now a `dataclass` instead of a `NamedTuple`. If you use the tuple-like interface (`connection[0]`, etc.) you should use the named attributes instead or use [`dataclasses.astuple()`](https://docs.python.org/3/library/dataclasses.html#dataclasses.astuple) to convert it to a tuple.
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ plugins:
- https://frequenz-floss.github.io/frequenz-api-common/v0.5/objects.inv
- https://frequenz-floss.github.io/frequenz-api-microgrid/v0.15/objects.inv
- https://frequenz-floss.github.io/frequenz-channels-python/v1.0-pre/objects.inv
- https://frequenz-floss.github.io/frequenz-client-base-python/v0.2-dev/objects.inv
- https://frequenz-floss.github.io/frequenz-client-base-python/v0.2/objects.inv
- https://grpc.github.io/grpc/python/objects.inv
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
# Note this plugin must be loaded after mkdocstrings to be able to use macros
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ requires-python = ">= 3.11, < 4"
dependencies = [
"frequenz-api-microgrid >= 0.15.3, < 0.16.0",
"frequenz-channels == 1.0.0b2",
"frequenz-client-base @ git+https://github.com/frequenz-floss/frequenz-client-base-python.git@03f2ed2104efc1bdad05eed68db167e87eb8b1aa",
"frequenz-client-base >= 0.2.0, < 0.3.0",
"grpcio >= 1.54.2, < 2",
"protobuf >= 4.25.3, < 5",
"timezonefinder >= 6.2.0, < 7",
Expand Down Expand Up @@ -66,7 +66,7 @@ dev-mkdocs = [
"mkdocs-gen-files == 0.5.0",
"mkdocs-literate-nav == 0.6.1",
"mkdocs-macros-plugin == 1.0.5",
"mkdocs-material == 9.5.11",
"mkdocs-material == 9.5.12",
"mkdocstrings[python] == 0.24.1",
"frequenz-repo-config[lib] == 0.9.1",
]
Expand Down
9 changes: 0 additions & 9 deletions src/frequenz/client/microgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"""


from frequenz.client.base.retry_strategy import (
ExponentialBackoff,
LinearBackoff,
RetryStrategy,
)

from ._client import ApiClient
from ._component import Component
from ._component_data import (
Expand All @@ -35,11 +29,8 @@
"EVChargerCableState",
"EVChargerComponentState",
"EVChargerData",
"ExponentialBackoff",
"InverterData",
"LinearBackoff",
"Location",
"Metadata",
"MeterData",
"RetryStrategy",
]
15 changes: 7 additions & 8 deletions src/frequenz/client/microgrid/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

# pylint: enable=no-name-in-module
from frequenz.channels import Receiver
from frequenz.client.base.grpc_streaming_helper import GrpcStreamingHelper
from frequenz.client.base.retry_strategy import LinearBackoff, RetryStrategy
from frequenz.client.base import retry, streaming
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module

from ._component import (
Expand Down Expand Up @@ -68,25 +67,25 @@ def __init__(
self,
grpc_channel: grpc.aio.Channel,
target: str,
retry_spec: RetryStrategy = LinearBackoff(),
retry_strategy: retry.Strategy = retry.LinearBackoff(),
) -> None:
"""Initialize the class instance.
Args:
grpc_channel: asyncio-supporting gRPC channel
target: server (host:port) to be used for asyncio-supporting gRPC
channel that the client should use to contact the API
retry_spec: Specs on how to retry if the connection to a streaming
method gets lost.
retry_strategy: The retry strategy to use to reconnect when the connection
to the streaming method is lost.
"""
self.target = target
"""The location (as "host:port") of the microgrid API gRPC server."""

self.api = MicrogridStub(grpc_channel)
"""The gRPC stub for the microgrid API."""

self._broadcasters: dict[int, GrpcStreamingHelper[Any, Any]] = {}
self._retry_spec = retry_spec
self._broadcasters: dict[int, streaming.GrpcStreamBroadcaster[Any, Any]] = {}
self._retry_strategy = retry_strategy

async def components(self) -> Iterable[Component]:
"""Fetch all the components present in the microgrid.
Expand Down Expand Up @@ -264,7 +263,7 @@ async def _new_component_data_receiver(

broadcaster = self._broadcasters.setdefault(
component_id,
GrpcStreamingHelper(
streaming.GrpcStreamBroadcaster(
f"raw-component-data-{component_id}",
# We need to cast here because grpc says StreamComponentData is
# a grpc.CallIterator[PbComponentData], not a
Expand Down
7 changes: 4 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
from frequenz.api.microgrid.microgrid_pb2 import ConnectionFilter as PbConnectionFilter
from frequenz.api.microgrid.microgrid_pb2 import ConnectionList as PbConnectionList
from frequenz.api.microgrid.microgrid_pb2 import SetBoundsParam as PbSetBoundsParam
from frequenz.client.base.retry_strategy import LinearBackoff
from google.protobuf.empty_pb2 import Empty

# pylint: enable=no-name-in-module
from frequenz.client.base.retry import LinearBackoff
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module

from frequenz.client.microgrid import _client as client
from frequenz.client.microgrid._component import (
Component,
Expand Down Expand Up @@ -66,7 +67,7 @@ async def _gprc_server(
microgrid = client.ApiClient(
grpc.aio.insecure_channel(f"[::]:{port}"),
f"[::]:{port}",
retry_spec=LinearBackoff(interval=0.0, jitter=0.05),
retry_strategy=LinearBackoff(interval=0.0, jitter=0.05),
)
await server.start()
try:
Expand Down

0 comments on commit adde8c2

Please sign in to comment.