Skip to content

Commit

Permalink
Adding lower default timeout for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
DrEsteban committed Nov 24, 2024
1 parent ccc35b1 commit f142d9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Models/EnphaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public class EnphaseConfiguration

[RequiredIf(nameof(Enabled), true)]
public string Host { get; set; } = string.Empty;

/// <summary>
/// Timeout for requests to the gateway.
/// </summary>
public int RequestTimeoutSeconds { get; set; } = 10;
}
5 changes: 5 additions & 0 deletions src/Models/TeslaConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class TeslaConfiguration
[RequiredIf(nameof(Enabled), true)]
public string RequestHost { get; set; } = "powerwall";

/// <summary>
/// Timeout for requests to the Tesla Gateway.
/// </summary>
public int RequestTimeoutSeconds { get; set; } = 10;

public TeslaLoginRequest GetTeslaLoginRequest()
=> new()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
client.BaseAddress = new Uri($"https://{teslaConfig.Host}");
// The Tesla Gateway only accepts a certain set of Host header values
client.DefaultRequestHeaders.Host = teslaConfig.RequestHost;
client.Timeout = TimeSpan.FromSeconds(teslaConfig.RequestTimeoutSeconds);
})
.ConfigurePrimaryHttpMessageHandler(_ =>
{
Expand All @@ -160,6 +161,7 @@
{
var enphaseConfig = c.GetRequiredService<IOptions<EnphaseConfiguration>>().Value;
client.BaseAddress = new Uri($"http://{enphaseConfig.Host}");
client.Timeout = TimeSpan.FromSeconds(enphaseConfig.RequestTimeoutSeconds);
})
.UseHttpClientMetrics()
.RemoveAllLoggers()
Expand Down

0 comments on commit f142d9d

Please sign in to comment.