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

if (r4.ContainsKey("tokens") && r4["tokens"] != null) #1334

Merged
Merged
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
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
Loading