diff --git a/TeslaSolarCharger/Server/ServerValidators/CarBasicConfigurationValidator.cs b/TeslaSolarCharger/Server/ServerValidators/CarBasicConfigurationValidator.cs index c1b02c257..f1834fe58 100644 --- a/TeslaSolarCharger/Server/ServerValidators/CarBasicConfigurationValidator.cs +++ b/TeslaSolarCharger/Server/ServerValidators/CarBasicConfigurationValidator.cs @@ -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) { diff --git a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs index 1a711dc0f..0760c95ea 100644 --- a/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs +++ b/TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs @@ -827,6 +827,18 @@ private async Task WakeUpCarIfNeeded(int carId) private async Task?> SendCommandToTeslaApi(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 diff --git a/TeslaSolarCharger/Server/Services/TokenHelper.cs b/TeslaSolarCharger/Server/Services/TokenHelper.cs index 6922b76cd..9b299ffd4 100644 --- a/TeslaSolarCharger/Server/Services/TokenHelper.cs +++ b/TeslaSolarCharger/Server/Services/TokenHelper.cs @@ -31,7 +31,7 @@ public async Task 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; } @@ -45,7 +45,7 @@ public async Task 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; }