use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_MaxRunningTime.
@Test
public void createRuntimeRequest_MaxRunningTime() {
LocalDateTime now = toToday(0, 30, 0);
Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
schedule.getTimeframe().setSchedule(schedule);
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
Assert.assertEquals(1800, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(30600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
Assert.assertEquals(7200, (int) runtimeRequest.getMaxRunningTime());
}
use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_MaxRunningTimeExceedsLatestEnd.
@Test
public void createRuntimeRequest_MaxRunningTimeExceedsLatestEnd() {
LocalDateTime now = toToday(8, 0, 0);
Schedule schedule = new Schedule(3600, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
schedule.getTimeframe().setSchedule(schedule);
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), schedule.getMaxRunningTime(), now);
Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(3600, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(3600, (int) runtimeRequest.getMinRunningTime());
Assert.assertEquals(3600, (int) runtimeRequest.getMaxRunningTime());
}
use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitorTest method getRemainingMinRunningTimeOfCurrentTimeFrame.
@Test
public void getRemainingMinRunningTimeOfCurrentTimeFrame() {
Schedule schedule = new Schedule(7200, null, new TimeOfDay(11, 0, 0), new TimeOfDay(17, 0, 0));
runningTimeMonitor.setSchedules(Collections.singletonList(schedule));
Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(10, 0, 0)));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(11, 00, 0));
Assert.assertEquals("With timeframe started but device switched off max running time should be returned", 7200, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(11, 30, 0)).intValue());
runningTimeMonitor.setRunning(true, toToday(12, 10, 0));
Assert.assertEquals("With timeframe started and device switched on max running time should be reduced by 5 minutes", 6900, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(12, 15, 0)).intValue());
runningTimeMonitor.setRunning(false, toToday(13, 10, 0));
Assert.assertEquals("With timeframe started and device switched off running time of one hour remains", 3600, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(13, 15, 0)).intValue());
runningTimeMonitor.setRunning(true, toToday(16, 10, 0));
Assert.assertEquals("Running time may exceed LatestEnd", 3300, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(16, 15, 0)).intValue());
Assert.assertEquals("Running time left right before LatestEnd", 601, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(16, 59, 59)).intValue());
runningTimeMonitor.setRunning(false, toToday(17, 0, 0));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(17, 0, 1));
Assert.assertNull("With timeframe expired running time should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(17, 0, 0)));
}
use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitor method activateTimeframeInterval.
public void activateTimeframeInterval(LocalDateTime now, Integer runtime) {
activeTimeframeInterval = null;
Schedule schedule = new Schedule(runtime, null, new TimeOfDay(now), new TimeOfDay(now));
Interval interval = new Interval(now.toDateTime(), now.plusSeconds(runtime).toDateTime());
Timeframe timeframe = schedule.getTimeframe();
activateTimeframeInterval(now, new TimeframeInterval(timeframe, interval));
}
use of de.avanux.smartapplianceenabler.schedule.Schedule in project SmartApplianceEnabler by camueller.
the class ScheduleTest method getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow.
@Test
public void getCurrentOrNextTimeframeInterval_timeFrameNotValidForDow() {
LocalDateTime now = toToday(9, 0, 0);
List<Schedule> schedules = new ArrayList<Schedule>();
// Timeframe only valid yesterday
schedules.add(new Schedule(true, 7200, null, new TimeOfDay(10, 0, 0), new TimeOfDay(14, 0, 0), Collections.singletonList(now.minusDays(1).get(DateTimeFieldType.dayOfWeek()))));
// Timeframe only valid tomorrow
schedules.add(new Schedule(true, 7200, null, new TimeOfDay(15, 0, 0), new TimeOfDay(18, 0, 0), Collections.singletonList(now.plusDays(1).get(DateTimeFieldType.dayOfWeek()))));
Assert.assertEquals(new Interval(toDay(1, 15, 0, 0).toDateTime(), toDay(1, 18, 0, 0).toDateTime()), Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, false).getInterval());
}
Aggregations