Skip to content

Commit

Permalink
Merge pull request bassmaster187#1334 from superfloh247/bugfix-vehicl…
Browse files Browse the repository at this point in the history
…e-tokens-null

if (r4.ContainsKey("tokens") && r4["tokens"] != null)
  • Loading branch information
bassmaster187 authored Jul 10, 2024
2 parents 84f2fd9 + 7bd3be9 commit 6153a03
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions TeslaLogger/WebHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ public string GetRegion()
}

HttpClient httpClientTeslaAPI = GetHttpClientTeslaAPI();
using (var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://teslalogger.de:4444/api/1/users/region"))) {
using (var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://teslalogger.de:4444/api/1/users/region")))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Tesla_token);
Tools.DebugLog($"GetRegion #{car.CarInDB} request: {request.RequestUri}");
HttpResponseMessage response = httpClientTeslaAPI.SendAsync(request).Result;
Expand Down Expand Up @@ -1606,9 +1607,10 @@ public void ResetLastChargingState()

internal bool IsCharging(bool justCheck = false, bool noMemcache = false)
{
if (car.FleetAPI && justCheck) {
return car.telemetry?.IsCharging ?? false;
}
if (car.FleetAPI && justCheck)
{
return car.telemetry?.IsCharging ?? false;
}

string resultContent = "";
try
Expand Down Expand Up @@ -2474,14 +2476,13 @@ public async Task<string> IsOnline(bool returnOnUnauthorized = false)
}

string state = r4["state"].ToString();
string temp_Tesla_Streamingtoken = r4["tokens"][0].ToString();

if (temp_Tesla_Streamingtoken != Tesla_Streamingtoken)
if (r4.ContainsKey("tokens") && r4["tokens"] != null)
{
Tesla_Streamingtoken = temp_Tesla_Streamingtoken;
//Log("Streamingtoken changed (IsOnline): " + Tools.ObfuscateString(Tesla_Streamingtoken));

// can be ignored, is not used at the moment car.Log("Tesla_Streamingtoken changed!");
string temp_Tesla_Streamingtoken = r4["tokens"][0].ToString();
if (temp_Tesla_Streamingtoken != Tesla_Streamingtoken)
{
Tesla_Streamingtoken = temp_Tesla_Streamingtoken;
}
}

try
Expand Down Expand Up @@ -3258,8 +3259,8 @@ public bool IsDriving(bool justinsertdb = false)
if (car.FleetAPI && !justinsertdb)
{
if (car.telemetry?.Driving == false)
{
return false;
{
return false;
}
}

Expand Down Expand Up @@ -4942,7 +4943,7 @@ public async Task<string> GetCommand(string cmd, bool noMemcache = false)
{
sleep = sleep * 1000;
}
else
else
{
sleep = (random.Next(5000) + 60000) * 1000;
}
Expand All @@ -4958,7 +4959,7 @@ public async Task<string> GetCommand(string cmd, bool noMemcache = false)
if (result.Headers.TryGetValues("ratelimit-reset", out var v3))
l += ", ratelimit-reset: " + v3.First();

l += ", sleep till: "+ DateTime.Now.AddMilliseconds(sleep).ToString(Tools.ciDeDE);
l += ", sleep till: " + DateTime.Now.AddMilliseconds(sleep).ToString(Tools.ciDeDE);

l += $", CommandCounter: {commandCounter} Drive: {commandCounterDrive} Charge: {commandCounterCharging} Online: {commandcounterOnline}";

Expand All @@ -4969,7 +4970,7 @@ public async Task<string> GetCommand(string cmd, bool noMemcache = false)

car.CreateExeptionlessLog("TooManyRequests", l, LogLevel.Warn).Submit();

Log(l1+l);
Log(l1 + l);
car.CurrentJSON.FatalError += " TooManyRequests";
car.CurrentJSON.CreateCurrentJSON();
Thread.Sleep(sleep);
Expand Down Expand Up @@ -5848,7 +5849,7 @@ internal static bool BranchExists(string branch, out HttpStatusCode statusCode)
else if (g.StatusCode == HttpStatusCode.NotFound)
{
return false;
}
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 6153a03

Please sign in to comment.