Skip to content

Commit

Permalink
HassClient bump, better socket close n cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Apr 9, 2020
1 parent 6a5660d commit 90b0f25
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/NetDaemon.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JoySoftware.HassClient" Version="0.0.30-alpha" />
<PackageReference Include="JoySoftware.HassClient" Version="0.0.31-alpha" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.1" />
</ItemGroup>

Expand Down
9 changes: 7 additions & 2 deletions src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NetDaemonHost : INetDaemonHost
/// <summary>
/// The intervall used when disconnected
/// </summary>
private const int _reconnectIntervall = 30000;
private const int _reconnectIntervall = 40000;

internal readonly Channel<(string, string)> _ttsMessageQueue =
Channel.CreateBounded<(string, string)>(20);
Expand Down Expand Up @@ -132,10 +132,13 @@ public IEntity Entities(Func<IEntityProperties, bool> func)
: null;
}

/// <inheritdoc/>
public void ListenEvent(string ev, Func<string, dynamic, Task> action) => _eventActions.Add((ev, action));

/// <inheritdoc/>
public void ListenEvent(Func<FluentEventProperty, bool> funcSelector, Func<string, dynamic, Task> func) => _eventFunctionList.Add((funcSelector, func));

/// <inheritdoc/>
public void ListenServiceCall(string domain, string service, Func<dynamic?, Task> action)
=> _serviceCallFunctionList.Add((domain.ToLowerInvariant(), service.ToLowerInvariant(), action));

Expand All @@ -149,6 +152,8 @@ public void ListenServiceCall(string domain, string service, Func<dynamic?, Task
_stateActions[uniqueId] = (pattern, action);
return uniqueId.ToString();
}

/// <inheritdoc/>
public void CancelListenState(string id)
{
// Remove and ignore if not exist
Expand Down Expand Up @@ -240,7 +245,7 @@ public async Task Run(string host, short port, bool ssl, string token, Cancellat
if (!connectResult)
{
Connected = false;
Logger.LogWarning("Home assistant is unavailable, retrying in 30 seconds...");
Logger.LogWarning($"Home assistant is unavailable, retrying in {_reconnectIntervall} seconds...");
await _hassClient.CloseAsync().ConfigureAwait(false);
await Task.Delay(_reconnectIntervall, cancellationToken).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

</PropertyGroup>
<ItemGroup>
<PackageReference Include="JoySoftware.HassClient" Version="0.0.30-alpha" />
<PackageReference Include="JoySoftware.HassClient" Version="0.0.31-alpha" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/DaemonRunner/DaemonRunner/DaemonRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

</PropertyGroup>
<ItemGroup>
<PackageReference Include="JoySoftware.HassClient" Version="0.0.30-alpha" />
<PackageReference Include="JoySoftware.HassClient" Version="0.0.31-alpha" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.5.0" />
<!-- <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.5.0-beta2-final" /> -->
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
Expand Down
6 changes: 3 additions & 3 deletions src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}
else
{
_logger.LogWarning("Home assistant still unavailable, retrying in 30 seconds...");
_logger.LogWarning("Home assistant still unavailable, retrying in 40 seconds...");
}
}
}
catch (OperationCanceledException)
{
if (!stoppingToken.IsCancellationRequested)
{
_logger.LogWarning("Home assistant disconnected!, retrying in 30 seconds...");
_logger.LogWarning("Home assistant disconnected!, retrying in 40 seconds...");
}
}

if (!stoppingToken.IsCancellationRequested)
// The service is still running, we have error in connection to hass
await Task.Delay(30000, stoppingToken).ConfigureAwait(false); // Wait 5 seconds
await Task.Delay(40000, stoppingToken).ConfigureAwait(false); // Wait 5 seconds
}
}
catch (OperationCanceledException)
Expand Down

0 comments on commit 90b0f25

Please sign in to comment.