@Test public void testDeviceList() { assumeNotNull(relayId); assumeNotNull(thermostatId); NADeviceListResponse deviceList = api.devicelist("app_thermostat", relayId, false); NADevice relay = deviceList.getBody().getDevices().get(0); assertEquals(relay.getId(), relayId); assertTrue(relay.getModules().contains(new String(thermostatId))); }
@Test public void testSetpoint() { assumeNotNull(relayId); assumeNotNull(thermostatId); Float setpointTemp = Float.valueOf(20); NAThermStateBody thermState = api.getthermstate(relayId, thermostatId).getBody(); NASetpoint setpoint = thermState.getSetpointOrder(); if (setpoint == null) { setpoint = thermState.getSetpoint(); } // If already in manual mode, ensure that the temp will be changed if (setpoint.getSetpointMode() == "manual") { setpointTemp = setpoint.getSetpointTemp() + Float.valueOf(0.5f); } // Send order api.setthermpoint( relayId, thermostatId, "manual", (int) (System.currentTimeMillis() / 1000 + 30), setpointTemp); // Verify order thermState = api.getthermstate(relayId, thermostatId).getBody(); if (thermState.getSetpointOrder() != null) { assertEquals(thermState.getSetpointOrder().getSetpointTemp(), setpointTemp); } else { assertEquals(thermState.getSetpoint().getSetpointTemp(), setpointTemp); } // Rollback previous mode api.setthermpoint( relayId, thermostatId, setpoint.getSetpointMode(), setpoint.getSetpointEndtime(), setpoint.getSetpointTemp()); }
@Test public void testGetMeasure() { assumeNotNull(relayId); assumeNotNull(thermostatId); CSVParams params = new CSVParams("Temperature", "Sp_Temperature", "BoilerOn", "BoilerOff"); assertEquals( api.getmeasure(relayId, "max", params, thermostatId, null, null, null, null, null) .getBody() .get(0) .getValue() .get(0) .size(), 4); }
@Test public void testGetUser() throws Exception { NAUserResponse user = api.getuser(); assertNotNull(user); assertEquals(user.getBody().getMail(), props.getProperty("io.swagger.client.username")); }
@Test public void testSchedule() { assumeNotNull(relayId); assumeNotNull(thermostatId); NAThermStateBody thermState = api.getthermstate(relayId, thermostatId).getBody(); if (thermState.getThermProgram().getName().equals(TEST_PROGRAM_NAME) || (thermState.getThermProgramOrder() != null && thermState.getThermProgramOrder().getName().equals(TEST_PROGRAM_NAME))) { throw new RuntimeException( "The test program should not be the one in use at the beginning of the test !"); } // Get program NAThermProgram program = thermState.getThermProgramOrder(); if (program == null) { program = thermState.getThermProgram(); } String previousProgramId = program.getProgramId(); // Do we need to create a test program ? // Note : if you want to test the program creation, you need to delete the test program manually // on Netatmo'site since it cannot be done by API. NAThermProgram testProgram = getExitingTestProgram(thermState); if (testProgram == null) { testProgram = program; testProgram.setProgramId(null); testProgram.setName(TEST_PROGRAM_NAME); NANewScheduleResponse newscheduleResponse = api.createnewschedule(relayId, thermostatId, testProgram); assertEquals(newscheduleResponse.getStatus(), "ok"); testProgram.setProgramId(newscheduleResponse.getBody().getScheduleId()); } // Switch to test schedule NAOkResponse naOkResponse = api.switchschedule(relayId, thermostatId, testProgram.getProgramId()); assertEquals(naOkResponse.getStatus(), "ok"); // Modify schedule Float nightTempBefore = null; for (NAZone zone : testProgram.getZones()) { if (zone.getType() == 1) { nightTempBefore = zone.getTemp(); zone.setTemp(nightTempBefore + Float.valueOf(0.5f)); break; } } if (nightTempBefore == null) { throw new RuntimeException( "The current program doesn't have a night zone. This is unexpected by this test !"); } naOkResponse = api.syncschedule(relayId, thermostatId, testProgram); assertEquals(naOkResponse.getStatus(), "ok"); // Verify the change of temperature thermState = api.getthermstate(relayId, thermostatId).getBody(); testProgram = thermState.getThermProgramOrder(); if (testProgram == null) { testProgram = thermState.getThermProgram(); } for (NAZone zone : testProgram.getZones()) { if (zone.getType() == 1) { assertEquals(nightTempBefore + Float.valueOf(0.5f), zone.getTemp(), 0.0001); zone.setTemp(nightTempBefore); break; } } // Rollback changes api.syncschedule(relayId, thermostatId, testProgram); api.switchschedule(relayId, thermostatId, previousProgramId); }