Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An asynchronous client for the PVOutput API.

Can safely be (cheaply) cloned or shared across threads.

§Usage

use pvoutput_client::{Client, types::params::GetStatusParams};
let client = Client::new("your-api-key", 12345, None, None)?;
let status = client.get_status(GetStatusParams::default()).await?;
println!("Generated {}Wh at {}", status.data.energy_generation, status.data.time);

Implementations§

Source§

impl Client

Source

pub async fn get_status( &self, params: GetStatusParams, ) -> Result<Response<Status>, NoEndpointSpecificError>

Retrieves a single status for the specified system.

PVOutput docs

Source

pub async fn get_status_history( &self, params: GetStatusParams, ) -> Result<Response<Vec<History>>, NoEndpointSpecificError>

Retrieves historic statuses for the specified system.

PVOutput docs

Source

pub async fn get_status_daily( &self, params: GetStatusParams, ) -> Result<Response<DailyStatus>, NoEndpointSpecificError>

Retrieves a daily stats summary for the specified system.

PVOutput docs

Source

pub async fn get_statistics( &self, params: GetStatisticsParams, ) -> Result<Response<Statistics>, NoEndpointSpecificError>

Retrieves statistics for a system.

This endpoint has a rate limit of twelve requests per hour for free accounts, and sixty for accounts with donation status.

This information is not exposed by the API – the rate_limit on the Response struct will not reflect these limits.

PVOutput docs

Source

pub async fn get_system( &self, params: GetSystemParams, ) -> Result<Response<FullSystem>, NoEndpointSpecificError>

Retrieves system information.

PVOutput docs

Source

pub async fn get_ladder( &self, system: Option<u32>, ) -> Result<Response<Ladder>, NoEndpointSpecificError>

Retrieves a system’s ladder ranking.

PVOutput docs

§Parameters
  • system: System ID to retrieve status for. If unset, the Client’s authenticated system is used. Requires donation status.
Source

pub async fn get_outputs( &self, params: GetOutputParams, ) -> Result<Response<Vec<Output>>, NoEndpointSpecificError>

Retrieves daily outputs.

PVOutput docs

Source

pub async fn get_aggregate_outputs( &self, aggregation: Aggregation, params: GetOutputParams, ) -> Result<Response<Vec<AggregatedOutput>>, NoEndpointSpecificError>

Retrieves monthly or yearly aggregated outputs.

PVOutput docs

Source

pub async fn get_team_outputs( &self, team_id: u32, params: GetOutputParams, ) -> Result<Response<Vec<TeamOutput>>, NoEndpointSpecificError>

Retrieves daily outputs for the given team.

PVOutput docs

Source

pub async fn get_extended( &self, params: GetExtendedParams, ) -> Result<Response<Vec<ExtendedData>>, NoEndpointSpecificError>

Retrieves daily extended output values for your system.

Requires donation status.

PVOutput docs

§Errors

Returns ClientError::NotFound if your system has no extended data for the specified date range.

Source

pub async fn get_favourites( &self, system: Option<u32>, ) -> Result<Response<Vec<FavouriteSystem>>, NoEndpointSpecificError>

Gets a system’s favourite systems. Limited to fifty systems.

PVOutput docs

§Parameters
  • system: System ID to retrieve favourites for. If unset, the Client’s authenticated system is used. Requires donation status.
Source

pub async fn get_missing( &self, from: Option<Date>, to: Option<Date>, ) -> Result<Response<Vec<Date>>, NoEndpointSpecificError>

Retrieves a list of missing output dates for your system.

A maximum of fifty missing dates will be returned in ascending order (i.e., oldest to most recent).

PVOutput docs

Source

pub async fn get_insolation( &self, params: GetInsolationParams, ) -> Result<Response<Vec<Insolation>>, NoEndpointSpecificError>

Retrieves insolation data at five minute intervals.

Requires donation status.

PVOutput docs

Source

pub async fn get_team( &self, team: u32, ) -> Result<Response<Team>, NoEndpointSpecificError>

Retrieves team data.

Only team owners may retrieve details of their own team. Donation-enabled accounts may query any team.

PVOutput docs

Source

pub async fn get_supply( &self, region: Option<Region>, timezone: Option<String>, ) -> Result<Response<Vec<Supply>>, NoEndpointSpecificError>

Retrieves aggregated live generation and consumption data.

§Parameters
  • region: Region to retrieve data for. If provided, the 24-hour supply and demand history for the region will be returned. Requires donation status.
  • timezone: Timezone to use in responses. If unset, data will be returned in UTC.

PVOutput docs

Source§

impl Client

Source

