Skip to content

Commit

Permalink
Do not log Goodwe's daily production total if less than current
Browse files Browse the repository at this point in the history
If the currently obtained value for the daily produced energy in kWh is
higher than reported by the Goodwe api, we should not record Goodwe's
value but keep the current value in the database.

The total daily production is logged hourly and should not decrease over
daytime, only increase.
  • Loading branch information
Jhnbrn90 committed Nov 10, 2023
1 parent 567c243 commit 253ebd6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/Console/Commands/StoreDailyYield.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ public function handle(): void
->dailyProductionLogs()
->firstOrNew(['created_at' => Carbon::today()]);

$log->total_production = $powerStation->energyProducedToday() * 1000;
// The total_production is set to 0 for non-existing
// production logs.
if (! $log->exists) {
$log->total_production = 0;
}

$energyProducedToday = $powerStation->energyProducedToday() * 1000;

// Do not update daily production when retrieved value is
// less than currently registered value.
if ($energyProducedToday > $log->total_production) {
$log->total_production = $energyProducedToday;
$log->save();
}

$log->save();
});

$this->info('Done');
Expand Down

0 comments on commit 253ebd6

Please sign in to comment.