[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
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof YamahaBridgeHandler) {
|
||||
this.handler = (YamahaBridgeHandler) handler;
|
||||
this.handler.setZoneDiscoveryService(this);
|
||||
if (handler instanceof YamahaBridgeHandler bridgeHandler) {
|
||||
bridgeHandler.setZoneDiscoveryService(this);
|
||||
this.handler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,9 +167,8 @@ public class YamahaBridgeHandler extends BaseBridgeHandler
|
|||
systemControl.setPartyModeMute(((OnOffType) command) == OnOffType.ON);
|
||||
break;
|
||||
case CHANNEL_PARTY_MODE_VOLUME:
|
||||
if (command instanceof IncreaseDecreaseType) {
|
||||
systemControl
|
||||
.setPartyModeVolume(((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE);
|
||||
if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||
systemControl.setPartyModeVolume(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE);
|
||||
} else {
|
||||
logger.warn("Only {} and {} commands are supported for {}", IncreaseDecreaseType.DECREASE,
|
||||
IncreaseDecreaseType.DECREASE, id);
|
||||
|
|
|
@ -87,7 +87,7 @@ import org.slf4j.LoggerFactory;
|
|||
* class {@link ZoneControlXML}, {@link InputWithPlayControlXML} and {@link InputWithNavigationControlXML}
|
||||
* 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
|
||||
* config object
|
||||
*/
|
||||
|
@ -287,11 +287,11 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
zoneControl.setVolumeDB(((DecimalType) command).floatValue());
|
||||
break;
|
||||
case CHANNEL_VOLUME:
|
||||
if (command instanceof DecimalType) {
|
||||
zoneControl.setVolume(((DecimalType) command).floatValue());
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
zoneControl.setVolume(decimalCommand.floatValue());
|
||||
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||
zoneControl.setVolumeRelative(zoneState,
|
||||
(((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE ? 1 : -1)
|
||||
(increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? 1 : -1)
|
||||
* zoneConfig.getVolumeRelativeChangeFactor());
|
||||
}
|
||||
break;
|
||||
|
@ -377,11 +377,11 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
return;
|
||||
}
|
||||
|
||||
if (command instanceof DecimalType) {
|
||||
inputWithPresetControl.selectItemByPresetNumber(((DecimalType) command).intValue());
|
||||
} else if (command instanceof StringType) {
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
inputWithPresetControl.selectItemByPresetNumber(decimalCommand.intValue());
|
||||
} else if (command instanceof StringType stringCommand) {
|
||||
try {
|
||||
int v = Integer.valueOf(((StringType) command).toString());
|
||||
int v = Integer.valueOf(stringCommand.toString());
|
||||
inputWithPresetControl.selectItemByPresetNumber(v);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Provide a number for {}", id);
|
||||
|
@ -408,8 +408,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
return;
|
||||
}
|
||||
|
||||
if (command instanceof PlayPauseType) {
|
||||
PlayPauseType t = ((PlayPauseType) command);
|
||||
if (command instanceof PlayPauseType t) {
|
||||
switch (t) {
|
||||
case PAUSE:
|
||||
inputWithPlayControl.pause();
|
||||
|
@ -418,8 +417,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
inputWithPlayControl.play();
|
||||
break;
|
||||
}
|
||||
} else if (command instanceof NextPreviousType) {
|
||||
NextPreviousType t = ((NextPreviousType) command);
|
||||
} else if (command instanceof NextPreviousType t) {
|
||||
switch (t) {
|
||||
case NEXT:
|
||||
inputWithPlayControl.nextTrack();
|
||||
|
@ -428,15 +426,15 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
inputWithPlayControl.previousTrack();
|
||||
break;
|
||||
}
|
||||
} else if (command instanceof DecimalType) {
|
||||
int v = ((DecimalType) command).intValue();
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
int v = decimalCommand.intValue();
|
||||
if (v < 0) {
|
||||
inputWithPlayControl.skipREV();
|
||||
} else if (v > 0) {
|
||||
inputWithPlayControl.skipFF();
|
||||
}
|
||||
} else if (command instanceof StringType) {
|
||||
String v = ((StringType) command).toFullString();
|
||||
} else if (command instanceof StringType stringCommand) {
|
||||
String v = stringCommand.toFullString();
|
||||
switch (v) {
|
||||
case "Play":
|
||||
inputWithPlayControl.play();
|
||||
|
@ -496,7 +494,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
} else if (id.equals(grpZone(CHANNEL_SURROUND))) {
|
||||
updateState(channelUID, new StringType(zoneState.surroundProgram));
|
||||
} 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))) {
|
||||
updateState(channelUID, new DecimalType(zoneState.dialogueLevel));
|
||||
} else if (id.equals(grpZone(CHANNEL_HDMI1OUT))) {
|
||||
|
@ -739,7 +737,7 @@ public class YamahaZoneThingHandler extends BaseThingHandler
|
|||
stateUpdatable.update();
|
||||
} catch (IOException 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) {
|
||||
String message = e.getMessage();
|
||||
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.
|
||||
* 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 {
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public class DeviceInformationXML implements DeviceInformation {
|
|||
|
||||
private boolean isFeatureSupported(Node node, String name) {
|
||||
String value = getNodeContentOrEmpty(node, name);
|
||||
boolean supported = value.equals("1") || value.equals("Available");
|
||||
boolean supported = "1".equals(value) || "Available".equals(value);
|
||||
return supported;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* XML implementation of {@link InputConverter}.
|
||||
*
|
||||
* @author Tomasz Maruszak - Initial contribution.
|
||||
* @author Tomasz Maruszak - Initial contribution
|
||||
*
|
||||
*/
|
||||
public class InputConverterXML implements InputConverter {
|
||||
|
|
|
@ -43,8 +43,8 @@ import org.w3c.dom.Node;
|
|||
* menu.goToPath(menuDir);
|
||||
* menu.selectItem(stationName);
|
||||
*
|
||||
* @author Dennis Frommknecht - Initial contribution
|
||||
* @author David Graeff - Completely refactored class
|
||||
* @author Dennis Frommknecht - Initial idea and implementaton
|
||||
* @author Tomasz Maruszak - Refactor
|
||||
*/
|
||||
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
|
||||
* {@link PresetInfoState} instead.
|
||||
*
|
||||
* @author David Graeff
|
||||
* @author David Graeff - Initial contribution
|
||||
* @author Tomasz Maruszak - Spotify support, refactoring
|
||||
*/
|
||||
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
|
||||
* {@link PresetInfoState} instead.
|
||||
*
|
||||
* @author David Graeff
|
||||
* @author David Graeff - Initial contribution
|
||||
* @author Tomasz Maruszak - Compatibility fixes
|
||||
*/
|
||||
public class InputWithPresetControlXML extends AbstractInputControlXML implements InputWithPresetControl {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class XMLUtils {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(XMLUtils.class);
|
||||
|
||||
// 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) {
|
||||
if (parent == null) {
|
||||
|
@ -174,12 +174,12 @@ public class XMLUtils {
|
|||
|
||||
try {
|
||||
// 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-parameter-entities", false);
|
||||
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
dbf.setXIncludeAware(false);
|
||||
dbf.setExpandEntityReferences(false);
|
||||
return dbf.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
|
||||
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://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
DBF.setXIncludeAware(false);
|
||||
DBF.setExpandEntityReferences(false);
|
||||
return DBF.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
|
||||
} catch (SAXException | ParserConfigurationException e) {
|
||||
throw new ReceivedMessageParseException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue