Search in sources :

Example 1 with MeasurementRequestStub

use of org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub in project openhab1-addons by openhab.

the class MeasurementTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    final MeasurementRequestStub request = createRequest("/getmeasure.json");
    request.addMeasure(NetatmoMeasureType.TEMPERATURE);
    request.addMeasure(NetatmoMeasureType.HUMIDITY);
    final MeasurementResponse response = request.execute();
    assertFalse(response.isError());
    assertNull(response.getError());
    assertEquals("access_token=" + ACCESS_TOKEN + "&scale=max&date_end=last&device_id=" + DEVICE_ID + "&module_id=" + MODULE_ID + "&type=Humidity,Temperature", request.getContent());
    final List<Body> bodyList = response.getBody();
    assertNotNull(bodyList);
    assertEquals(1, bodyList.size());
    final Body body = bodyList.get(0);
    final List<List<BigDecimal>> valuesList = body.getValues();
    assertNotNull(valuesList);
    assertEquals(1, valuesList.size());
    final List<BigDecimal> values = valuesList.get(0);
    assertNotNull(values);
    assertEquals(2, values.size());
    assertEquals(new BigDecimal("77"), values.get(0));
    assertEquals(new BigDecimal("19.3"), values.get(1));
}
Also used : MeasurementResponse(org.openhab.binding.netatmo.internal.weather.MeasurementResponse) List(java.util.List) MeasurementRequestStub(org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub) Body(org.openhab.binding.netatmo.internal.weather.MeasurementResponse.Body) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with MeasurementRequestStub

use of org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub 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)

Aggregations

Test (org.junit.Test)2 MeasurementRequestStub (org.openhab.binding.netatmo.internal.weather.MeasurementRequestStub)2 MeasurementResponse (org.openhab.binding.netatmo.internal.weather.MeasurementResponse)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 NetatmoError (org.openhab.binding.netatmo.internal.messages.NetatmoError)1 Body (org.openhab.binding.netatmo.internal.weather.MeasurementResponse.Body)1