Search in sources :

Example 91 with LocalDateTime

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 92 with LocalDateTime

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);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval)

Example 93 with LocalDateTime

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);
    }
}
Also used : LocalDateTime(org.joda.time.LocalDateTime)

Example 94 with LocalDateTime

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);
    }
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ModbusSlave(de.avanux.smartapplianceenabler.modbus.ModbusSlave) ModbusTcp(de.avanux.smartapplianceenabler.modbus.ModbusTcp)

Example 95 with LocalDateTime

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

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4