Skip to content

Commit

Permalink
Merge pull request #15 from tuxBurner/feature/#14_filter_events
Browse files Browse the repository at this point in the history
#14 filter events on the regex before returning
  • Loading branch information
stheves authored Feb 29, 2020
2 parents 6f13ebe + 032e36a commit 1bd30f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/io/theves/denon4j/DenonReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static java.lang.String.format;

Expand Down Expand Up @@ -446,10 +447,14 @@ public boolean isConnected() {
return protocol.isConnected();
}

public Event send(String command, String regex) {
return send(command, Condition.regex(regex)).stream().findFirst().orElseThrow(() -> new TimeoutException(
format("No response received after %s milliseconds. Receiver may be too busy to respond.", RECV_TIMEOUT)
));
public Event send(final String command,final String regex) {

return send(command, Condition.regex(regex))
.stream()
.filter(event -> event.asciiValue().matches(regex))
.findFirst().orElseThrow(() -> new TimeoutException(
format("No response received after %s milliseconds. Receiver may be too busy to respond.", RECV_TIMEOUT)
));
}

/**
Expand Down

0 comments on commit 1bd30f4

Please sign in to comment.