use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method getIntervals_DayOfWeekNotMatching_BeforeIntervalStart.
@Test
public void getIntervals_DayOfWeekNotMatching_BeforeIntervalStart() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(3));
LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
List<TimeframeInterval> intervals = timeframe.getIntervals(now);
Assert.assertEquals(1, intervals.size());
Assert.assertEquals(new Interval(toDayOfWeek(now, 3, 10, 0, 0).toDateTime(), toDayOfWeek(now, 3, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class Appliance method createRuntimeRequest.
protected RuntimeRequest createRuntimeRequest(Interval interval, Integer minRunningTime, Integer maxRunningTime, LocalDateTime now) {
Integer earliestStart = 0;
DateTime start = interval.getStart();
DateTime end = interval.getEnd();
if (start.isAfter(now.toDateTime())) {
earliestStart = Double.valueOf(new Interval(now.toDateTime(), start).toDurationMillis() / 1000).intValue();
}
LocalDateTime nowBeforeEnd = new LocalDateTime(now);
if (now.toDateTime().isAfter(end)) {
nowBeforeEnd = now.minusHours(24);
}
Integer latestEnd = Double.valueOf(new Interval(nowBeforeEnd.toDateTime(), end).toDurationMillis() / 1000).intValue();
if (maxRunningTime != null && maxRunningTime > latestEnd) {
maxRunningTime = latestEnd;
}
return createRuntimeRequest(earliestStart, latestEnd, minRunningTime, maxRunningTime);
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class Appliance method finishedCurrentDetected.
@Override
public void finishedCurrentDetected() {
if (runningTimeMonitor != null) {
logger.debug("{}: Deactivating timeframe interval until starting current is detected again", id);
runningTimeMonitor.activateTimeframeInterval(new LocalDateTime(), (TimeframeInterval) null);
}
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class Appliance method start.
public void start(Timer timer, GpioController gpioController, Map<String, PulseReceiver> pulseReceiverIdWithPulseReceiver, Map<String, ModbusTcp> modbusIdWithModbusTcp) {
if (runningTimeMonitor != null) {
runningTimeMonitor.setTimer(timer);
}
for (GpioControllable gpioControllable : getGpioControllables()) {
logger.info("{}: Starting {}", id, gpioControllable.getClass().getSimpleName());
gpioControllable.setGpioController(gpioController);
gpioControllable.start();
}
if (meter != null && meter instanceof S0ElectricityMeterNetworked) {
S0ElectricityMeterNetworked s0ElectricityMeterNetworked = (S0ElectricityMeterNetworked) meter;
logger.info("{}: Starting {}", id, S0ElectricityMeterNetworked.class.getSimpleName());
String pulseReceiverId = s0ElectricityMeterNetworked.getIdref();
PulseReceiver pulseReceiver = pulseReceiverIdWithPulseReceiver.get(pulseReceiverId);
s0ElectricityMeterNetworked.setPulseReceiver(pulseReceiver);
s0ElectricityMeterNetworked.start();
}
if (meter != null && meter instanceof HttpElectricityMeter) {
((HttpElectricityMeter) meter).start(timer);
}
for (ModbusSlave modbusSlave : getModbusSlaves()) {
logger.info("{}: Starting {}", id, modbusSlave.getClass().getSimpleName());
modbusSlave.setApplianceId(id);
String modbusId = modbusSlave.getIdref();
ModbusTcp modbusTcp = modbusIdWithModbusTcp.get(modbusId);
modbusSlave.setModbusTcp(modbusTcp);
}
if (meter != null && meter instanceof ModbusElectricityMeter) {
((ModbusElectricityMeter) meter).start(timer);
}
if (control != null && control instanceof StartingCurrentSwitch) {
logger.info("{}: Starting {}", id, StartingCurrentSwitch.class.getSimpleName());
((StartingCurrentSwitch) control).start(new LocalDateTime(), getMeter(), timer);
}
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedAndActive_NotSufficient.
@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedAndActive_NotSufficient() {
int nowSeconds = 10;
LocalDateTime now = toToday(11, 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, 3600 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
Assert.assertEquals(new RuntimeRequest(75600 - nowSeconds, 90000 - nowSeconds, 3600, null), runtimeRequests.get(1));
Assert.assertEquals(new RuntimeRequest(162000 - nowSeconds, 176400 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
Aggregations