Enable consumer invocation in fetcher

This commit is contained in:
2024-11-13 18:28:33 +01:00
parent 252b920119
commit d2ef1b8a3e

View File

@@ -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;
}
};