66import asyncio
77import logging
88from collections .abc import AsyncIterator , Awaitable , Callable , Iterable , Set
9+ from dataclasses import replace
910from typing import Any , TypeVar , cast
1011
1112import grpc .aio
4445_logger = logging .getLogger (__name__ )
4546
4647
48+ DEFAULT_CHANNEL_OPTIONS = replace (
49+ channel .ChannelOptions (), ssl = channel .SslOptions (enabled = False )
50+ )
51+ """The default channel options for the microgrid API client.
52+
53+ These are the same defaults as the common default options but with SSL disabled, as the
54+ microgrid API does not use SSL by default.
55+ """
56+
57+
4758class ApiClient :
4859 """A microgrid API client."""
4960
5061 def __init__ (
5162 self ,
5263 server_url : str ,
5364 * ,
65+ channel_options : channel .ChannelOptions = DEFAULT_CHANNEL_OPTIONS ,
5466 retry_strategy : retry .Strategy | None = None ,
5567 ) -> None :
5668 """Initialize the class instance.
@@ -62,14 +74,18 @@ def __init__(
6274 where the `port` should be an int between 0 and 65535 (defaulting to
6375 9090) and `ssl` should be a boolean (defaulting to `false`).
6476 For example: `grpc://localhost:1090?ssl=true`.
77+ channel_options: The default options use to create the channel when not
78+ specified in the URL.
6579 retry_strategy: The retry strategy to use to reconnect when the connection
6680 to the streaming method is lost. By default a linear backoff strategy
6781 is used.
6882 """
6983 self ._server_url = server_url
7084 """The location of the microgrid API server as a URL."""
7185
72- self .api = microgrid_pb2_grpc .MicrogridStub (channel .parse_grpc_uri (server_url ))
86+ self .api = microgrid_pb2_grpc .MicrogridStub (
87+ channel .parse_grpc_uri (server_url , defaults = channel_options )
88+ )
7389 """The gRPC stub for the microgrid API."""
7490
7591 self ._broadcasters : dict [int , streaming .GrpcStreamBroadcaster [Any , Any ]] = {}
0 commit comments