1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//! Read-only API endpoint methods.
use const_format::formatcp;
use jiff::civil::Date;
use serde::Serialize;
use crate::{
API_BASE_URL, Client, parser,
parser::parse_none,
types::{
error::NoEndpointSpecificError,
params::{
Aggregation, GetExtendedParams, GetInsolationParams, GetOutputParams, GetOutputParamsOuter, GetStatisticsParams,
GetStatusParams, GetStatusParamsOuter, GetSystemParams,
},
regions::Region,
response::{
AggregatedOutput, DailyStatus, ExtendedData, FavouriteSystem, FullSystem, History, Insolation, Ladder, Output,
Response, Statistics, Status, Supply, Team, TeamOutput,
},
},
};
impl Client {
/// Retrieves a single status for the specified system.
///
/// - For historic data (`h`), use [`Client::get_status_history`]
/// - For statistics (`stats`), use [`Client::get_status_daily`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-status-service)
pub async fn get_status(&self, params: GetStatusParams) -> crate::Result<Response<Status>, NoEndpointSpecificError> {
self
.get_single(
formatcp!("{API_BASE_URL}/getstatus.jsp"),
GetStatusParamsOuter::new(params, false, false),
parse_none,
)
.await
}
/// Retrieves historic statuses for the specified system.
///
/// - For a single measurement, use [`Client::get_status`]
/// - For statistics (`stats`), use [`Client::get_status_daily`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-status-service)
pub async fn get_status_history(
&self,
params: GetStatusParams,
) -> crate::Result<Response<Vec<History>>, NoEndpointSpecificError> {
self
.get_multiple(
formatcp!("{API_BASE_URL}/getstatus.jsp"),
GetStatusParamsOuter::new(params, true, false),
parse_none,
)
.await
}
/// Retrieves a daily stats summary for the specified system.
///
/// - For historic data (`h`), use [`Client::get_status_history`]
/// - For a single measurement, use [`Client::get_status`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-status-service)
pub async fn get_status_daily(
&self,
params: GetStatusParams,
) -> crate::Result<Response<DailyStatus>, NoEndpointSpecificError> {
let (rate_limit, response) = self
.get(
formatcp!("{API_BASE_URL}/getstatus.jsp"),
GetStatusParamsOuter::new(params, false, true),
parse_none,
)
.await?;
Ok(Response::new(parser::daily_status(&response)?, rate_limit))
}
/// 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](https://pvoutput.org/help/donations.html).
///
/// This information is not exposed by the API -- the `rate_limit` on the `Response` struct will not reflect these
/// limits.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-statistic-service)
pub async fn get_statistics(
&self,
params: GetStatisticsParams,
) -> crate::Result<Response<Statistics>, NoEndpointSpecificError> {
let (rate_limit, response) = self.get(formatcp!("{API_BASE_URL}/getstatistic.jsp"), ¶ms, parse_none).await?;
Ok(Response::new(parser::statistics(&response, ¶ms)?, rate_limit))
}
/// Retrieves system information.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-system-service)
pub async fn get_system(
&self,
params: GetSystemParams,
) -> crate::Result<Response<FullSystem>, NoEndpointSpecificError> {
let (rate_limit, response) = self.get(formatcp!("{API_BASE_URL}/getsystem.jsp"), ¶ms, parse_none).await?;
Ok(Response::new(parser::system(&response, ¶ms)?, rate_limit))
}
/// Retrieves a system's ladder ranking.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-ladder-service)
///
/// # Parameters
/// - `system`: System ID to retrieve status for.
/// If unset, the [`Client`]'s authenticated system is used.
/// Requires [donation status](https://pvoutput.org/help/donations.html).
pub async fn get_ladder(&self, system: Option<u32>) -> crate::Result<Response<Ladder>, NoEndpointSpecificError> {
self.get_single(formatcp!("{API_BASE_URL}/getladder.jsp"), &[("sid1", system)], parse_none).await
}
/// Retrieves daily outputs.
///
/// - For aggregated outputs (`a`), use [`Client::get_aggregate_outputs`]
/// - For team outputs (`tid`), use [`Client::get_team_outputs`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-output-service)
pub async fn get_outputs(
&self,
params: GetOutputParams,
) -> crate::Result<Response<Vec<Output>>, NoEndpointSpecificError> {
let params = GetOutputParamsOuter {
params,
..Default::default()
};
let (rate_limit, response) = self.get(formatcp!("{API_BASE_URL}/getoutput.jsp"), ¶ms, parse_none).await?;
Ok(Response::new(parser::outputs(&response, ¶ms.params)?, rate_limit))
}
/// Retrieves monthly or yearly aggregated outputs.
///
/// - For daily outputs, use [`Client::get_outputs`]
/// - For team outputs (`tid`), use [`Client::get_team_outputs`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-output-service)
pub async fn get_aggregate_outputs(
&self,
aggregation: Aggregation,
params: GetOutputParams,
) -> crate::Result<Response<Vec<AggregatedOutput>>, NoEndpointSpecificError> {
let params = GetOutputParamsOuter {
params,
a: Some(aggregation),
..Default::default()
};
let (rate_limit, response) = self.get(formatcp!("{API_BASE_URL}/getoutput.jsp"), ¶ms, parse_none).await?;
Ok(Response::new(parser::aggregate_outputs(&response, params.params.time_of_export)?, rate_limit))
}
/// Retrieves daily outputs for the given team.
///
/// - For daily outputs, use [`Client::get_outputs`]
/// - For aggregated outputs (`a`), use [`Client::get_aggregate_outputs`]
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-output-service)
pub async fn get_team_outputs(
&self,
team_id: u32,
params: GetOutputParams,
) -> crate::Result<Response<Vec<TeamOutput>>, NoEndpointSpecificError> {
self
.get_multiple(
formatcp!("{API_BASE_URL}/getoutput.jsp"),
GetOutputParamsOuter {
params,
tid: Some(team_id),
..Default::default()
},
parse_none,
)
.await
}
/// Retrieves daily extended output values for your system.
///
/// Requires [donation status](https://pvoutput.org/help/donations.html).
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-extended-service)
///
/// # Errors
/// Returns [`ClientError::NotFound`](crate::ClientError::NotFound) if your system has no extended data for the
/// specified date range.
pub async fn get_extended(
&self,
params: GetExtendedParams,
) -> crate::Result<Response<Vec<ExtendedData>>, NoEndpointSpecificError> {
self.get_multiple(formatcp!("{API_BASE_URL}/getextended.jsp"), ¶ms, parse_none).await
}
/// Gets a system's favourite systems.
/// Limited to fifty systems.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-favourite-service)
///
/// # Parameters
/// - `system`: System ID to retrieve favourites for.
/// If unset, the [`Client`]'s authenticated system is used.
/// Requires [donation status](https://pvoutput.org/help/donations.html).
pub async fn get_favourites(
&self,
system: Option<u32>,
) -> crate::Result<Response<Vec<FavouriteSystem>>, NoEndpointSpecificError> {
let (rate_limit, response) =
self.get(formatcp!("{API_BASE_URL}/getfavourite.jsp"), &[("sid1", system)], parse_none).await?;
Ok(Response::new(parser::favourites(&response)?, rate_limit))
}
/// 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](https://pvoutput.org/help/api_specification.html#get-missing-service)
pub async fn get_missing(
&self,
from: Option<Date>,
to: Option<Date>,
) -> crate::Result<Response<Vec<Date>>, NoEndpointSpecificError> {
self
.get_single(
formatcp!("{API_BASE_URL}/getmissing.jsp"),
&[
("df", from.map(|d| d.strftime("%Y%m%d").to_string())),
("dt", to.map(|d| d.strftime("%Y%m%d").to_string())),
],
parse_none,
)
.await
}
/// Retrieves insolation data at five minute intervals.
///
/// Requires [donation status](https://pvoutput.org/help/donations.html).
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-insolation-service)
pub async fn get_insolation(
&self,
params: GetInsolationParams,
) -> crate::Result<Response<Vec<Insolation>>, NoEndpointSpecificError> {
self.get_multiple(formatcp!("{API_BASE_URL}/getinsolation.jsp"), ¶ms, parse_none).await
}
/// Retrieves team data.
///
/// Only team owners may retrieve details of their own team.
/// [Donation-enabled](https://pvoutput.org/help/donations.html) accounts may query any team.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-team-service)
pub async fn get_team(&self, team: u32) -> crate::Result<Response<Team>, NoEndpointSpecificError> {
// why is this a semicolon-delimited response??
let (rate_limit, response) =
self.get(formatcp!("{API_BASE_URL}/getteam.jsp"), &[("tid", team)], parse_none).await?;
Ok(Response::new(
Self::semicolon_reader(&response).deserialize().collect::<csv::Result<Vec<_>>>()?.remove(0),
rate_limit,
))
}
/// 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](https://pvoutput.org/help/donations.html).
/// - `timezone`: Timezone to use in responses.
/// If unset, data will be returned in UTC.
///
/// [PVOutput docs](https://pvoutput.org/help/api_specification.html#get-supply-service)
pub async fn get_supply(
&self,
region: Option<Region>,
timezone: Option<String>,
) -> crate::Result<Response<Vec<Supply>>, NoEndpointSpecificError> {
#[derive(Serialize)]
struct Params {
r: Option<Region>,
tz: Option<String>,
}
let params = Params {
r: region,
tz: timezone,
};
self.get_multiple(formatcp!("{API_BASE_URL}/getsupply.jsp"), ¶ms, parse_none).await
}
}