Skip to content

Commit

Permalink
increase interval precision
Browse files Browse the repository at this point in the history
  • Loading branch information
zivillian committed Apr 10, 2024
1 parent a1a0d6f commit 0242291
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ora2mqtt/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ public async Task<int> Run(CancellationToken cancellationToken)

using var mqtt = await ConnectMqttAsync(config.Mqtt, cancellationToken);

var api = GetGwmApiClient(config, cancellationToken);
var api = GetGwmApiClient(config);

try
{
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(Intervall));
while (!cancellationToken.IsCancellationRequested)
{
await RefreshTokenAsync(api, config, cancellationToken);
await PublishStatusAsync(mqtt, api, cancellationToken);
await Task.Delay(Intervall * 1000, cancellationToken);
await timer.WaitForNextTickAsync(cancellationToken);
}
}
catch (TaskCanceledException)
Expand Down Expand Up @@ -72,7 +73,7 @@ private async Task<IMqttClient> ConnectMqttAsync(Ora2MqttMqttOptions options,Can
return client;
}

private GwmApiClient GetGwmApiClient(Ora2MqttOptions options, CancellationToken cancellationToken)
private GwmApiClient GetGwmApiClient(Ora2MqttOptions options)
{
var client = ConfigureApiClient(options);
client.SetAccessToken(options.Account.AccessToken);
Expand Down

0 comments on commit 0242291

Please sign in to comment.