use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_WithinInterval.
@Test
public void getIntervals_AcrossWeeks_WithinInterval() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(6, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(1, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(7, 10, 0, 0);
List<TimeframeInterval> intervals = timeRange.getIntervals(now);
Assert.assertEquals(1, intervals.size());
LocalDateTime start = startTimeOfDayOfWeek.toLastOccurrence(now);
assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_BeforeIntervalStart.
@Test
public void getIntervals_AcrossWeeks_BeforeIntervalStart() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(6, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(1, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(3, 0, 0, 0);
List<TimeframeInterval> intervals = timeRange.getIntervals(now);
Assert.assertEquals(1, intervals.size());
LocalDateTime start = startTimeOfDayOfWeek.toNextOccurrence(now);
assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_BeforeIntervalStart.
@Test
public void getIntervals_SameWeek_BeforeIntervalStart() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(5, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(7, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(1, 0, 0, 0);
List<TimeframeInterval> intervals = timeRange.getIntervals(now);
Assert.assertEquals(1, intervals.size());
LocalDateTime start = startTimeOfDayOfWeek.toNextOccurrence(now);
assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class SaeController method suggestRuntime.
/**
* Suggest a runtime for immediate start.
* @param applianceId
* @return the suggested runtime in s; 0 if no timeframe interval was found; null if no appliance was found for the given id
*/
public Integer suggestRuntime(String applianceId) {
logger.debug("{}: Received request to suggest runtime", applianceId);
Appliance appliance = ApplianceManager.getInstance().findAppliance(applianceId);
if (appliance != null) {
LocalDateTime now = new LocalDateTime();
List<TimeframeInterval> timeframeIntervals = Schedule.findTimeframeIntervals(now, null, appliance.getSchedules(), false, false);
if (timeframeIntervals.size() > 0) {
return timeframeIntervals.get(0).getTimeframe().getSchedule().getMinRunningTime();
}
} else {
logger.error("{}: Appliance not found", applianceId);
return null;
}
return 0;
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class IntegrationTest method testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval.
@Test
public void testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval() {
String applianceId = "F-001";
TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(true).withMockMeter().withSchedule(10, 0, 18, 0, 3600, null).init();
Appliance appliance = builder.getAppliance();
StartingCurrentSwitch control = (StartingCurrentSwitch) appliance.getControl();
Meter meter = appliance.getMeter();
RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
log("Check initial values");
assertRunningTime(null, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
log("Detect starting current");
LocalDateTime timeBeforeStartingCurrent = toToday(11, 29, 0);
Mockito.when(meter.getAveragePower()).thenReturn(StartingCurrentSwitchDefaults.getPowerThreshold() + 1);
control.detectStartingCurrent(timeBeforeStartingCurrent, meter);
assertRunningTime(timeBeforeStartingCurrent, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
Assert.assertEquals(0, sempController.createDevice2EM(timeBeforeStartingCurrent).getPlanningRequest().size());
LocalDateTime timeStartingCurrent = toToday(11, 30, 0);
control.detectStartingCurrent(toToday(11, 30, 0), meter);
assertRunningTime(timeStartingCurrent, control, runningTimeMonitor, false, false, false, false, true, 0, 3600, null);
assertPlanningRequest(timeStartingCurrent, new Timeframe(applianceId, 0, 23400, 3599, 3600));
log("Switch on");
LocalDateTime timeSwitchOn = toToday(12, 0, 0);
sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
log("Check values after switch on");
assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, true, false, true, 0, 3600, null);
assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 21600, 3599, 3600));
ApplianceStatus applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
log("Switch off");
LocalDateTime timeSwitchOff = toToday(13, 0, 0);
sempController.em2Device(timeSwitchOff, createEM2Device(applianceId, false));
log("Check values after switch off");
assertRunningTime(timeSwitchOff, control, runningTimeMonitor, false, true, false, true, true, 3600, 0, null);
Assert.assertEquals(0, sempController.createDevice2EM(timeSwitchOff).getPlanningRequest().size());
// TODO nochmal an/aus schalten
}
Aggregations