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

net-daemon / netdaemon / 6307257339

24 Sep 2023 10:30AM UTC coverage: 82.031% (-0.07%) from 82.097%
6307257339

push

github

web-flow
remove --no-symbols so that symbol packages are pushed (#933)

810 of 1126 branches covered (0.0%)

Branch coverage included in aggregate %.

2938 of 3443 relevant lines covered (85.33%)

51.15 hits per line

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

54.17
/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
    {
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
    {
35
        return _ws.ConnectAsync(uri, cancel);
21✔
36
    }
37

38
    public Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription,
39
        CancellationToken cancellationToken)
40
    {
41
        return _ws.CloseAsync(closeStatus, statusDescription, cancellationToken);
20✔
42
    }
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
    {
53
        return _ws.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
57✔
54
    }
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
    {
71
        return _ws.ReceiveAsync(buffer, cancellationToken);
96✔
72
    }
73

74
    public ValueTask DisposeAsync()
75
    {
76
        _ws.Dispose();
19✔
77
        return ValueTask.CompletedTask;
19✔
78
    }
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

© 2025 Coveralls, Inc