From c4d3c9c571c841f8fa300e334d5ad76d83b99931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 26 Jan 2025 09:54:54 +0100 Subject: [PATCH 1/3] fix(TokenHelper): set correct value on fleet api token expiry cache --- TeslaSolarCharger/Server/Services/TokenHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } From d073118f261c84b096dabb432f152ecf1df9144f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 26 Jan 2025 11:45:11 +0100 Subject: [PATCH 2/3] fix(CarBasicConfigurationValidator): do not show PLease disable on already disabled error --- .../ServerValidators/CarBasicConfigurationValidator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) { From 7d8a5797ccdb2ff5739277b27425b1598e095da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Sun, 26 Jan 2025 11:48:01 +0100 Subject: [PATCH 3/3] fix(TeslaFleetApiService): do not send commands if fleet telemetry is not connected but should be --- .../Server/Services/TeslaFleetApiService.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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