use of org.openhab.binding.netatmo.internal.messages.NetatmoError in project openhab1-addons by openhab.
the class RefreshTokenTest method testError.
@Test
public void testError() throws Exception {
final RefreshTokenRequestStub request = createRequest("/error-2.json");
final RefreshTokenResponse response = request.execute();
assertTrue(response.isError());
final NetatmoError error = response.getError();
assertNotNull(error);
assertEquals(2, error.getCode());
assertEquals("Invalid access token", error.getMessage());
}
use of org.openhab.binding.netatmo.internal.messages.NetatmoError in project openhab1-addons by openhab.
the class NetatmoWeatherBinding method processGetStationsData.
private GetStationsDataResponse processGetStationsData(OAuthCredentials oauthCredentials, Collection<NetatmoBindingProvider> providers, EventPublisher eventPublisher) {
GetStationsDataRequest stationsDataRequest = new GetStationsDataRequest(oauthCredentials.getAccessToken());
logger.debug("Request: {}", stationsDataRequest);
GetStationsDataResponse stationsDataResponse = stationsDataRequest.execute();
logger.debug("Response: {}", stationsDataResponse);
if (stationsDataResponse.isError()) {
final NetatmoError error = stationsDataResponse.getError();
if (error.isAccessTokenExpired() || error.isTokenNotVaid()) {
logger.debug("Token is expired or is not valid, refreshing: code = {} message = {}", error.getCode(), error.getMessage());
oauthCredentials.refreshAccessToken();
execute(oauthCredentials, providers, eventPublisher);
} else {
logger.error("Error processing device list: code = {} message = {}", error.getCode(), error.getMessage());
throw new NetatmoException(error.getMessage());
}
// abort processing
return null;
} else {
processGetStationsDataResponse(stationsDataResponse, providers);
}
return stationsDataResponse;
}
use of org.openhab.binding.netatmo.internal.messages.NetatmoError in project openhab1-addons by openhab.
the class NetatmoCameraBinding method processGetHomeData.
/**
* Camera Home Implementation
*
* @param oauthCredentials
* @param providers
*/
private void processGetHomeData(OAuthCredentials oauthCredentials, Collection<NetatmoBindingProvider> providers, EventPublisher eventPublisher) {
GetHomeDataRequest homeDataRequest = new GetHomeDataRequest(oauthCredentials.getAccessToken());
logger.debug("Request: {}", homeDataRequest);
GetHomeDataResponse homeDataResponse = homeDataRequest.execute();
logger.debug("Response: {}", homeDataResponse);
if (homeDataResponse.isError()) {
final NetatmoError error = homeDataResponse.getError();
if (error.isAccessTokenExpired() || error.isTokenNotVaid()) {
logger.debug("Token is expired or is not valid, refreshing: code = {} message = {}", error.getCode(), error.getMessage());
oauthCredentials.refreshAccessToken();
execute(oauthCredentials, providers, eventPublisher);
} else {
logger.error("Error processing home list: code = {} message = {}", error.getCode(), error.getMessage());
throw new NetatmoException(error.getMessage());
}
// abort processing
return;
} else {
processGetHomeDataResponse(homeDataResponse, providers);
}
}
use of org.openhab.binding.netatmo.internal.messages.NetatmoError in project openhab1-addons by openhab.
the class MeasurementTest method testError.
@Test
public void testError() throws Exception {
final MeasurementRequestStub request = createRequest("/error-2.json");
final MeasurementResponse response = request.execute();
assertTrue(response.isError());
final NetatmoError error = response.getError();
assertNotNull(error);
assertEquals(2, error.getCode());
assertEquals("Invalid access token", error.getMessage());
}
use of org.openhab.binding.netatmo.internal.messages.NetatmoError in project openhab1-addons by openhab.
the class NetatmoWeatherBinding method processMeasurements.
private DeviceMeasureValueMap processMeasurements(OAuthCredentials oauthCredentials, Collection<NetatmoBindingProvider> providers, EventPublisher eventPublisher) {
DeviceMeasureValueMap deviceMeasureValueMap = new DeviceMeasureValueMap();
for (final MeasurementRequest request : createMeasurementRequests(providers)) {
final MeasurementResponse response = request.execute();
logger.debug("Request: {}", request);
logger.debug("Response: {}", response);
if (response.isError()) {
final NetatmoError error = response.getError();
if (error.isAccessTokenExpired() || error.isTokenNotVaid()) {
logger.debug("Token is expired or is not valid, refreshing: code = {} message = {}", error.getCode(), error.getMessage());
oauthCredentials.refreshAccessToken();
execute(oauthCredentials, providers, eventPublisher);
return null;
} else {
logger.error("Error sending measurement request: code = {} message = {}", error.getCode(), error.getMessage());
throw new NetatmoException(error.getMessage());
}
} else {
processMeasurementResponse(request, response, deviceMeasureValueMap);
}
}
return deviceMeasureValueMap;
}
Aggregations