Make Tauron service supports Dayjs
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"axios-cookiejar-support": "^5.0.3",
|
"axios-cookiejar-support": "^5.0.3",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"tough-cookie": "^5.0.0",
|
"tough-cookie": "^5.0.0",
|
||||||
"tough-cookie-file-store": "^2.0.3",
|
"tough-cookie-file-store": "^2.0.3",
|
||||||
"yaml": "^2.6.0"
|
"yaml": "^2.6.0"
|
||||||
@@ -469,6 +470,11 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dayjs": {
|
||||||
|
"version": "1.11.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz",
|
||||||
|
"integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg=="
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.7",
|
"version": "4.3.7",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"axios-cookiejar-support": "^5.0.3",
|
"axios-cookiejar-support": "^5.0.3",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"tough-cookie": "^5.0.0",
|
"tough-cookie": "^5.0.0",
|
||||||
"tough-cookie-file-store": "^2.0.3",
|
"tough-cookie-file-store": "^2.0.3",
|
||||||
"yaml": "^2.6.0"
|
"yaml": "^2.6.0"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { CookieJar } from 'tough-cookie';
|
|||||||
import { FileCookieStore } from 'tough-cookie-file-store';
|
import { FileCookieStore } from 'tough-cookie-file-store';
|
||||||
import { EnergyDTO, EnergyRequestDTO, Payload, PowerDTO, PowerRequestDTO, ReadingDTO, ReadingRequestDTO } from "./types";
|
import { EnergyDTO, EnergyRequestDTO, Payload, PowerDTO, PowerRequestDTO, ReadingDTO, ReadingRequestDTO } from "./types";
|
||||||
import { TauronConfig } from '../config';
|
import { TauronConfig } from '../config';
|
||||||
|
import { Dayjs } from 'dayjs';
|
||||||
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|
||||||
@@ -13,12 +14,14 @@ const BASE_URL = 'https://elicznik.tauron-dystrybucja.pl';
|
|||||||
const ENERGY_API = '/energia/api';
|
const ENERGY_API = '/energia/api';
|
||||||
const POWER_API = '/moc/api';
|
const POWER_API = '/moc/api';
|
||||||
const READING_API = '/odczyty/api';
|
const READING_API = '/odczyty/api';
|
||||||
|
const DATE_FORMAT = 'DD.MM.YYYY';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for Tauron API.
|
* Utility class for Tauron API.
|
||||||
* @param config - configuration of service
|
* @param config - configuration of service
|
||||||
*/
|
*/
|
||||||
export const Tauron = class {
|
export class Tauron {
|
||||||
#http: Axios;
|
#http: Axios;
|
||||||
#config: TauronConfig;
|
#config: TauronConfig;
|
||||||
|
|
||||||
@@ -113,12 +116,14 @@ export const Tauron = class {
|
|||||||
* @param type - type of measurement, can be 'consum' (regular one) or 'average'
|
* @param type - type of measurement, can be 'consum' (regular one) or 'average'
|
||||||
* @returns the energy data from Tauron API
|
* @returns the energy data from Tauron API
|
||||||
*/
|
*/
|
||||||
async getEnergyForDay(day: string): Promise<EnergyDTO> {
|
async getEnergyForDay(day: Dayjs): Promise<EnergyDTO> {
|
||||||
|
const date = day.format(DATE_FORMAT);
|
||||||
|
|
||||||
return await this.getEnergy({
|
return await this.getEnergy({
|
||||||
type: 'consum',
|
type: 'consum',
|
||||||
profile: "full time",
|
profile: "full time",
|
||||||
from: day,
|
from: date,
|
||||||
to: day,
|
to: date,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,11 +134,11 @@ export const Tauron = class {
|
|||||||
* @param type - type of measurement, can be 'consum' (regular one) or 'average'
|
* @param type - type of measurement, can be 'consum' (regular one) or 'average'
|
||||||
* @returns the energy data from Tauron API
|
* @returns the energy data from Tauron API
|
||||||
*/
|
*/
|
||||||
async getEnergyForRange(from: string, to: string): Promise<EnergyDTO> {
|
async getEnergyForRange(from: Dayjs, to: Dayjs): Promise<EnergyDTO> {
|
||||||
return await this.getEnergy({
|
return await this.getEnergy({
|
||||||
type: 'consum',
|
type: 'consum',
|
||||||
from,
|
from: from.format(DATE_FORMAT),
|
||||||
to,
|
to: to.format(DATE_FORMAT),
|
||||||
profile: "range"
|
profile: "range"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -168,8 +173,11 @@ export const Tauron = class {
|
|||||||
* @param to - the measurement ending date
|
* @param to - the measurement ending date
|
||||||
* @returns the power data from Tauron API
|
* @returns the power data from Tauron API
|
||||||
*/
|
*/
|
||||||
async getPowerForRange(from: string, to: string): Promise<PowerDTO[]> {
|
async getPowerForRange(from: Dayjs, to: Dayjs): Promise<PowerDTO[]> {
|
||||||
return await this.getPower({ from, to });
|
return await this.getPower({
|
||||||
|
from: from.format(DATE_FORMAT),
|
||||||
|
to: to.format(DATE_FORMAT)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,10 +195,10 @@ export const Tauron = class {
|
|||||||
* @param to - the measurement ending date
|
* @param to - the measurement ending date
|
||||||
* @returns the readings from Tauron API
|
* @returns the readings from Tauron API
|
||||||
*/
|
*/
|
||||||
async getReadingForRange(from: string, to: string): Promise<ReadingDTO[]> {
|
async getReadingForRange(from: Dayjs, to: Dayjs): Promise<ReadingDTO[]> {
|
||||||
return await this.getReading({
|
return await this.getReading({
|
||||||
from,
|
from: from.format(DATE_FORMAT),
|
||||||
to,
|
to: to.format(DATE_FORMAT),
|
||||||
type: 'energia-pobrana',
|
type: 'energia-pobrana',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user