Search in sources :

Example 21 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class StartingCurrentSwitch method on.

@Override
public boolean on(boolean switchOn) {
    logger.debug("Setting appliance switch to " + (switchOn ? "on" : "off"));
    on = switchOn;
    if (switchOn) {
        applianceOn(true);
        switchOnTime = new LocalDateTime();
    }
    // don't switch off appliance - otherwise it cannot be operated
    return on;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime)

Example 22 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class Appliance method startingCurrentDetected.

@Override
public void startingCurrentDetected() {
    logger.debug("Activating next sufficient timeframe interval after starting current has been detected");
    LocalDateTime now = new LocalDateTime();
    TimeframeInterval timeframeInterval;
    Schedule forcedSchedule = getForcedSchedule(now);
    if (forcedSchedule != null) {
        logger.debug("Forcing schedule " + forcedSchedule);
        timeframeInterval = Schedule.getCurrentOrNextTimeframeInterval(now, Collections.singletonList(forcedSchedule), false, true);
    } else {
        timeframeInterval = Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, true);
    }
    runningTimeMonitor.activateTimeframeInterval(now, timeframeInterval);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime)

Example 23 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempController method planningRequest.

@RequestMapping(value = BASE_URL + "/PlanningRequest", method = RequestMethod.GET, produces = "application/xml")
@ResponseBody
public String planningRequest(@RequestParam(value = "DeviceId", required = false) String deviceId) {
    LocalDateTime now = new LocalDateTime();
    List<PlanningRequest> planningRequests = new ArrayList<PlanningRequest>();
    if (deviceId != null) {
        ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, deviceId);
        applianceLogger.debug("Planning request requested");
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
        PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
        addPlanningRequest(planningRequests, planningRequest);
    } else {
        logger.debug("Planning request requested of all devices");
        List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
        for (Appliance appliance : appliances) {
            ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, appliance.getId());
            PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
            addPlanningRequest(planningRequests, planningRequest);
        }
    }
    Device2EM device2EM = new Device2EM();
    if (planningRequests.size() > 0) {
        device2EM.setPlanningRequest(planningRequests);
    }
    return marshall(device2EM);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ArrayList(java.util.ArrayList) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger)

Example 24 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempController method createSempTimeFrame.

protected de.avanux.smartapplianceenabler.semp.webservice.Timeframe createSempTimeFrame(ApplianceLogger applianceLogger, String deviceId, Schedule schedule, Interval interval, long minRunningTime, long maxRunningTime, LocalDateTime now) {
    Long earliestStart = 0l;
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();
    if (start.isAfter(now.toDateTime())) {
        earliestStart = Double.valueOf(new Interval(now.toDateTime(), start).toDurationMillis() / 1000).longValue();
    }
    LocalDateTime nowBeforeEnd = new LocalDateTime(now);
    if (now.toDateTime().isAfter(end)) {
        nowBeforeEnd = now.minusHours(24);
    }
    Long latestEnd = Double.valueOf(new Interval(nowBeforeEnd.toDateTime(), end).toDurationMillis() / 1000).longValue();
    return createSempTimeFrame(applianceLogger, deviceId, earliestStart, latestEnd, minRunningTime, maxRunningTime);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval)

Example 25 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_WithinInterval.

@Test
public void getIntervals_SameWeek_WithinInterval() {
    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(5, 18, 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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)66 Test (org.junit.Test)35 DateTime (org.joda.time.DateTime)15 Interval (org.joda.time.Interval)12 LocalDate (org.joda.time.LocalDate)11 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ApplianceLogger (de.avanux.smartapplianceenabler.log.ApplianceLogger)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 DateTimeZone (org.joda.time.DateTimeZone)4 Person (org.qi4j.test.indexing.model.Person)4 HashMap (java.util.HashMap)3 Chronology (org.joda.time.Chronology)3 LocalTime (org.joda.time.LocalTime)3 de.avanux.smartapplianceenabler.appliance (de.avanux.smartapplianceenabler.appliance)2 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)2 GJChronology (org.joda.time.chrono.GJChronology)2 ISOChronology (org.joda.time.chrono.ISOChronology)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2