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
impl Client
Sourcepub async fn get_status(
&self,
params: GetStatusParams,
) -> Result<Response<Status>, NoEndpointSpecificError>
pub async fn get_status( &self, params: GetStatusParams, ) -> Result<Response<Status>, NoEndpointSpecificError>
Retrieves a single status for the specified system.
- For historic data (
h), useClient::get_status_history - For statistics (
stats), useClient::get_status_daily
Sourcepub async fn get_status_history(
&self,
params: GetStatusParams,
) -> Result<Response<Vec<History>>, NoEndpointSpecificError>
pub async fn get_status_history( &self, params: GetStatusParams, ) -> Result<Response<Vec<History>>, NoEndpointSpecificError>
Retrieves historic statuses for the specified system.
- For a single measurement, use
Client::get_status - For statistics (
stats), useClient::get_status_daily
Sourcepub async fn get_status_daily(
&self,
params: GetStatusParams,
) -> Result<Response<DailyStatus>, NoEndpointSpecificError>
pub async fn get_status_daily( &self, params: GetStatusParams, ) -> Result<Response<DailyStatus>, NoEndpointSpecificError>
Retrieves a daily stats summary for the specified system.
- For historic data (
h), useClient::get_status_history - For a single measurement, use
Client::get_status
Sourcepub async fn get_statistics(
&self,
params: GetStatisticsParams,
) -> Result<Response<Statistics>, NoEndpointSpecificError>
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.
Sourcepub async fn get_system(
&self,
params: GetSystemParams,
) -> Result<Response<FullSystem>, NoEndpointSpecificError>
pub async fn get_system( &self, params: GetSystemParams, ) -> Result<Response<FullSystem>, NoEndpointSpecificError>
Retrieves system information.
Sourcepub async fn get_ladder(
&self,
system: Option<u32>,
) -> Result<Response<Ladder>, NoEndpointSpecificError>
pub async fn get_ladder( &self, system: Option<u32>, ) -> Result<Response<Ladder>, NoEndpointSpecificError>
Retrieves a system’s ladder ranking.
§Parameters
system: System ID to retrieve status for. If unset, theClient’s authenticated system is used. Requires donation status.
Sourcepub async fn get_outputs(
&self,
params: GetOutputParams,
) -> Result<Response<Vec<Output>>, NoEndpointSpecificError>
pub async fn get_outputs( &self, params: GetOutputParams, ) -> Result<Response<Vec<Output>>, NoEndpointSpecificError>
Retrieves daily outputs.
- For aggregated outputs (
a), useClient::get_aggregate_outputs - For team outputs (
tid), useClient::get_team_outputs
Sourcepub async fn get_aggregate_outputs(
&self,
aggregation: Aggregation,
params: GetOutputParams,
) -> Result<Response<Vec<AggregatedOutput>>, NoEndpointSpecificError>
pub async fn get_aggregate_outputs( &self, aggregation: Aggregation, params: GetOutputParams, ) -> Result<Response<Vec<AggregatedOutput>>, NoEndpointSpecificError>
Retrieves monthly or yearly aggregated outputs.
- For daily outputs, use
Client::get_outputs - For team outputs (
tid), useClient::get_team_outputs
Sourcepub async fn get_team_outputs(
&self,
team_id: u32,
params: GetOutputParams,
) -> Result<Response<Vec<TeamOutput>>, NoEndpointSpecificError>
pub async fn get_team_outputs( &self, team_id: u32, params: GetOutputParams, ) -> Result<Response<Vec<TeamOutput>>, NoEndpointSpecificError>
Retrieves daily outputs for the given team.
- For daily outputs, use
Client::get_outputs - For aggregated outputs (
a), useClient::get_aggregate_outputs
Sourcepub async fn get_extended(
&self,
params: GetExtendedParams,
) -> Result<Response<Vec<ExtendedData>>, NoEndpointSpecificError>
pub async fn get_extended( &self, params: GetExtendedParams, ) -> Result<Response<Vec<ExtendedData>>, NoEndpointSpecificError>
Retrieves daily extended output values for your system.
Requires donation status.
§Errors
Returns ClientError::NotFound if your system has no extended data for the
specified date range.
Sourcepub async fn get_favourites(
&self,
system: Option<u32>,
) -> Result<Response<Vec<FavouriteSystem>>, NoEndpointSpecificError>
pub async fn get_favourites( &self, system: Option<u32>, ) -> Result<Response<Vec<FavouriteSystem>>, NoEndpointSpecificError>
Gets a system’s favourite systems. Limited to fifty systems.
§Parameters
system: System ID to retrieve favourites for. If unset, theClient’s authenticated system is used. Requires donation status.
Sourcepub async fn get_missing(
&self,
from: Option<Date>,
to: Option<Date>,
) -> Result<Response<Vec<Date>>, NoEndpointSpecificError>
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).
Sourcepub async fn get_insolation(
&self,
params: GetInsolationParams,
) -> Result<Response<Vec<Insolation>>, NoEndpointSpecificError>
pub async fn get_insolation( &self, params: GetInsolationParams, ) -> Result<Response<Vec<Insolation>>, NoEndpointSpecificError>
Sourcepub async fn get_team(
&self,
team: u32,
) -> Result<Response<Team>, NoEndpointSpecificError>
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.
Sourcepub async fn get_supply(
&self,
region: Option<Region>,
timezone: Option<String>,
) -> Result<Response<Vec<Supply>>, NoEndpointSpecificError>
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.
Source§impl Client
impl Client
Sourcepub async fn add_outputs(
&self,
body: Vec<AddOutputParams>,
) -> Result<Response<()>, AddOutputError>
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.
§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.
Sourcepub async fn add_status(
&self,
body: AddStatusParams,
) -> Result<Response<()>, AddStatusError>
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.
Sourcepub async fn add_batch_status(
&self,
statuses: Vec<AddBatchStatusParams>,
cumulative: bool,
) -> Result<Response<Vec<BatchStatusReport>>, AddStatusError>
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.
Sourcepub async fn add_batch_status_net(
&self,
statuses: Vec<AddNetBatchStatusParams>,
) -> Result<Response<Vec<BatchStatusReport>>, AddStatusError>
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.
Sourcepub async fn post_system(
&self,
system: PostSystemParams,
) -> Result<Response<()>, PostSystemError>
pub async fn post_system( &self, system: PostSystemParams, ) -> Result<Response<()>, PostSystemError>
Updates system configuration.
§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 nolabel. Theu8value carried by this variant refers to the variable that was missing itslabel. - [
DataError::MissingExtendedDataUnit]: The same as above, but for theunitfield. - [
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).
Sourcepub async fn delete_status(
&self,
date: Date,
time: Option<Time>,
) -> Result<Response<()>, DateTimeError>
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.
Source§impl Client
impl Client
Sourcepub fn new(
api_key: &str,
system_id: u32,
user_agent: Option<&str>,
timeout: Option<Duration>,
) -> Result<Self, NoEndpointSpecificError>
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_agentwill 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)?;Sourcepub fn new_with_reqwest(
api_key: &str,
system_id: u32,
reqwest: Client,
) -> Result<Self, NoEndpointSpecificError>
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)?;Sourcepub const fn default_user_agent() -> &'static str
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
Sourcepub async fn search(
&self,
params: SearchParams,
) -> Result<Response<Vec<SearchResult>>, NoEndpointSpecificError>
pub async fn search( &self, params: SearchParams, ) -> Result<Response<Vec<SearchResult>>, NoEndpointSpecificError>
Searches systems. Limited to a maximum of 30 results.