pub async fn add_outputs( &self, body: Vec<AddOutputParams>, ) -> Result<Response<()>, AddOutputError>

Adds one or more outputs for the Client’s system.

If the user has donation status, a maximum of one hundred outputs can be provided at once; otherwise, only one may be provided.

PVOutput docs

§Errors

Returns [crate::ClientError::InvalidData] containing [DataError::NoData] if the body vector is empty, or any other [DataError] variant if the provided parameters are invalid.

Source

pub async fn add_status( &self, body: AddStatusParams, ) -> Result<Response<()>, AddStatusError>

Adds a single status for the Client’s system.

If the user has donation status, statuses from up to ninety days in the past may be added; otherwise, statuses can only be from the past fourteen days.

PVOutput docs

Source

pub async fn add_batch_status( &self, statuses: Vec<AddBatchStatusParams>, cumulative: bool, ) -> Result<Response<Vec<BatchStatusReport>>, AddStatusError>

Adds multiple statuses for the Client’s system.

If the user has donation status, statuses may be from up to ninety days in the past (up from fourteen days), and one hundred statuses may be uploaded at a time (up from thirty).

This method does not set the n (net) flag. To upload net statuses, use the Client::add_batch_status_net method.

PVOutput docs

Source

pub async fn add_batch_status_net( &self, statuses: Vec<AddNetBatchStatusParams>, ) -> Result<Response<Vec<BatchStatusReport>>, AddStatusError>

Adds multiple statuses for the Client’s system.

If the user has donation status, statuses may be from up to ninety days in the past (up from fourteen days), and one hundred statuses may be uploaded at a time (up from thirty).

This method sets the n (net) flag. To upload statuses without the net flag set, use the Client::add_batch_status method.

PVOutput docs

Source

pub async fn post_system( &self, system: PostSystemParams, ) -> Result<Response<()>, PostSystemError>

Updates system configuration.

PVOutput docs

§Errors

In addition to the standard errors, this method can return a wide array of [crate::ClientError::InvalidData] variants:

  • [DataError::SystemNameTooLong]
  • [DataError::MissingExtendedDataLabel]: An extended variable update was provided with no label. The u8 value carried by this variant refers to the variable that was missing its label.
  • [DataError::MissingExtendedDataUnit]: The same as above, but for the unit field.
  • [DataError::ExtendedDataLabelTooLong]
  • [DataError::ExtendedDataUnitTooLong]
  • [DataError::InvalidExtendedDataField]: The variable specified by this variant’s first value had an invalid field (specified by the variant’s second value).
Source

pub async fn delete_status( &self, date: Date, time: Option<Time>, ) -> Result<Response<()>, DateTimeError>

Deletes a status, or all statuses for a day.

If time is set, the specific status with the provided date and time will be deleted. Otherwise, all statuses for the given date will be deleted.

PVOutput docs

Source§

impl Client

Source

pub fn new( api_key: &str, system_id: u32, user_agent: Option<&str>, timeout: Option<Duration>, ) -> Result<Self, NoEndpointSpecificError>

Creates a new Client.

If you want to provide your own [reqwest::Client], see Client::new_with_reqwest.

§Parameters
  • api_key: Your PVOutput API key.
  • system_id: A PVOutput system ID. The system must be owned by the API key provided.
  • user_agent: A user agent to use for all requests. If not provided, Client::default_user_agent will be used.
  • timeout: An overall timeout, applied from when the request starts connecting to when the response body has finished. If not provided, a default value of twenty seconds will be used.
§Example
let client = pvoutput_client::Client::new("your-api-key", 12345, None, None)?;
Source

pub fn new_with_reqwest( api_key: &str, system_id: u32, reqwest: Client, ) -> Result<Self, NoEndpointSpecificError>

Creates a new Client backed by the provided [reqwest::Client].

If you don’t want to provide your own reqwest Client, see Client::new.

The provided reqwest Client should have a user agent and timeout. Client::default_user_agent provides a sensible default user agent string.

§Example
let reqwest = reqwest::ClientBuilder::new()
  .user_agent(pvoutput_client::Client::default_user_agent())
  .timeout(std::time::Duration::from_secs(20))
  .build()?;
let client = pvoutput_client::Client::new_with_reqwest("your-api-key", 12345, reqwest)?;
Source

pub const fn default_user_agent() -> &'static str

Provides a default user agent. The agent will look something like pvoutput-client/v0.1.0 +https://gitlab.com/Lynnesbian/pvoutput-client

Source

pub async fn search( &self, params: SearchParams, ) -> Result<Response<Vec<SearchResult>>, NoEndpointSpecificError>

Searches systems. Limited to a maximum of 30 results.

PVOutput docs

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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