• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 5806423617

pending completion
5806423617

push

github

web-flow
Minor MQTT updates (#906)

* Provide more useful information on disconnection.

* Add some comments on how to test the MQTT entity subscriptions

* Refactor MQTT entity creation and exercise app - use consistent IDs and ensure they are deleted when done

791 of 1116 branches covered (70.88%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 1 file covered. (100.0%)

3708 of 4361 relevant lines covered (85.03%)

47.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/Client/NetDaemon.HassClient/Internal/Net/WebSocketClientImpl.cs
1
namespace NetDaemon.Client.Internal.Net;
2

3
/// <summary>
4
///     This class wraps the ClientWebSocket so we can do
5
///     mockable communications
6
/// </summary>
7
internal class WebSocketClientImpl : IWebSocketClient
8
{
9
    private readonly ClientWebSocket _ws;
10

11
    /// <summary>
12
    ///     Constructor
13
    /// </summary>
14
    /// <param name="bypassCertificateErrors">
15
    ///     Provide the hash string for certificate that the websocket should ignore
16
    ///     errors from
17
    /// </param>
18
    public WebSocketClientImpl(bool bypassCertificateErrors = false)
22✔
19
    {
22✔
20
        _ws = new ClientWebSocket();
22✔
21

22
        if (bypassCertificateErrors)
22!
23
            _ws.Options.RemoteCertificateValidationCallback = (_, cert, _, sslPolicyErrors) =>
×
24
            {
×
25
                return sslPolicyErrors == SslPolicyErrors.None || true;
×
26
            };
×
27
    }
22✔
28

29
    public WebSocketState State => _ws.State;
354✔
30

31
    public WebSocketCloseStatus? CloseStatus => _ws.CloseStatus;
155✔
32

33
    public Task ConnectAsync(Uri uri, CancellationToken cancel)
34
    {
21✔
35
        return _ws.ConnectAsync(uri, cancel);
21✔
36
    }
21✔
37

38
    public Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription,
39
        CancellationToken cancellationToken)
40
    {
20✔
41
        return _ws.CloseAsync(closeStatus, statusDescription, cancellationToken);
20✔
42
    }
20✔
43

44
    public Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription,
45
        CancellationToken cancellationToken)
46
    {
×
47
        return _ws.CloseAsync(closeStatus, statusDescription, cancellationToken);
×
48
    }
×
49

50
    public Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage,
51
        CancellationToken cancellationToken)
52
    {
57✔
53
        return _ws.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
57✔
54
    }
57✔
55

56
    public async ValueTask SendAsync(ReadOnlyMemory<byte> buffer, WebSocketMessageType messageType,
57
        bool endOfMessage, CancellationToken cancellationToken)
58
    {
×
59
        await Task.FromException(new NotImplementedException()).ConfigureAwait(false);
×
60
    }
×
61

62
    public Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer,
63
        CancellationToken cancellationToken)
64
    {
×
65
        return Task.FromException<WebSocketReceiveResult>(new NotImplementedException());
×
66
    }
×
67

68
    public ValueTask<ValueWebSocketReceiveResult> ReceiveAsync(Memory<byte> buffer,
69
        CancellationToken cancellationToken)
70
    {
96✔
71
        return _ws.ReceiveAsync(buffer, cancellationToken);
96✔
72
    }
96✔
73

74
    public ValueTask DisposeAsync()
75
    {
19✔
76
        _ws.Dispose();
19✔
77
        return ValueTask.CompletedTask;
19✔
78
    }
19✔
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc