import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.stream.MalformedJsonException;
/**
* The {@link SenecHomeApi} class configures http client and
Request request = httpClient.newRequest(location);
request.header(HttpHeader.ACCEPT, MimeTypes.Type.APPLICATION_JSON.asString());
request.header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString());
- ContentResponse response = request.method(HttpMethod.POST)
- .content(new StringContentProvider(gson.toJson(new SenecHomeResponse()))).send();
-
- if (response.getStatus() == HttpStatus.OK_200) {
- return Objects.requireNonNull(gson.fromJson(response.getContentAsString(), SenecHomeResponse.class));
- } else {
- logger.trace("Got unexpected response code {}", response.getStatus());
- throw new IOException("Got unexpected response code " + response.getStatus());
+ ContentResponse response = null;
+ try {
+ response = request.method(HttpMethod.POST)
+ .content(new StringContentProvider(gson.toJson(new SenecHomeResponse()))).send();
+ if (response.getStatus() == HttpStatus.OK_200) {
+ return Objects.requireNonNull(gson.fromJson(response.getContentAsString(), SenecHomeResponse.class));
+ } else {
+ logger.trace("Got unexpected response code {}", response.getStatus());
+ throw new IOException("Got unexpected response code " + response.getStatus());
+ }
+ } catch (MalformedJsonException | JsonSyntaxException | InterruptedException | TimeoutException
+ | ExecutionException e) {
+ String errorMessage = "\nlocation: " + location;
+ errorMessage += "\nrequest: " + request.toString();
+ errorMessage += "\nrequest.getHeaders: " + request.getHeaders();
+ if (response == null) {
+ errorMessage += "\nresponse: null";
+ } else {
+ errorMessage += "\nresponse: " + response.toString();
+ errorMessage += "\nresponse.getHeaders: " + response.getHeaders();
+ if (response.getContent() == null) {
+ errorMessage += "\nresponse.getContent is null";
+ } else {
+ errorMessage += "\nresponse.getContentAsString: " + response.getContentAsString();
+ }
+ }
+ logger.trace("Issue with getting SenecHomeResponse\n{}", errorMessage);
+ throw e;
}
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.gson.JsonSyntaxException;
+
/**
* The {@link SenecHomeHandler} is responsible for handling commands, which are
* sent to one of the channels.
}
public @Nullable Boolean refreshState() {
+ SenecHomeResponse response = null;
try {
- SenecHomeResponse response = senecHomeApi.getStatistics();
+ response = senecHomeApi.getStatistics();
logger.trace("received {}", response);
BigDecimal pvLimitation = new BigDecimal(100).subtract(getSenecValue(response.limitation.powerLimitation))
updateGridPowerValues(getSenecValue(response.grid.currentGridValue));
updateStatus(ThingStatus.ONLINE);
- } catch (IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ } catch (JsonSyntaxException | IOException | InterruptedException | TimeoutException | ExecutionException e) {
+ if (response == null) {
+ logger.trace("Faulty response: is null");
+ } else {
+ logger.trace("Faulty response: {}", response.toString());
+ }
logger.warn("Error refreshing source '{}'", getThing().getUID(), e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Could not connect to Senec web interface:" + e.getMessage());