Search in sources :

Example 6 with TimeframeInterval

use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.

the class RunningTimeMonitor method activateTimeframeInterval.

/**
 * Activate the given timeframe interval.
 * @param now
 * @param timeframeIntervalToBeActivated the timeframe interval or null
 */
public void activateTimeframeInterval(LocalDateTime now, TimeframeInterval timeframeIntervalToBeActivated) {
    boolean intervalChanged = false;
    if (timeframeIntervalToBeActivated != null && activeTimeframeInterval == null) {
        Schedule schedule = timeframeIntervalToBeActivated.getTimeframe().getSchedule();
        runningTime = 0;
        remainingMinRunningTimeWhileNotRunning = schedule.getMinRunningTime();
        remainingMaxRunningTimeWhileNotRunning = schedule.getMaxRunningTime();
        intervalChanged = true;
        logger.debug("{}: Interval activated: ", applianceId, timeframeIntervalToBeActivated);
    } else if (timeframeIntervalToBeActivated == null && activeTimeframeInterval != null) {
        logger.debug("{}: Interval expired: {}", applianceId, activeTimeframeInterval);
        running = false;
        runningTime = null;
        interrupted = false;
        statusChangedAt = null;
        remainingMinRunningTimeWhileNotRunning = null;
        remainingMaxRunningTimeWhileNotRunning = null;
        intervalChanged = true;
    }
    TimeframeInterval deactivatedTimeframeInterval = activeTimeframeInterval;
    activeTimeframeInterval = timeframeIntervalToBeActivated;
    if (intervalChanged) {
        logger.debug("{}: Active interval changed. deactivatedTimeframeInterval={} activeTimeframeInterval={}", applianceId, deactivatedTimeframeInterval, activeTimeframeInterval);
        for (ActiveIntervalChangedListener listener : scheduleChangedListeners) {
            logger.debug("{}: Notifying {} {}", applianceId, ActiveIntervalChangedListener.class.getSimpleName(), listener.getClass().getSimpleName());
            listener.activeIntervalChanged(now, applianceId, deactivatedTimeframeInterval, activeTimeframeInterval);
        }
    }
}
Also used : TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule)

Example 7 with TimeframeInterval

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

Example 8 with TimeframeInterval

use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method getIntervals_AllDayOfWeek_WithinInterval.

@Test
public void getIntervals_AllDayOfWeek_WithinInterval() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0));
    List<TimeframeInterval> intervals = timeframe.getIntervals(toToday(11, 0, 0));
    Assert.assertEquals(7, intervals.size());
    Assert.assertEquals(new Interval(toToday(10, 0, 0).toDateTime(), toToday(12, 0, 0).toDateTime()), intervals.get(0).getInterval());
    Assert.assertEquals(new Interval(toDay(1, 10, 0, 0).toDateTime(), toDay(1, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
    Assert.assertEquals(new Interval(toDay(2, 10, 0, 0).toDateTime(), toDay(2, 12, 0, 0).toDateTime()), intervals.get(2).getInterval());
    Assert.assertEquals(new Interval(toDay(3, 10, 0, 0).toDateTime(), toDay(3, 12, 0, 0).toDateTime()), intervals.get(3).getInterval());
    Assert.assertEquals(new Interval(toDay(4, 10, 0, 0).toDateTime(), toDay(4, 12, 0, 0).toDateTime()), intervals.get(4).getInterval());
    Assert.assertEquals(new Interval(toDay(5, 10, 0, 0).toDateTime(), toDay(5, 12, 0, 0).toDateTime()), intervals.get(5).getInterval());
    Assert.assertEquals(new Interval(toDay(6, 10, 0, 0).toDateTime(), toDay(6, 12, 0, 0).toDateTime()), intervals.get(6).getInterval());
}
Also used : TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 9 with TimeframeInterval

use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method getIntervals_ValidOnSundayAndHoliday_HolidayIsSunday.

@Test
public void getIntervals_ValidOnSundayAndHoliday_HolidayIsSunday() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Arrays.asList(7, 8));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    timeframe.setHolidays(Collections.singletonList(now.toLocalDate().plusDays(6)));
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 7, 10, 0, 0).toDateTime(), toDayOfWeek(now, 7, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Example 10 with TimeframeInterval

use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.

the class DayTimeframeTest method getIntervals_ValidOnSundayAndHoliday_HolidayIsThursday.

@Test
public void getIntervals_ValidOnSundayAndHoliday_HolidayIsThursday() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Arrays.asList(7, 8));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    timeframe.setHolidays(Collections.singletonList(now.toLocalDate().plusDays(3)));
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(2, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 4, 10, 0, 0).toDateTime(), toDayOfWeek(now, 4, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 7, 10, 0, 0).toDateTime(), toDayOfWeek(now, 7, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) DayTimeframe(de.avanux.smartapplianceenabler.schedule.DayTimeframe) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Test(org.junit.Test)

Aggregations

TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)22 Test (org.junit.Test)17 LocalDateTime (org.joda.time.LocalDateTime)16 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)12 Interval (org.joda.time.Interval)10 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)9 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)4 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1