[yamahareceiver] Show correct status detail on failure (#15510)
* Partial fix #7667 * java 17 instanceof * Checkstyle Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
d9235da5db
commit
5cc5ee6f7b
|
@ -101,9 +101,9 @@ public class ZoneDiscoveryService extends AbstractDiscoveryService implements Di
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||||
if (handler instanceof YamahaBridgeHandler) {
|
if (handler instanceof YamahaBridgeHandler bridgeHandler) {
|
||||||
this.handler = (YamahaBridgeHandler) handler;
|
bridgeHandler.setZoneDiscoveryService(this);
|
||||||
this.handler.setZoneDiscoveryService(this);
|
this.handler = bridgeHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,9 +167,8 @@ public class YamahaBridgeHandler extends BaseBridgeHandler
|
||||||
systemControl.setPartyModeMute(((OnOffType) command) == OnOffType.ON);
|
systemControl.setPartyModeMute(((OnOffType) command) == OnOffType.ON);
|
||||||
break;
|
break;
|
||||||
case CHANNEL_PARTY_MODE_VOLUME:
|
case CHANNEL_PARTY_MODE_VOLUME:
|
||||||
if (command instanceof IncreaseDecreaseType) {
|
if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||||
systemControl
|
systemControl.setPartyModeVolume(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE);
|
||||||
.setPartyModeVolume(((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE);
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Only {} and {} commands are supported for {}", IncreaseDecreaseType.DECREASE,
|
logger.warn("Only {} and {} commands are supported for {}", IncreaseDecreaseType.DECREASE,
|
||||||
IncreaseDecreaseType.DECREASE, id);
|
IncreaseDecreaseType.DECREASE, id);
|
||||||
|
|
|
@ -87,7 +87,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* class {@link ZoneControlXML}, {@link InputWithPlayControlXML} and {@link InputWithNavigationControlXML}
|
* class {@link ZoneControlXML}, {@link InputWithPlayControlXML} and {@link InputWithNavigationControlXML}
|
||||||
* for communication.
|
* for communication.
|
||||||
*
|
*
|
||||||
* @author David Graeff <david.graeff@web.de>
|
* @author David Graeff - Initial contribution
|
||||||
* @author Tomasz Maruszak - [yamaha] Tuner band selection and preset feature for dual band models (RX-S601D), added
|
* @author Tomasz Maruszak - [yamaha] Tuner band selection and preset feature for dual band models (RX-S601D), added
|
||||||
* config object
|
* config object
|
||||||
*/
|
*/
|
||||||
|
@ -287,11 +287,11 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
zoneControl.setVolumeDB(((DecimalType) command).floatValue());
|
zoneControl.setVolumeDB(((DecimalType) command).floatValue());
|
||||||
break;
|
break;
|
||||||
case CHANNEL_VOLUME:
|
case CHANNEL_VOLUME:
|
||||||
if (command instanceof DecimalType) {
|
if (command instanceof DecimalType decimalCommand) {
|
||||||
zoneControl.setVolume(((DecimalType) command).floatValue());
|
zoneControl.setVolume(decimalCommand.floatValue());
|
||||||
} else if (command instanceof IncreaseDecreaseType) {
|
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||||
zoneControl.setVolumeRelative(zoneState,
|
zoneControl.setVolumeRelative(zoneState,
|
||||||
(((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE ? 1 : -1)
|
(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1)
|
||||||
* zoneConfig.getVolumeRelativeChangeFactor());
|
* zoneConfig.getVolumeRelativeChangeFactor());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -377,11 +377,11 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command instanceof DecimalType) {
|
if (command instanceof DecimalType decimalCommand) {
|
||||||
inputWithPresetControl.selectItemByPresetNumber(((DecimalType) command).intValue());
|
inputWithPresetControl.selectItemByPresetNumber(decimalCommand.intValue());
|
||||||
} else if (command instanceof StringType) {
|
} else if (command instanceof StringType stringCommand) {
|
||||||
try {
|
try {
|
||||||
int v = Integer.valueOf(((StringType) command).toString());
|
int v = Integer.valueOf(stringCommand.toString());
|
||||||
inputWithPresetControl.selectItemByPresetNumber(v);
|
inputWithPresetControl.selectItemByPresetNumber(v);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.warn("Provide a number for {}", id);
|
logger.warn("Provide a number for {}", id);
|
||||||
|
@ -408,8 +408,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command instanceof PlayPauseType) {
|
if (command instanceof PlayPauseType t) {
|
||||||
PlayPauseType t = ((PlayPauseType) command);
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case PAUSE:
|
case PAUSE:
|
||||||
inputWithPlayControl.pause();
|
inputWithPlayControl.pause();
|
||||||
|
@ -418,8 +417,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
inputWithPlayControl.play();
|
inputWithPlayControl.play();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (command instanceof NextPreviousType) {
|
} else if (command instanceof NextPreviousType t) {
|
||||||
NextPreviousType t = ((NextPreviousType) command);
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case NEXT:
|
case NEXT:
|
||||||
inputWithPlayControl.nextTrack();
|
inputWithPlayControl.nextTrack();
|
||||||
|
@ -428,15 +426,15 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
inputWithPlayControl.previousTrack();
|
inputWithPlayControl.previousTrack();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (command instanceof DecimalType) {
|
} else if (command instanceof DecimalType decimalCommand) {
|
||||||
int v = ((DecimalType) command).intValue();
|
int v = decimalCommand.intValue();
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
inputWithPlayControl.skipREV();
|
inputWithPlayControl.skipREV();
|
||||||
} else if (v > 0) {
|
} else if (v > 0) {
|
||||||
inputWithPlayControl.skipFF();
|
inputWithPlayControl.skipFF();
|
||||||
}
|
}
|
||||||
} else if (command instanceof StringType) {
|
} else if (command instanceof StringType stringCommand) {
|
||||||
String v = ((StringType) command).toFullString();
|
String v = stringCommand.toFullString();
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case "Play":
|
case "Play":
|
||||||
inputWithPlayControl.play();
|
inputWithPlayControl.play();
|
||||||
|
@ -496,7 +494,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
} else if (id.equals(grpZone(CHANNEL_SURROUND))) {
|
} else if (id.equals(grpZone(CHANNEL_SURROUND))) {
|
||||||
updateState(channelUID, new StringType(zoneState.surroundProgram));
|
updateState(channelUID, new StringType(zoneState.surroundProgram));
|
||||||
} else if (id.equals(grpZone(CHANNEL_SCENE))) {
|
} else if (id.equals(grpZone(CHANNEL_SCENE))) {
|
||||||
// no state updates available
|
logger.debug("No state updates available");
|
||||||
} else if (id.equals(grpZone(CHANNEL_DIALOGUE_LEVEL))) {
|
} else if (id.equals(grpZone(CHANNEL_DIALOGUE_LEVEL))) {
|
||||||
updateState(channelUID, new DecimalType(zoneState.dialogueLevel));
|
updateState(channelUID, new DecimalType(zoneState.dialogueLevel));
|
||||||
} else if (id.equals(grpZone(CHANNEL_HDMI1OUT))) {
|
} else if (id.equals(grpZone(CHANNEL_HDMI1OUT))) {
|
||||||
|
@ -739,7 +737,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
||||||
stateUpdatable.update();
|
stateUpdatable.update();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.debug("State update error. Changing thing to offline", e);
|
logger.debug("State update error. Changing thing to offline", e);
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||||
} catch (ReceivedMessageParseException e) {
|
} catch (ReceivedMessageParseException e) {
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
updateProperty(PROPERTY_LAST_PARSE_ERROR, message != null ? message : "");
|
updateProperty(PROPERTY_LAST_PARSE_ERROR, message != null ? message : "");
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.openhab.binding.yamahareceiver.internal.protocol;
|
||||||
* For example, AVRs when setting input 'AUDIO_X' (or HDMI_X) need the input to be sent in this form.
|
* For example, AVRs when setting input 'AUDIO_X' (or HDMI_X) need the input to be sent in this form.
|
||||||
* However, what comes back in the status update from the AVR is 'AUDIOX' (and 'HDMIX') respectively.
|
* However, what comes back in the status update from the AVR is 'AUDIOX' (and 'HDMIX') respectively.
|
||||||
*
|
*
|
||||||
* @author Tomasz Maruszak
|
* @author Tomasz Maruszak - Initial contribution
|
||||||
*/
|
*/
|
||||||
public interface InputConverter {
|
public interface InputConverter {
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class DeviceInformationXML implements DeviceInformation {
|
||||||
|
|
||||||
private boolean isFeatureSupported(Node node, String name) {
|
private boolean isFeatureSupported(Node node, String name) {
|
||||||
String value = getNodeContentOrEmpty(node, name);
|
String value = getNodeContentOrEmpty(node, name);
|
||||||
boolean supported = value.equals("1") || value.equals("Available");
|
boolean supported = "1".equals(value) || "Available".equals(value);
|
||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* XML implementation of {@link InputConverter}.
|
* XML implementation of {@link InputConverter}.
|
||||||
*
|
*
|
||||||
* @author Tomasz Maruszak - Initial contribution.
|
* @author Tomasz Maruszak - Initial contribution
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InputConverterXML implements InputConverter {
|
public class InputConverterXML implements InputConverter {
|
||||||
|
|
|
@ -43,8 +43,8 @@ import org.w3c.dom.Node;
|
||||||
* menu.goToPath(menuDir);
|
* menu.goToPath(menuDir);
|
||||||
* menu.selectItem(stationName);
|
* menu.selectItem(stationName);
|
||||||
*
|
*
|
||||||
|
* @author Dennis Frommknecht - Initial contribution
|
||||||
* @author David Graeff - Completely refactored class
|
* @author David Graeff - Completely refactored class
|
||||||
* @author Dennis Frommknecht - Initial idea and implementaton
|
|
||||||
* @author Tomasz Maruszak - Refactor
|
* @author Tomasz Maruszak - Refactor
|
||||||
*/
|
*/
|
||||||
public class InputWithNavigationControlXML extends AbstractInputControlXML implements InputWithNavigationControl {
|
public class InputWithNavigationControlXML extends AbstractInputControlXML implements InputWithNavigationControl {
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.w3c.dom.Node;
|
||||||
* No state will be saved in here, but in {@link PlayInfoState} and
|
* No state will be saved in here, but in {@link PlayInfoState} and
|
||||||
* {@link PresetInfoState} instead.
|
* {@link PresetInfoState} instead.
|
||||||
*
|
*
|
||||||
* @author David Graeff
|
* @author David Graeff - Initial contribution
|
||||||
* @author Tomasz Maruszak - Spotify support, refactoring
|
* @author Tomasz Maruszak - Spotify support, refactoring
|
||||||
*/
|
*/
|
||||||
public class InputWithPlayControlXML extends AbstractInputControlXML implements InputWithPlayControl {
|
public class InputWithPlayControlXML extends AbstractInputControlXML implements InputWithPlayControl {
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.w3c.dom.Node;
|
||||||
* No state will be saved in here, but in {@link PlayInfoState} and
|
* No state will be saved in here, but in {@link PlayInfoState} and
|
||||||
* {@link PresetInfoState} instead.
|
* {@link PresetInfoState} instead.
|
||||||
*
|
*
|
||||||
* @author David Graeff
|
* @author David Graeff - Initial contribution
|
||||||
* @author Tomasz Maruszak - Compatibility fixes
|
* @author Tomasz Maruszak - Compatibility fixes
|
||||||
*/
|
*/
|
||||||
public class InputWithPresetControlXML extends AbstractInputControlXML implements InputWithPresetControl {
|
public class InputWithPresetControlXML extends AbstractInputControlXML implements InputWithPresetControl {
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class XMLUtils {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(XMLUtils.class);
|
private static final Logger LOG = LoggerFactory.getLogger(XMLUtils.class);
|
||||||
|
|
||||||
// We need a lot of xml parsing. Create a document builder beforehand.
|
// We need a lot of xml parsing. Create a document builder beforehand.
|
||||||
static final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
static Node getNode(Node parent, String[] nodePath, int offset) {
|
static Node getNode(Node parent, String[] nodePath, int offset) {
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
|
@ -174,12 +174,12 @@ public class XMLUtils {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// see https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
|
// see https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
|
||||||
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
DBF.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
DBF.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
DBF.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||||
dbf.setXIncludeAware(false);
|
DBF.setXIncludeAware(false);
|
||||||
dbf.setExpandEntityReferences(false);
|
DBF.setExpandEntityReferences(false);
|
||||||
return dbf.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
|
return DBF.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
|
||||||
} catch (SAXException | ParserConfigurationException e) {
|
} catch (SAXException | ParserConfigurationException e) {
|
||||||
throw new ReceivedMessageParseException(e);
|
throw new ReceivedMessageParseException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue