This commit is contained in:
Av3m
2022-12-17 00:11:27 +01:00
committed by Thomas Vogl
parent c34a9fd911
commit af2f10bde8
2 changed files with 30 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
import org.openhab.binding.mediolaaiogateway.internal.config.MediolaAioBridgeConfig;
import org.openhab.binding.mediolaaiogateway.internal.discovery.MediolaAioDeviceDiscoveryService;
@@ -100,24 +101,30 @@ public class MediolaAioGatewayBridgeHandler extends BaseBridgeHandler {
synchronized (this) {
try {
response = request.send();
if(!HttpStatus.isSuccess(response.getStatus())) {
throw new MediolaAioCommunicationError("invalid http result code");
}
content = response.getContent();
} catch (InterruptedException | TimeoutException | ExecutionException e) {
throw new MediolaAioCommunicationError("communication error", e);
}
}
JsonObject convertedObject = new Gson().fromJson(new String(content), JsonObject.class);
if (!convertedObject.has("XC_SUC")) {
if (convertedObject.has("XC_ERR")) {
throw new MediolaAioCommandError(convertedObject.get("XC_ERR").getAsString());
} else {
throw new MediolaAioCommandError("unknown reason.");
try {
JsonObject convertedObject = new Gson().fromJson(new String(content), JsonObject.class);
if (!convertedObject.has("XC_SUC")) {
if (convertedObject.has("XC_ERR")) {
throw new MediolaAioCommandError(convertedObject.get("XC_ERR").getAsString());
} else {
throw new MediolaAioCommandError("unknown reason.");
}
}
return convertedObject.get("XC_SUC");
} catch (Exception e) {
throw new MediolaAioCommandError("json decode of response failed.");
}
return convertedObject.get("XC_SUC");
}