Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[benqprojector] Fix response processing for newer projectors #18009

Merged
merged 6 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.benqprojector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sitemaps/benq.sitemap
sitemap benq label="BenQ Projector" {
Frame label="Controls" {
Switch item=benqPower label="Power"
Selection item=benqSource label="Source" mappings=["hdmi"="HDMI", "hdmi2"="HDMI2", "ypbr"="Component", "RGB"="Computer", "vid"="Video", "svid"="S-Video"]
Selection item=benqSource label="Source" mappings=["hdmi"="HDMI", "hdmi2"="HDMI2", "usbreader"="USB Reader", "ypbr"="Component", "RGB"="Computer", "vid"="Video", "svid"="S-Video"]
Selection item=benqPictureMode label="Picture Mode"
Selection item=benqAspectRatio label="Aspect Ratio"
Switch item=benqFreeze label="Freeze"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public Switch getPowerStatus() throws BenqProjectorCommandException, BenqProject

public void setPower(Switch value) throws BenqProjectorCommandException, BenqProjectorException {
sendCommand(value == Switch.ON ? "pow=on" : "pow=off");

// some projectors need the off command twice to switch off
if (value == Switch.OFF) {
sendCommand("pow=off");
lsiepel marked this conversation as resolved.
Show resolved Hide resolved
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -88,8 +89,12 @@ default String sendMsgReadResp(String data, @Nullable InputStream in, @Nullable
byte[] tmpData = new byte[availableBytes];
int readBytes = in.read(tmpData, 0, availableBytes);
resp = resp.concat(new String(tmpData, 0, readBytes, StandardCharsets.US_ASCII));
if (resp.contains(END)) {
return resp.replaceAll("[\\r\\n*#>]", BLANK).replace(data, BLANK);

// The response is fully received when the second '#' arrives
// example: *pow=?# *POW=ON#
if (resp.chars().filter(ch -> ch == '#').count() >= 2) {
return resp.replaceAll("[\\s\\r\\n*#>]", BLANK).replace(data, BLANK)
.toLowerCase(Locale.ENGLISH);
}
} else {
try {
Expand Down