diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/http/DenonMarantzHttpConnector.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/http/DenonMarantzHttpConnector.java index 7a4a5ac079fe5..b7e62e0b16219 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/http/DenonMarantzHttpConnector.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/http/DenonMarantzHttpConnector.java @@ -16,6 +16,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringWriter; +import java.math.BigDecimal; import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -47,6 +48,7 @@ import org.openhab.binding.denonmarantz.internal.xml.entities.commands.AppCommandResponse; import org.openhab.binding.denonmarantz.internal.xml.entities.commands.CommandRx; import org.openhab.binding.denonmarantz.internal.xml.entities.commands.CommandTx; +import org.openhab.binding.denonmarantz.internal.xml.entities.types.StringType; import org.openhab.core.io.net.http.HttpUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -194,6 +196,40 @@ private void updateMain() throws IOException { } } + private void updateMainZoneByAppCommand() throws IOException { + String url = statusUrl + URL_APP_COMMAND; + logger.trace("Refreshing URL: {}", url); + + AppCommandRequest request = AppCommandRequest.of(CommandTx.CMD_ALL_POWER).add(CommandTx.CMD_VOLUME_LEVEL) + .add(CommandTx.CMD_MUTE_STATUS); + AppCommandResponse response = postDocument(url, AppCommandResponse.class, request); + + if (response != null) { + for (CommandRx rx : response.getCommands()) { + String inputSource = rx.getSource(); + if (inputSource != null) { + state.setInput(inputSource); + } + Boolean power = rx.getZone1(); + if (power != null) { + state.setMainZonePower(power.booleanValue()); + } + BigDecimal volume = rx.getVolume(); + if (volume != null) { + state.setMainVolume(volume); + } + Boolean mute = rx.getMute(); + if (mute != null) { + state.setMute(mute.booleanValue()); + } + String surroundMode = rx.getSurround(); + if (surroundMode != null) { + state.setSurroundProgram(surroundMode); + } + } + } + } + private void updateMainZone() throws IOException { String url = statusUrl + URL_ZONE_MAIN; logger.trace("Refreshing URL: {}", url); @@ -209,10 +245,11 @@ private void updateMainZone() throws IOException { config.inputOptions = mainZone.getInputFuncList(); } - if (mainZone.getSurrMode() == null) { + StringType surroundMode = mainZone.getSurrMode(); + if (surroundMode == null) { logger.debug("Unable to get the SURROUND_MODE. MainZone update may not be correct."); } else { - state.setSurroundProgram(mainZone.getSurrMode().getValue()); + state.setSurroundProgram(surroundMode.getValue()); } } } @@ -286,8 +323,12 @@ private boolean setConfigProperties() throws IOException { private void refreshHttpProperties() throws IOException { logger.trace("Refreshing Denon status"); - updateMain(); - updateMainZone(); + if (config.getHttpPort() == 8080) { + updateMainZoneByAppCommand(); + } else { + updateMain(); + updateMainZone(); + } updateSecondaryZones(); updateDisplayInfo(); } @@ -333,6 +374,7 @@ private T postDocument(String uri, Class response, S request) throws I ByteArrayInputStream inputStream = new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8)); String result = HttpUtil.executeUrl("POST", uri, inputStream, CONTENT_TYPE_XML, REQUEST_TIMEOUT_MS); + logger.trace("result of postDocument for uri '{}':\r\n{}", uri, result); if (result != null && !result.isBlank()) { JAXBContext jcResponse = JAXBContext.newInstance(response); diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/handler/DenonMarantzHandler.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/handler/DenonMarantzHandler.java index 1ba7dcc5ed27c..806a290ca86fe 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/handler/DenonMarantzHandler.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/handler/DenonMarantzHandler.java @@ -228,7 +228,7 @@ private void autoConfigure() throws InterruptedException { httpApiUsable = true; } } catch (TimeoutException | ExecutionException e) { - logger.debug("Error when trying to access AVR using HTTP on port 80, reverting to Telnet mode.", e); + logger.debug("Error when trying to access AVR using HTTP on port 80.", e); } if (telnetEnable) { @@ -238,13 +238,15 @@ private void autoConfigure() throws InterruptedException { response = httpClient.newRequest("http://" + host + ":8080/goform/Deviceinfo.xml") .timeout(3, TimeUnit.SECONDS).send(); if (response.getStatus() == HttpURLConnection.HTTP_OK) { - logger.debug( - "This model responds to HTTP port 8080, we use this port to retrieve the number of zones."); + logger.debug("This model responds to HTTP port 8080, disabling the Telnet mode by default."); + telnetEnable = false; httpPort = 8080; httpApiUsable = true; } } catch (TimeoutException | ExecutionException e) { - logger.debug("Additionally tried to connect to port 8080, this also failed", e); + logger.debug( + "Additionally tried to connect to port 8080, this also failed. Reverting to Telnet mode.", + e); } } diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/entities/commands/CommandRx.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/entities/commands/CommandRx.java index d9bb5d8b7ddd2..cb82d439a841a 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/entities/commands/CommandRx.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/entities/commands/CommandRx.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.denonmarantz.internal.xml.entities.commands; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -20,6 +21,10 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import org.openhab.binding.denonmarantz.internal.xml.adapters.OnOffAdapter; +import org.openhab.binding.denonmarantz.internal.xml.adapters.VolumeAdapter; /** * Response to a {@link CommandTx} @@ -30,21 +35,27 @@ @XmlAccessorType(XmlAccessType.FIELD) public class CommandRx { - private String zone1; + @XmlJavaTypeAdapter(OnOffAdapter.class) + private Boolean zone1; - private String zone2; + @XmlJavaTypeAdapter(OnOffAdapter.class) + private Boolean zone2; - private String zone3; + @XmlJavaTypeAdapter(OnOffAdapter.class) + private Boolean zone3; - private String zone4; + @XmlJavaTypeAdapter(OnOffAdapter.class) + private Boolean zone4; - private String volume; + @XmlJavaTypeAdapter(value = VolumeAdapter.class) + private BigDecimal volume; private String disptype; private String dispvalue; - private String mute; + @XmlJavaTypeAdapter(OnOffAdapter.class) + private Boolean mute; private String type; @@ -69,46 +80,48 @@ public class CommandRx { private String source; + private String surround; + public CommandRx() { } - public String getZone1() { + public Boolean getZone1() { return zone1; } - public void setZone1(String zone1) { + public void setZone1(Boolean zone1) { this.zone1 = zone1; } - public String getZone2() { + public Boolean getZone2() { return zone2; } - public void setZone2(String zone2) { + public void setZone2(Boolean zone2) { this.zone2 = zone2; } - public String getZone3() { + public Boolean getZone3() { return zone3; } - public void setZone3(String zone3) { + public void setZone3(Boolean zone3) { this.zone3 = zone3; } - public String getZone4() { + public Boolean getZone4() { return zone4; } - public void setZone4(String zone4) { + public void setZone4(Boolean zone4) { this.zone4 = zone4; } - public String getVolume() { + public BigDecimal getVolume() { return volume; } - public void setVolume(String volume) { + public void setVolume(BigDecimal volume) { this.volume = volume; } @@ -128,11 +141,11 @@ public void setDispvalue(String dispvalue) { this.dispvalue = dispvalue; } - public String getMute() { + public Boolean getMute() { return mute; } - public void setMute(String mute) { + public void setMute(Boolean mute) { this.mute = mute; } @@ -184,6 +197,14 @@ public void setSource(String source) { this.source = source; } + public String getSurround() { + return surround; + } + + public void setSurround(String surround) { + this.surround = surround; + } + public String getText(String key) { for (Text text : texts) { if (text.getId().equals(key)) {