Skip to content

Commit

Permalink
fix(TeslaFleetApiService): add latest value before last refresh to de…
Browse files Browse the repository at this point in the history
…tect if calling Tesla API is required
  • Loading branch information
pkuehnel committed Dec 1, 2024
1 parent 0cdd71b commit 74445f8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,31 @@ private async Task<List<CarValueLogTimeStampAndValues>> GetValuesSince(int carId
InvalidValue = c.InvalidValue,
})
.ToListAsync();
return values;

var lastBeforeStartTimeValue = await teslaSolarChargerContext.CarValueLogs
.Where(c => c.Type == carValueType
&& c.Source == CarValueSource.FleetTelemetry
&& c.CarId == carId
&& c.Timestamp <= startTime)
.OrderByDescending(c => c.Timestamp)
.Select(c => new CarValueLogTimeStampAndValues
{
Timestamp = c.Timestamp,
DoubleValue = c.DoubleValue,
IntValue = c.IntValue,
StringValue = c.StringValue,
UnknownValue = c.UnknownValue,
BooleanValue = c.BooleanValue,
InvalidValue = c.InvalidValue,
})
.FirstOrDefaultAsync(); // Use FirstOrDefault to get the single latest value before startTime

// Combine the results
if (lastBeforeStartTimeValue != null)
{
values.Add(lastBeforeStartTimeValue); // Add the value before startTime if it exists
}
return values.OrderByDescending(v => v.Timestamp).ToList();
}


Expand Down

0 comments on commit 74445f8

Please sign in to comment.