Skip to content

Commit

Permalink
fix(lib): show warning only once if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
manushak committed Apr 10, 2024
1 parent c8118f7 commit 50cf99b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/watt-time/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const WattTimeGridEmissions = (): PluginInterface => {
const metadata = {kind: 'execute'};
const wattTimeAPI = WattTimeAPI();
const errorBuilder = buildErrorMessage(WattTimeGridEmissions.name);
let isWarned = false;

/**
* Initialize authentication with global config.
Expand Down Expand Up @@ -90,11 +91,13 @@ export const WattTimeGridEmissions = (): PluginInterface => {
const schema = z
.object({
duration: z.number().refine(value => {
if (value < 300) {
if (value < 300 && !isWarned) {
isWarned = true;
console.warn(
'WARN (Watt-TIME): your timestamps are spaced less than 300s apart. The minimum resolution of the Watt-time API is 300s. To account for this, we make API requests every 300s and interpolate the values in between. To use real Watt-time data only, change your time resolution to >= 300 seconds.'
);
}

return value;
}),
timestamp: z.string(),
Expand Down

0 comments on commit 50cf99b

Please sign in to comment.