Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ public async Task UsingDisposedConnectionWhenPostApiShouldThrowException()
await act.Should().ThrowAsync<ObjectDisposedException>();
}

[Fact]
public async Task SubscribeToSpecificEventShouldSendRequestedEventType()
{
var pipeline = new TransportPipelineMock();
SubscribeEventCommand? sentCommand = null;
pipeline
.Setup(n => n.SendMessageAsync(It.IsAny<SubscribeEventCommand>(), It.IsAny<CancellationToken>()))
.Returns<SubscribeEventCommand, CancellationToken>((command, _) =>
{
sentCommand = command;
pipeline.AddResponse(new HassMessage { Type = "result", Id = command.Id, Success = true });
return Task.CompletedTask;
});

await using var homeAssistantConnection = CreateHomeAssistantConnection(pipeline);

_ = await homeAssistantConnection.SubscribeToHomeAssistantEventsAsync("state_changed", CancellationToken.None);

sentCommand.Should().NotBeNull();
sentCommand!.EventType.Should().Be("state_changed");
}

[Fact]
public async Task HomeAssistantConnectionDisposedMultipleTimesShouldNotThrow()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ private async Task<IObservable<HassEvent>> SubscribeToHomeAssistantEventsInterna
_internalCancelSource.Token
);

var result = await SendCommandAndReturnHassMessageResponseAsync(new SubscribeEventCommand(),
var result = await SendCommandAndReturnHassMessageResponseAsync(new SubscribeEventCommand
{
EventType = eventType
},
combinedTokenSource.Token).ConfigureAwait(false);

// The id if the message we used to subscribe should be used as the filter for the event messages
Expand Down
Loading