Skip to content

Commit

Permalink
Merge pull request #1782 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Jan 26, 2025
2 parents 5103131 + a73c378 commit d11a110
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public CarBasicConfigurationValidator(IConfigurationWrapper configurationWrapper
.FirstOrDefaultAsync();
if (isCarFleetTelemetryHardwareIncompatible)
{
context.AddFailure("The selected car is not compatible with Fleet Telemetry. Please disable Fleet Telemetry.");
if (fleetTelemetryEnabled)
{
context.AddFailure("The selected car is not compatible with Fleet Telemetry. Please disable Fleet Telemetry.");
}
}
else if (fleetTelemetryEnabled != true)
{
Expand Down
12 changes: 12 additions & 0 deletions TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,18 @@ private async Task WakeUpCarIfNeeded(int carId)
private async Task<DtoGenericTeslaResponse<T>?> SendCommandToTeslaApi<T>(string vin, DtoFleetApiRequest fleetApiRequest, int? intParam = null) where T : class
{
logger.LogTrace("{method}({vin}, {@fleetApiRequest}, {intParam})", nameof(SendCommandToTeslaApi), vin, fleetApiRequest, intParam);
var fleetTelemetryEnabled = await teslaSolarChargerContext.Cars
.Where(c => c.Vin == vin)
.Select(c => c.UseFleetTelemetry)
.FirstAsync();
if (fleetTelemetryEnabled)
{
if(!fleetTelemetryWebSocketService.IsClientConnected(vin))
{
logger.LogError("Do not send command to car {vin} as Fleet Telemetry is enabled but client is not connected", vin);
return null;
}
}
if (await tokenHelper.GetBackendTokenState(true) != TokenState.UpToDate)
{
//Do not show base api not licensed error if not connected to backend
Expand Down
4 changes: 2 additions & 2 deletions TeslaSolarCharger/Server/Services/TokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<TokenState> GetFleetApiTokenState(bool useCache)
}
var state = await GetUncachedFleetApiTokenState().ConfigureAwait(false);
memoryCache.Set(constants.FleetApiTokenStateKey, state.TokenState, GetCacheEntryOptions(state.ExpiresAtUtc));
memoryCache.Set(constants.FleetApiTokenExpirationTimeKey, state, GetCacheEntryOptions(state.ExpiresAtUtc));
memoryCache.Set(constants.FleetApiTokenExpirationTimeKey, state.ExpiresAtUtc, GetCacheEntryOptions(state.ExpiresAtUtc));
return state.TokenState;
}

Expand All @@ -45,7 +45,7 @@ public async Task<TokenState> GetFleetApiTokenState(bool useCache)
}
var state = await GetUncachedFleetApiTokenState().ConfigureAwait(false);
memoryCache.Set(constants.FleetApiTokenStateKey, state.TokenState, GetCacheEntryOptions(state.ExpiresAtUtc));
memoryCache.Set(constants.FleetApiTokenExpirationTimeKey, state, GetCacheEntryOptions(state.ExpiresAtUtc));
memoryCache.Set(constants.FleetApiTokenExpirationTimeKey, state.ExpiresAtUtc, GetCacheEntryOptions(state.ExpiresAtUtc));
return state.ExpiresAtUtc;
}

Expand Down

0 comments on commit d11a110

Please sign in to comment.