Skip to content

Commit 81cfd08

Browse files
Use SL protected websocket when root certificate is provided (#58)
1 parent 95060b0 commit 81cfd08

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

TgHomeBot.SmartHome.HomeAssistant/HomeAssistantMonitor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public async Task StartMonitoringAsync(CancellationToken cancellationToken)
4646
}
4747

4848
var baseurl = options.Value.BaseUrl.TrimEnd('/');
49-
baseurl = "ws" + baseurl[baseurl.IndexOf(':')..];
49+
var protocol = _caCertificate is not null ? "wss" : "ws";
50+
baseurl = protocol + baseurl[baseurl.IndexOf(':')..];
5051
var uri = new Uri($"{baseurl}/api/websocket");
5152

5253
// Use startup cancellation token for first attempt only
@@ -88,11 +89,11 @@ public async Task StartMonitoringAsync(CancellationToken cancellationToken)
8889
}
8990
catch (Exception ex)
9091
{
91-
logger.LogError("Error connecting to Home Assistant: [{Type}] {Exception}", ex.GetType().FullName, ex.Message);
92+
logger.LogError(ex, "Error connecting to Home Assistant: [{Type}] {Exception}", ex.GetType().FullName, ex.Message);
9293
var inner = ex.InnerException;
9394
while (inner is not null)
9495
{
95-
logger.LogError("Inner exception: [{Type}] {Exception}", inner.GetType().FullName, inner.Message);
96+
logger.LogError(inner, "Inner exception: [{Type}] {Exception}", inner.GetType().FullName, inner.Message);
9697
inner = inner.InnerException;
9798
}
9899

0 commit comments

Comments
 (0)