-
Notifications
You must be signed in to change notification settings - Fork 447
/
Copy pathqueryHistoricTimeseriesEnergyPerPeriodRequest.ts
52 lines (46 loc) · 1.52 KB
/
queryHistoricTimeseriesEnergyPerPeriodRequest.ts
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
// @ts-strict-ignore
import { format } from "date-fns";
import { Resolution } from "src/app/edge/history/shared";
import { ChannelAddress } from "../../type/channeladdress";
import { JsonrpcRequest } from "../base";
import { JsonRpcUtils } from "../jsonrpcutils";
/**
* Represents a JSON-RPC Request to query Timeseries Energy data.
*
* <pre>
* {
* "jsonrpc": "2.0",
* "id": UUID,
* "method": "queryHistoricTimeseriesEnergyPerPeriod",
* "params": {
* "timezone": Number,
* "fromDate": YYYY-MM-DD,
* "toDate": YYYY-MM-DD,
* "channels": ChannelAddress[],
* "resolution": Number
* }
* }
* </pre>
*/
export class QueryHistoricTimeseriesEnergyPerPeriodRequest extends JsonrpcRequest {
private static METHOD: string = "queryHistoricTimeseriesEnergyPerPeriod";
public constructor(
private fromDate: Date,
private toDate: Date,
private channels: ChannelAddress[],
private resolution: Resolution,
) {
super(QueryHistoricTimeseriesEnergyPerPeriodRequest.METHOD, {
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
fromDate: format(fromDate, "yyyy-MM-dd"),
toDate: format(toDate, "yyyy-MM-dd"),
channels: JsonRpcUtils.channelsToStringArray(channels),
resolution: resolution,
});
// delete local fields, otherwise they are sent with the JSON-RPC Request
delete this.fromDate;
delete this.toDate;
delete this.channels;
delete this.resolution;
}
}