Skip to content

Commit

Permalink
[yamahareceiver] connect timed out since 2.5M4 (openhab#6328) (openha…
Browse files Browse the repository at this point in the history
…b#6835)

Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
  • Loading branch information
zarusz authored and J-N-K committed Jan 19, 2020
1 parent b17f4e9 commit 4a8c82b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
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
// 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

0 comments on commit 4a8c82b

Please sign in to comment.