[bosesoundtouch] Fix regression and add tests (#14097)

* Fix regression and add tests

Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel
2022-12-30 13:58:27 +01:00
committed by GitHub
parent 8904f92e7b
commit 5881cf0cbe
6 changed files with 221 additions and 17 deletions

View File

@@ -155,7 +155,6 @@ public class CommandExecutor implements AvailableSources {
contentItem.setPresetID(presetID);
currentContentItem = contentItem;
}
updateOperatingValues();
}

View File

@@ -97,11 +97,6 @@ public class XMLResponseHandler extends DefaultHandler {
// showing a
// warning for unhandled states
XMLHandlerState localState = null;
if (stateMap != null) {
localState = stateMap.get(localName);
}
switch (curState) {
case INIT:
if ("updates".equals(localName)) {
@@ -112,10 +107,13 @@ public class XMLResponseHandler extends DefaultHandler {
state = XMLHandlerState.Unprocessed;
}
} else {
XMLHandlerState localState = stateMap.get(localName);
if (localState == null) {
logger.debug("{}: Unhandled XML entity during {}: '{}", handler.getDeviceName(), curState,
logger.warn("{}: Unhandled XML entity during {}: '{}", handler.getDeviceName(), curState,
localName);
state = XMLHandlerState.Unprocessed;
} else {
state = localState;
}
}
break;
@@ -196,9 +194,11 @@ public class XMLResponseHandler extends DefaultHandler {
state = XMLHandlerState.Presets;
} else if ("group".equals(localName)) {
this.masterDeviceId = new BoseSoundTouchConfiguration();
state = stateMap.get(localName);
} else {
if (localState == null) {
logger.debug("{}: Unhandled XML entity during {}: '{}", handler.getDeviceName(), curState,
state = stateMap.get(localName);
if (state == null) {
logger.warn("{}: Unhandled XML entity during {}: '{}", handler.getDeviceName(), curState,
localName);
state = XMLHandlerState.Unprocessed;
@@ -366,16 +366,12 @@ public class XMLResponseHandler extends DefaultHandler {
if (contentItem == null) {
contentItem = new ContentItem();
}
String source = "";
String location = "";
String sourceAccount = "";
Boolean isPresetable = false;
if (attributes != null) {
source = attributes.getValue("source");
sourceAccount = attributes.getValue("sourceAccount");
location = attributes.getValue("location");
isPresetable = Boolean.parseBoolean(attributes.getValue("isPresetable"));
String source = attributes.getValue("source");
String location = attributes.getValue("location");
String sourceAccount = attributes.getValue("sourceAccount");
Boolean isPresetable = Boolean.parseBoolean(attributes.getValue("isPresetable"));
if (source != null) {
contentItem.setSource(source);

View File

@@ -47,6 +47,7 @@ public class XMLResponseProcessor {
public void handleMessage(String msg) throws SAXException, IOException, ParserConfigurationException {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

View File

@@ -306,6 +306,14 @@ public class BoseSoundTouchHandler extends BaseThingHandler implements WebSocket
return commandExecutor;
}
/**
* Sets the CommandExecutor of this handler
*
*/
public void setCommandExecutor(@Nullable CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
}
/**
* Returns the Session this handler has opened
*