Skip to main content

MicrogridClient

Struct MicrogridClient 

Source
pub struct MicrogridClient<T> { /* private fields */ }
Expand description

The Frequenz Microgrid API

Implementations§

Source§

impl MicrogridClient<Channel>

Source

pub async fn connect<D>(dst: D) -> Result<Self, Error>
where D: TryInto<Endpoint>, D::Error: Into<StdError>,

Attempt to create a new client by connecting to a given endpoint.

Source§

impl<T> MicrogridClient<T>
where T: GrpcService<Body>, T::Error: Into<StdError>, T::ResponseBody: Body<Data = Bytes> + Send + 'static, <T::ResponseBody as Body>::Error: Into<StdError> + Send,

Source

pub fn new(inner: T) -> Self

Source

pub fn with_origin(inner: T, origin: Uri) -> Self

Source

pub fn with_interceptor<F>( inner: T, interceptor: F, ) -> MicrogridClient<InterceptedService<T, F>>
where F: Interceptor, T::ResponseBody: Default, T: Service<Request<Body>, Response = Response<<T as GrpcService<Body>>::ResponseBody>>, <T as Service<Request<Body>>>::Error: Into<StdError> + Send + Sync,

Source

pub fn send_compressed(self, encoding: CompressionEncoding) -> Self

Compress requests with the given encoding.

This requires the server to support it otherwise it might respond with an error.

Source

pub fn accept_compressed(self, encoding: CompressionEncoding) -> Self

Enable decompressing responses.

Source

pub fn max_decoding_message_size(self, limit: usize) -> Self

Limits the maximum size of a decoded message.

Default: 4MB

Source

pub fn max_encoding_message_size(self, limit: usize) -> Self

Limits the maximum size of an encoded message.

Default: usize::MAX

Source

pub async fn get_microgrid( &mut self, request: impl IntoRequest<Empty>, ) -> Result<Response<GetMicrogridResponse>, Status>

Returns information about the local microgrid. This information that describes the overall microgrid, as opposed to its electrical components or sensors, e.g., the microgrid ID, location.

Source

pub async fn list_electrical_components( &mut self, request: impl IntoRequest<ListElectricalComponentsRequest>, ) -> Result<Response<ListElectricalComponentsResponse>, Status>

List electrical components in the local microgrid, optionally filtered by a given list of electrical component IDs and their categories.

Electrical components are a part of a microgrid’s electrical infrastructure are can be connected to each other to form an electrical circuit, which can then be represented as a graph.

If provided, the filters for electrical component IDs and categories have an AND relationship with one another, meaning that they are applied serially, but the elements within a single filter list have an OR relationship with each other. E.g., if ids = [1, 2, 3], and categories = [ ElectricalComponentCategory::ELECTRICAL_COMPONENT_CATEGORY_INVERTER, ElectricalComponentCategory::ELECTRICAL_COMPONENT_CATEGORY_BATTERY], then the results will consist of elements that have the IDs 1, OR 2, OR 3, AND are of the categories ElectricalComponentCategory::ELECTRICAL_COMPONENT_CATEGORY_INVERTER OR ElectricalComponentCategory::ELECTRICAL_COMPONENT_CATEGORY_BATTERY.

If a filter list is empty, then that filter is not applied.

Source

pub async fn list_sensors( &mut self, request: impl IntoRequest<ListSensorRequest>, ) -> Result<Response<ListSensorsResponse>, Status>

Returns a list of sensors in the local microgrid, optionally filtered by a given list of sensor IDs.

Sensors measure physical metrics in the microgrid’s surroundings, and are not classified as electrical components.

If provided, the filters for sensor IDs and categories have an AND relationship with one another, meaning that they are applied serially, but the elements within a single filter list have an OR relationship with each other. E.g., if ids = [1, 2, 3], then the results will consist of elements that have the IDs 1, OR 2, OR 3,

If a filter list is empty, then that filter is not applied.

Source

pub async fn list_electrical_component_connections( &mut self, request: impl IntoRequest<ListElectricalComponentConnectionsRequest>, ) -> Result<Response<ListElectricalComponentConnectionsResponse>, Status>

Electrical components are a part of a microgrid’s electrical infrastructure are can be connected to each other to form an electrical circuit, which can then be represented as a graph.

This RPC return a list of the connections between two electrical components, denoted by (start, end). The direction of a connection is always away from the grid endpoint, i.e. aligned with the direction of positive current according to the passive sign convention: https://en.wikipedia.org/wiki/Passive_sign_convention

The request may be filtered by start/end electrical component(s) of individual connections. If provided, the start and end filters have an AND relationship between each other, meaning that they are applied serially, but an OR relationship with other elements in the same list. For example, if start = [1, 2, 3], and end = [4, 5, 6], then the result should have all the connections where

  • each start electrical component ID is either 1, 2, OR 3, AND
  • each end electrical component ID is either 4, 5, OR 6.
Source

pub async fn receive_electrical_component_telemetry_stream( &mut self, request: impl IntoRequest<ReceiveElectricalComponentTelemetryStreamRequest>, ) -> Result<Response<Streaming<ReceiveElectricalComponentTelemetryStreamResponse>>, Status>

Returns a stream containing data from a electrical component with a given ID.

Source

pub async fn receive_sensor_telemetry_stream( &mut self, request: impl IntoRequest<ReceiveSensorTelemetryStreamRequest>, ) -> Result<Response<Streaming<ReceiveSensorTelemetryStreamResponse>>, Status>

Returns a stream containing data from a sensor with a given ID.

Source

pub async fn augment_electrical_component_bounds( &mut self, request: impl IntoRequest<AugmentElectricalComponentBoundsRequest>, ) -> Result<Response<AugmentElectricalComponentBoundsResponse>, Status>

Augments the overall bounds for a given metric of a given electrical component with the provided bounds. Returns the UTC time at which the provided bounds will expire and its effects will no longer be visible in the overall bounds for the given metric.

The request parameters allows users to select a duration until which the bounds will stay in effect. If no duration is provided, then the bounds will be removed after a default duration of 5 seconds.

