Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1782

Merged
merged 6 commits into from
Jan 26, 2025
Merged

Develop #1782

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading