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

[yamahareceiver] connect timed out since 2.5M4 fix #6835

Merged
merged 1 commit into from
Jan 16, 2020
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 @@ -722,6 +722,7 @@ protected void updateAsyncMakeOfflineIfFail(IStateUpdatable stateUpdatable) {
try {
stateUpdatable.update();
} catch (IOException e) {
logger.debug("State update error. Changing thing to offline", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
} catch (ReceivedMessageParseException e) {
updateProperty(PROPERTY_LAST_PARSE_ERROR, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openhab.binding.yamahareceiver.internal.state.DeviceInformationState;
import org.openhab.binding.yamahareceiver.internal.state.NavigationControlState;
import org.openhab.binding.yamahareceiver.internal.state.NavigationControlStateListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -48,6 +49,8 @@
*/
public class InputWithNavigationControlXML extends AbstractInputControlXML implements InputWithNavigationControl {

private final Logger logger = LoggerFactory.getLogger(InputWithNavigationControlXML.class);

public static final int MAX_PER_PAGE = 8;
private boolean useAlternativeBackToHomeCmd = false;

Expand Down Expand Up @@ -297,8 +300,10 @@ public void update() throws IOException, ReceivedMessageParseException {

totalWaitingTime += YamahaReceiverBindingConstants.MENU_RETRY_DELAY;
if (totalWaitingTime > YamahaReceiverBindingConstants.MENU_MAX_WAITING_TIME) {
throw new IOException(
"Menu still not ready after " + YamahaReceiverBindingConstants.MENU_MAX_WAITING_TIME + "ms");
logger.info("Menu still not ready after " + YamahaReceiverBindingConstants.MENU_MAX_WAITING_TIME + "ms. The menu state will be out of sync.");
// ToDo: this needs to redesigned to allow for some sort of async update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a TODO, what should be done and can it be completed before merging the PR?

Copy link
Member Author

@zarusz zarusz Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put that ToDo for another time. I am not using menus myself and not sure how it works, but when you look at the code it would require a rework to avoid delaying and a looping to fetch updates until the devices applies changes.

Too big refactor for now.
With this PR I am trying to fix the rather critical issue introduced last time.

// Note: there is not really that much we can do here.
return;
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class XMLConnection extends AbstractConnection {
private static final String XML_END = "</YAMAHA_AV>";
private static final String HEADER_CHARSET_PART = "charset=";

private static final int CONNECTION_TIMEOUT_MS = 5000;

public XMLConnection(String host) {
super(host);
}
Expand Down Expand Up @@ -74,7 +76,7 @@ private <T> T postMessage(String prefix, String message, String suffix,
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length", Integer.toString(message.length()));

connection.setConnectTimeout(5); // set a timeout in case the device is not reachable (went offline)
connection.setConnectTimeout(CONNECTION_TIMEOUT_MS); // set a timeout in case the device is not reachable (went offline)
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public class ZoneControlXML implements ZoneControl {
protected boolean dialogueLevelSupported = false;

public ZoneControlXML(AbstractConnection con, Zone zone, YamahaZoneConfig zoneSettings,
ZoneControlStateListener observer, DeviceInformationState deviceInformationState,
Supplier<InputConverter> inputConverterSupplier) {
ZoneControlStateListener observer, DeviceInformationState deviceInformationState,
Supplier<InputConverter> inputConverterSupplier) {

this.comReference = new WeakReference<>(con);
this.zone = zone;
Expand Down Expand Up @@ -132,22 +132,19 @@ protected void applyModelVariations() {

try {
// Note: Detection for RX-V3900, which has a different XML node for surround program
Node basicStatusNode = getZoneResponse(comReference.get(), getZone(), ZONE_BASIC_STATUS_CMD,
ZONE_BASIC_STATUS_PATH);
Node basicStatusNode = getZoneResponse(comReference.get(), getZone(), ZONE_BASIC_STATUS_CMD, ZONE_BASIC_STATUS_PATH);
String surroundProgram = getNodeContentOrEmpty(basicStatusNode, "Surr/Pgm_Sel/Pgm");

if (StringUtils.isNotEmpty(surroundProgram)) {
surroundSelProgram = new CommandTemplate(
"<Surr><Pgm_Sel><Straight>Off</Straight><Pgm>%s</Pgm></Pgm_Sel></Surr>", "Surr/Pgm_Sel/Pgm");
surroundSelProgram = new CommandTemplate("<Surr><Pgm_Sel><Straight>Off</Straight><Pgm>%s</Pgm></Pgm_Sel></Surr>", "Surr/Pgm_Sel/Pgm");
logger.debug("Zone {} - adjusting command to: {}", getZone(), surroundSelProgram);

surroundSelStraight = new CommandTemplate("<Surr><Pgm_Sel><Straight>On</Straight></Pgm_Sel></Surr>",
"Surr/Pgm_Sel/Straight");
surroundSelStraight = new CommandTemplate("<Surr><Pgm_Sel><Straight>On</Straight></Pgm_Sel></Surr>", "Surr/Pgm_Sel/Straight");
logger.debug("Zone {} - adjusting command to: {}", getZone(), surroundSelStraight);
}

} catch (ReceivedMessageParseException | IOException e) {
logger.warn("Could not perform feature detection for RX-V3900", e);
logger.debug("Could not perform feature detection for RX-V3900");
}
}

Expand Down