Skip to content

Commit

Permalink
[viessmann] fix npe error reading (#492)
Browse files Browse the repository at this point in the history
* [viessmann] fix npe handleViError

Signed-off-by: Ronny Grun <[email protected]>
  • Loading branch information
rogrun committed Jun 8, 2023
1 parent f349143 commit 78a53f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,27 @@ private Properties setHeaders() throws ViessmannAuthException {
private void handleViError(String response) throws ViessmannCommunicationException {
ViErrorDTO viError = GSON.fromJson(response, ViErrorDTO.class);
if (viError != null) {
switch (viError.getStatusCode()) {
case HttpStatus.TOO_MANY_REQUESTS_429:
logger.warn("ViError: {} | Resetting Limit at {}", viError.getMessage(),
viError.getExtendedPayload().getLimitResetDateTime());
bridgeHandler.updateBridgeStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
String.format("API Call limit reached. Reset at %s",
viError.getExtendedPayload().getLimitResetDateTime()));
bridgeHandler.waitForApiCallLimitReset(viError.getExtendedPayload().getLimitReset());
break;
case HttpStatus.BAD_GATEWAY_502:
logger.debug("ViError: {} | Device not reachable", viError.getMessage());
throw new ViessmannCommunicationException(viError.getMessage());
default:
logger.error("ViError: {} | StatusCode: {} | Reason: ", viError.getMessage(),
viError.getStatusCode(), viError.getExtendedPayload());
break;
if ("INTERNAL_SERVER_ERROR".equals(viError.getErrorType())) {
logger.debug("ViError: {} | Device not reachable", viError.getMessage());
throw new ViessmannCommunicationException("INTERNAL_SERVER_ERROR");
} else {
switch (viError.getStatusCode()) {
case HttpStatus.TOO_MANY_REQUESTS_429:
logger.warn("ViError: {} | Resetting Limit at {}", viError.getMessage(),
viError.getExtendedPayload().getLimitResetDateTime());
bridgeHandler.updateBridgeStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
String.format("API Call limit reached. Reset at %s",
viError.getExtendedPayload().getLimitResetDateTime()));
bridgeHandler.waitForApiCallLimitReset(viError.getExtendedPayload().getLimitReset());
break;
case HttpStatus.BAD_GATEWAY_502:
logger.debug("ViError: {} | Device not reachable", viError.getMessage());
throw new ViessmannCommunicationException(viError.getMessage());
default:
logger.error("ViError: {} | StatusCode: {} | Reason: ", viError.getMessage(),
viError.getStatusCode(), viError.getExtendedPayload());
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void getDeviceError() {
EventsDTO errors = api.getSelectedEvents("device-error");
countApiCalls();
logger.trace("Errors:{}", errors);
if (errors != null) {
if (errors != null && errors.data.size() > 0) {
String state = errors.data.get(0).body.errorDescription;
Boolean active = errors.data.get(0).body.active;
updateState("lastErrorMessage", StringType.valueOf(state));
Expand Down

0 comments on commit 78a53f0

Please sign in to comment.