Search in sources :

Example 1 with TimeOfDay

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 2 with TimeOfDay

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));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 3 with TimeOfDay

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));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 4 with TimeOfDay

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());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 5 with TimeOfDay

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());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Aggregations

TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)25 Test (org.junit.Test)23 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)17 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)16 Interval (org.joda.time.Interval)15 LocalDateTime (org.joda.time.LocalDateTime)11 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)8 ArrayList (java.util.ArrayList)2 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1