[boschindego] Add missing specialized text for unreachable device (#13058)

* Add missing specialized text for unreachable device
* Document IndegoUnreachableException on relevant paths

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2022-07-05 13:01:46 +02:00 committed by GitHub
parent 949848723a
commit f5eabf0ba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -189,10 +189,11 @@ public class IndegoController {
* @param dtoClass the DTO class to which the JSON result should be deserialized
* @return the deserialized DTO from the JSON response
* @throws IndegoAuthenticationException if request was rejected as unauthorized
* @throws IndegoUnreachableException if device cannot be reached (gateway timeout error)
* @throws IndegoException if any communication or parsing error occurred
*/
private <T> T getRequestWithAuthentication(String path, Class<? extends T> dtoClass)
throws IndegoAuthenticationException, IndegoException {
throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException {
if (!session.isValid()) {
authenticate();
}
@ -218,10 +219,11 @@ public class IndegoController {
* @param dtoClass the DTO class to which the JSON result should be deserialized
* @return the deserialized DTO from the JSON response
* @throws IndegoAuthenticationException if request was rejected as unauthorized
* @throws IndegoUnreachableException if device cannot be reached (gateway timeout error)
* @throws IndegoException if any communication or parsing error occurred
*/
private <T> T getRequest(String path, Class<? extends T> dtoClass)
throws IndegoAuthenticationException, IndegoException {
throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException {
try {
Request request = httpClient.newRequest(BASE_URL + path).method(HttpMethod.GET).header(CONTEXT_HEADER_NAME,
session.getContextId());
@ -521,9 +523,11 @@ public class IndegoController {
*
* @return the device state
* @throws IndegoAuthenticationException if request was rejected as unauthorized
* @throws IndegoUnreachableException if device cannot be reached (gateway timeout error)
* @throws IndegoException if any communication or parsing error occurred
*/
public OperatingDataResponse getOperatingData() throws IndegoAuthenticationException, IndegoException {
public OperatingDataResponse getOperatingData()
throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException {
return getRequestWithAuthentication(SERIAL_NUMBER_SUBPATH + this.getSerialNumber() + "/operatingData",
OperatingDataResponse.class);
}

View File

@ -31,6 +31,7 @@ import org.openhab.binding.boschindego.internal.dto.response.DeviceStateResponse
import org.openhab.binding.boschindego.internal.dto.response.OperatingDataResponse;
import org.openhab.binding.boschindego.internal.exceptions.IndegoAuthenticationException;
import org.openhab.binding.boschindego.internal.exceptions.IndegoException;
import org.openhab.binding.boschindego.internal.exceptions.IndegoUnreachableException;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
@ -145,12 +146,16 @@ public class BoschIndegoHandler extends BaseThingHandler {
} catch (IndegoAuthenticationException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.comm-error.authentication-failure");
} catch (IndegoUnreachableException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.comm-error.unreachable");
} catch (IndegoException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
private void handleRefreshCommand(String channelId) throws IndegoAuthenticationException, IndegoException {
private void handleRefreshCommand(String channelId)
throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException {
switch (channelId) {
case STATE:
case TEXTUAL_STATE:
@ -212,6 +217,9 @@ public class BoschIndegoHandler extends BaseThingHandler {
} catch (IndegoAuthenticationException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.comm-error.authentication-failure");
} catch (IndegoUnreachableException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.comm-error.unreachable");
} catch (IndegoException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
@ -233,7 +241,8 @@ public class BoschIndegoHandler extends BaseThingHandler {
}
}
private void refreshOperatingData() throws IndegoAuthenticationException, IndegoException {
private void refreshOperatingData()
throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException {
updateOperatingData(controller.getOperatingData());
updateStatus(ThingStatus.ONLINE);
}