Search in sources :

Example 1 with NetatmoError

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());
}
Also used : RefreshTokenRequestStub(org.openhab.binding.netatmo.internal.authentication.RefreshTokenRequestStub) NetatmoError(org.openhab.binding.netatmo.internal.messages.NetatmoError) Test(org.junit.Test)

Example 2 with NetatmoError

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;
}
Also used : NetatmoError(org.openhab.binding.netatmo.internal.messages.NetatmoError) NetatmoException(org.openhab.binding.netatmo.internal.NetatmoException)

Example 3 with NetatmoError

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);
    }
}
Also used : NetatmoError(org.openhab.binding.netatmo.internal.messages.NetatmoError) NetatmoException(org.openhab.binding.netatmo.internal.NetatmoException)

Example 4 with NetatmoError

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());
}
Also used : MeasurementResponse(org.openhab.binding.netatmo.internal.weather.MeasurementResponse) MeasurementRequestStub(org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub) NetatmoError(org.openhab.binding.netatmo.internal.messages.NetatmoError) Test(org.junit.Test)

Example 5 with NetatmoError

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;
}
Also used : NetatmoError(org.openhab.binding.netatmo.internal.messages.NetatmoError) NetatmoException(org.openhab.binding.netatmo.internal.NetatmoException)

Aggregations

NetatmoError (org.openhab.binding.netatmo.internal.messages.NetatmoError)5 NetatmoException (org.openhab.binding.netatmo.internal.NetatmoException)3 Test (org.junit.Test)2 RefreshTokenRequestStub (org.openhab.binding.netatmo.internal.authentication.RefreshTokenRequestStub)1 MeasurementRequestStub (org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub)1 MeasurementResponse (org.openhab.binding.netatmo.internal.weather.MeasurementResponse)1