Inclusion bounds give the range that the system will try to keep the metric within. If the metric goes outside of these bounds, the system will try to bring it back within the bounds. If the bounds for a metric are [`lower_1, upper_1], [lower_2, upper_2](<lower_1, upper_1], [lower_2, upper_2>), then this metric's valueneeds to comply with the constraintslower_1 <= value <= upper_1ORlower_2 <= value <= upper_2`.

If multiple inclusion bounds have been provided for a metric, then the overlapping bounds are merged into a single bound, and non-overlapping bounds are kept separate. E.g. if the bounds are [0, 10], [5, 15], 20, 30, then the resulting bounds will be [0, 15], 20, 30.

The following diagram illustrates how bounds are applied:

 lower_1  upper_1
<----|========|--------|========|-------->
                   lower_2  upper_2

The bounds in this example are [[lower_1, upper_1], [lower_2, upper_2]]. –– values here are considered out of range. ==== values here are considered within range.

Note that for power metrics, regardless of the bounds, 0W is always allowed.

Source

pub async fn set_electrical_component_power( &mut self, request: impl IntoRequest<SetElectricalComponentPowerRequest>, ) -> Result<Response<Streaming<SetElectricalComponentPowerResponse>>, Status>

Sets the active or reactive power output of a electrical component to a specified target. This RPC allows setting either active or reactive power in a single request. Setting both simultaneously is not supported; clients must issue separate requests for each power type.

Clients are expected to provide the target power in the request parameters. The target power is specified in watts (W) for active power, and in volt-amperes reactive (VAR) for reactive power. The sign-convention for the target power is as follows:

For active power:

  • Negative values (-) indicate discharge towards the grid.
  • Positive values (+) indicate charge from the direction of the grid.

For reactive power:

  • Negative values (-) indicate capacitive reactive power, where the current leads the voltage.
  • Positive values (+) indicate inductive reactive power, where the current lags the voltage.

Note that the target electrical component may have a resolution of more than 1 W or 1 VAr. E.g., an inverter may have a resolution of 88 W. In such cases, the target power’s magnitude will be floored to the nearest multiple of the resolution.

The server provides a stream of responses in return. Each response will contain the current status of the request. Initial response: The initial response will be sent immediately after the request is received, and will indicate whether the request was accepted or rejected. If the request was accepted, this response will also contain the timestamp until which the given power command will stay in effect, after which the electrical component will be returned to its default state. Subsequent response: After the initial response, the server will send another response in the stream, which will be the final response. It will indicate whether the request was successful, failed, or overridden by another request. If the request was successful, it will also contain the timestamp until which the given power command will stay in effect, after which the electrical component will be returned to its default state.

This command is supported for the following electrical component categories, provided the specific model also supports it:

  • ELECTRICAL_COMPONENT_CATEGORY_CAPACITOR_BANK
  • ELECTRICAL_COMPONENT_CATEGORY_CHP
  • ELECTRICAL_COMPONENT_CATEGORY_ELECTROLYZER
  • ELECTRICAL_COMPONENT_CATEGORY_EV_CHARGER
  • ELECTRICAL_COMPONENT_CATEGORY_INVERTER
  • ELECTRICAL_COMPONENT_CATEGORY_WIND_TURBINE
Source

pub async fn start_electrical_component( &mut self, request: impl IntoRequest<StartElectricalComponentRequest>, ) -> Result<Response<Empty>, Status>

Starts the electrical component, and brings it into a state where it is immediately operational.

Performs the following sequence of actions for the following electrical component categories:

  • Inverter:

  • closes DC relays, if the feature is available

  • closes AC relays

  • sets power output to 0

  • Battery: Checks if DC relays are open, then

  • closes DC relays

  • Relays:

  • closes relays

  • Precharge Modules:

  • starts the precharge process, and eventually closes the DC relays.

If any of the above mentioned actions for a given electrical component has already been performed, then this method call effectively skips that action.

If a feature required to perform an action is missing, then that action is skipped.

Source

pub async fn put_electrical_component_in_standby( &mut self, request: impl IntoRequest<PutElectricalComponentInStandbyRequest>, ) -> Result<Response<Empty>, Status>

Sets the given electrical component into a standby state, from which it can take a few minutes to return to an operational state. A transition to an operational state can be triggered by calling the StartElectricalComponent RPC, or the SetElectricalComponentPowerActive RPC.

Performs the following sequence actions for the following electrical component categories:

  • Inverter: Checks if AC and DC relays are closed, then
  • sets power to 0, and
  • opens AC relays

If any of the checks mentioned above fails, then the method call returns an error.

If any of the above mentioned actions for a given electrical component has already been performed, then this method call effectively skips that action.

Source

pub async fn stop_electrical_component( &mut self, request: impl IntoRequest<StopElectricalComponentRequest>, ) -> Result<Response<Empty>, Status>

Stops the electrical component completely, potentially disengaging its power electronics controller(s).

Performs the following sequence actions for the following electrical component categories:

  • Inverter:

  • Brings electrical component to the cold-standby state

  • opens DC relays

  • Battery: Checks if the power output is 0, then

  • opens DC relays

  • Relays:

  • opens relays

  • Precharge Modules:

  • opens the DC relays.

If any of the checks mentioned above fails, then the method call returns an error.

If any of the above mentioned actions for a given electrical component has already been performed, then this method call effectively skips that action.

If a feature required to perform an action is missing, then that action is skipped.

Source

pub async fn ack_electrical_component_error( &mut self, request: impl IntoRequest<AckElectricalComponentErrorRequest>, ) -> Result<Response<Empty>, Status>

Acknowledges any recoverable error reported by the electrical component, and brings it back to the stopped or cold-standby state.

Trait Implementations§

Source§

impl<T: Clone> Clone for MicrogridClient<T>

Source§

fn clone(&self) -> MicrogridClient<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for MicrogridClient<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for MicrogridClient<T>

§

impl<T> RefUnwindSafe for MicrogridClient<T>
where T: RefUnwindSafe,

§

impl<T> Send for MicrogridClient<T>
where T: Send,

§

impl<T> Sync for MicrogridClient<T>
where T: Sync,

§

impl<T> Unpin for MicrogridClient<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for MicrogridClient<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for MicrogridClient<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more