/// <summary> /// Send a command to Home-Assistant /// </summary> /// <param name="command">The command to send</param> /// <returns>A task that will complete once the command has been sent to HA</returns> public async Task Send(HomeAssistantCommand command, CancellationToken ct) { using (EnsureConnected()) { var connection = GetConnection(); await connection.Execute(command, ct); } }
/// <summary> /// Send a command to Home-Assistant /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="command">The command to send</param> /// <returns>A task that will complete once the command has been sent to HA with the response</returns> public async Task <TResult> Send <TResult>(HomeAssistantCommand command, CancellationToken ct) { using (EnsureConnected()) { var connection = GetConnection(); var resultStr = await connection.Execute(command, ct); return(JsonSerializer.Deserialize <TResult>(resultStr, JsonReadOpts)); } }
public PendingCommand(HomeAssistantCommand command, Connection connection, CommandId id, CancellationToken ct) { _connection = connection; _ct = CancellationTokenSource.CreateLinkedTokenSource(ct); _ct.CancelAfter(_timeout); Command = command; Id = id.Value; connection.RegisterPending(this); }