Skip to content

Commit 032e36a

Browse files
committed
#14 filter events on the regex before returning
1 parent 6f13ebe commit 032e36a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/io/theves/denon4j/DenonReceiver.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.*;
2929
import java.util.logging.Level;
3030
import java.util.logging.Logger;
31+
import java.util.stream.Collectors;
3132

3233
import static java.lang.String.format;
3334

@@ -446,10 +447,14 @@ public boolean isConnected() {
446447
return protocol.isConnected();
447448
}
448449

449-
public Event send(String command, String regex) {
450-
return send(command, Condition.regex(regex)).stream().findFirst().orElseThrow(() -> new TimeoutException(
451-
format("No response received after %s milliseconds. Receiver may be too busy to respond.", RECV_TIMEOUT)
452-
));
450+
public Event send(final String command,final String regex) {
451+
452+
return send(command, Condition.regex(regex))
453+
.stream()
454+
.filter(event -> event.asciiValue().matches(regex))
455+
.findFirst().orElseThrow(() -> new TimeoutException(
456+
format("No response received after %s milliseconds. Receiver may be too busy to respond.", RECV_TIMEOUT)
457+
));
453458
}
454459

455460
/**

0 commit comments

Comments
 (0)