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;
}
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);
}
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);
}
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);
}
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());
}
Aggregations