Skip to content

Commit 6a636c6

Browse files
Fix reconnecting
1 parent a1fa291 commit 6a636c6

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

Home Assistant Taskbar Menu/Connection/HaClientContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4+
using System.Windows;
45
using System.Windows.Threading;
56
using Home_Assistant_Taskbar_Menu.Entities;
67
using Home_Assistant_Taskbar_Menu.Utils;
@@ -18,11 +19,10 @@ public static void Initialize(Configuration configuration)
1819
HomeAssistantWebsocketClient = new HomeAssistantWebsocketsClient(Configuration);
1920
}
2021

21-
public static async void Recreate()
22+
public static void Recreate()
2223
{
23-
HomeAssistantWebsocketClient?.Disconnect();
24-
HomeAssistantWebsocketClient = new HomeAssistantWebsocketsClient(Configuration);
25-
await Start();
24+
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
25+
Application.Current.Shutdown();
2626
}
2727

2828
public static async Task Start()

Home Assistant Taskbar Menu/Connection/HomeAssistantWebsocketsClient.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,14 @@ public HomeAssistantWebsocketsClient(Configuration configuration)
9595
_websocketClient.ReconnectionHappened.Subscribe(recInfo =>
9696
{
9797
{
98+
ConsoleWriter.WriteLine($"RECONNECTION HAPPENED: {recInfo.Type}", ConsoleColor.Yellow);
99+
if (recInfo.Type == ReconnectionType.NoMessageReceived)
100+
{
101+
HaClientContext.Recreate();
102+
}
103+
98104
if (recInfo.Type != ReconnectionType.Initial)
99105
{
100-
ConsoleWriter.WriteLine($"RECONNECTION HAPPENED: {recInfo.Type}", ConsoleColor.Yellow);
101106
Authenticated = false;
102107
Authenticate();
103108
}

0 commit comments

Comments
 (0)