Enable consumer invocation in fetcher
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import { type Tauron } from "../tauron";
|
||||
import { Measurement } from "./types";
|
||||
import { consume } from "../consumers";
|
||||
import { Config } from "../config";
|
||||
|
||||
export class Fetcher {
|
||||
#config: Config;
|
||||
#service: Tauron;
|
||||
|
||||
constructor(service: Tauron) {
|
||||
constructor(config: Config, service: Tauron) {
|
||||
this.#config = config;
|
||||
this.#service = service;
|
||||
}
|
||||
|
||||
@@ -23,11 +27,15 @@ export class Fetcher {
|
||||
const energyForYear = await this.#service.getEnergyForYear(date.format('YYYY'));
|
||||
const reading = await this.#service.getReadingForRange(date, date);
|
||||
|
||||
return {
|
||||
const measurement: Measurement = {
|
||||
energyForDay,
|
||||
energyForMonth,
|
||||
energyForYear,
|
||||
reading: reading?.[0],
|
||||
};
|
||||
|
||||
consume(this.#config, date, measurement);
|
||||
|
||||
return measurement;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user