use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight.
@Test
public void createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight() {
LocalDateTime now = toToday(23, 30, 0);
Schedule schedule = new Schedule(7200, null, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(16200, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
Assert.assertNull(runtimeRequest.getMaxRunningTime());
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive.
@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive() {
int nowSeconds = 10;
LocalDateTime now = toToday(8, 0, nowSeconds);
Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), null, true, 3600 - nowSeconds, null);
Assert.assertEquals(3, runtimeRequests.size());
Assert.assertEquals(new RuntimeRequest(0, 14400 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
Assert.assertEquals(new RuntimeRequest(86400 - nowSeconds, 100800 - nowSeconds, 3600, null), runtimeRequests.get(1));
Assert.assertEquals(new RuntimeRequest(172800 - nowSeconds, 187200 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient.
@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient() {
int nowSeconds = 10;
LocalDateTime now = toToday(8, 0, nowSeconds);
Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
TimeframeInterval activeTimeframeInterval = schedule.getTimeframe().getIntervals(now).get(0);
List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), activeTimeframeInterval, true, 3600 - nowSeconds, null);
Assert.assertEquals(3, runtimeRequests.size());
Assert.assertEquals(new RuntimeRequest(0, 14400 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
Assert.assertEquals(new RuntimeRequest(86400 - nowSeconds, 100800 - nowSeconds, 3600, null), runtimeRequests.get(1));
Assert.assertEquals(new RuntimeRequest(172800 - nowSeconds, 187200 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitorTest method getRemainingMaxRunningTimeOfCurrentTimeFrame_MinRunningTimeDifferentFromMaxRunningTime.
@Test
public void getRemainingMaxRunningTimeOfCurrentTimeFrame_MinRunningTimeDifferentFromMaxRunningTime() {
Schedule schedule = new Schedule(300, 3600, new TimeOfDay(8, 0, 0), new TimeOfDay(22, 59, 59));
runningTimeMonitor.setSchedules(Collections.singletonList(schedule));
Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(toToday(7, 0, 0)));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(9, 00, 0));
runningTimeMonitor.setRunning(true, toToday(9, 00, 0));
Assert.assertEquals("With timeframe started and device switched on one minute ago 59 minutes are left", 3540, runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(toToday(9, 1, 0)).intValue());
Assert.assertEquals("With timeframe started and device switched on one hour ago no running time is left", 0, runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(toToday(10, 0, 0)).intValue());
Assert.assertEquals("With timeframe started and device switched on one hour plus one minute ago remaining max running time has become negative", -60, runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame(toToday(10, 1, 0)).intValue());
}
use of de.avanux.smartapplianceenabler.schedule.TimeOfDay in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitorTest method getRemainingMinRunningTimeOfCurrentTimeFrame_MinRunningTimeDifferentFromMaxRunningTime.
@Test
public void getRemainingMinRunningTimeOfCurrentTimeFrame_MinRunningTimeDifferentFromMaxRunningTime() {
Schedule schedule = new Schedule(300, 3600, new TimeOfDay(8, 0, 0), new TimeOfDay(22, 59, 59));
runningTimeMonitor.setSchedules(Collections.singletonList(schedule));
Assert.assertNull("Timeframe not yet started should return NULL", runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(7, 0, 0)));
runningTimeMonitor.updateActiveTimeframeInterval(toToday(8, 00, 0));
runningTimeMonitor.setRunning(true, toToday(9, 00, 0));
Assert.assertEquals("With timeframe started and device switched on one minute ago 4 minutes are left", 240, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(9, 1, 0)).intValue());
Assert.assertEquals("With timeframe started and device switched on 5 minutes ago no running time is left", 0, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(9, 5, 0)).intValue());
Assert.assertEquals("With timeframe started and device switched on 6 minutes ago remaining min running time has become negative", -60, runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame(toToday(9, 6, 0)).intValue());
}
Aggregations