Search in sources :

Example 6 with Control

use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.

the class PulseElectricityMeterTest method getAveragePower_NHZ.

/**
 * Make sure that some power value during ramp up is not reported as "before increase" value
 * after switch off.
 * O-----O-----O---OOOO-(---
 */
@Test
public void getAveragePower_NHZ() {
    addTimestamps(3000, 1800, 700, 100, 90, 80, 70);
    Control control = mock(Control.class);
    when(control.isOn()).thenReturn(true);
    pulseElectricityMeter.setControl(control);
    Assert.assertEquals(6, pulseElectricityMeter.getAveragePower(currentTimeMillis));
}
Also used : Control(de.avanux.smartapplianceenabler.control.Control) Test(org.junit.Test)

Example 7 with Control

use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.

the class IntegrationTest method testSwitchOnAndOff.

@Test
public void testSwitchOnAndOff() {
    String applianceId = "F-001";
    TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(false).withSchedule(10, 0, 18, 0, 7200, null).init();
    Appliance appliance = builder.getAppliance();
    Control control = appliance.getControl();
    RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
    log("Check initial values");
    LocalDateTime timeTimeframeStart = toToday(10, 0, 0);
    Assert.assertFalse(control.isOn());
    Assert.assertNull(runningTimeMonitor.getActiveTimeframeInterval());
    assertPlanningRequest(timeTimeframeStart, new Timeframe(applianceId, 0, 28800, 7199, 7200), new Timeframe(applianceId, add24h(0), add24h(28800), 7199, 7200));
    logger.debug("########## First switching cycle");
    log("Update timeframe intervals right before switch on");
    LocalDateTime timeSwitchOn = toToday(11, 0, 0);
    runningTimeMonitor.updateActiveTimeframeInterval(timeSwitchOn);
    Assert.assertNotNull(runningTimeMonitor.getActiveTimeframeInterval());
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 25200, 7199, 7200), new Timeframe(applianceId, add24h(-3600), add24h(25200), 7199, 7200), new Timeframe(applianceId, add48h(-3600), add48h(25200), 7199, 7200));
    log("Switch on");
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    log("Check values after switch on");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, false, 0, 7200, null);
    ApplianceStatus applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
    Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 25200, 7199, 7200), new Timeframe(applianceId, add24h(-3600), add24h(25200), 7199, 7200), new Timeframe(applianceId, add48h(-3600), add48h(25200), 7199, 7200));
    log("Switch off");
    LocalDateTime timeSwitchOff = toToday(12, 0, 0);
    sempController.em2Device(timeSwitchOff, createEM2Device(applianceId, false));
    log("Update timeframe intervals right after switch off");
    runningTimeMonitor.updateActiveTimeframeInterval(timeSwitchOff);
    log("Check values after switch off");
    assertRunningTime(timeSwitchOff, control, runningTimeMonitor, false, false, true, 3600, 3600, null);
    assertPlanningRequest(timeSwitchOff, new Timeframe(applianceId, 0, 21600, 3599, 3600), new Timeframe(applianceId, add24h(-7200), add24h(21600), 7199, 7200), new Timeframe(applianceId, add48h(-7200), add48h(21600), 7199, 7200));
    ApplianceStatus applianceStatusAfterSwitchOff = getApplianceStatus(timeSwitchOff);
    Assert.assertFalse(applianceStatusAfterSwitchOff.isOn());
    logger.debug("########## Second switching cycle");
    log("Switch on");
    timeSwitchOn = toToday(16, 0, 0);
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    log("Check values after switch on");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, false, 3600, 3600, null);
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 7200, 3599, 3600), new Timeframe(applianceId, add24h(-21600), add24h(7200), 7199, 7200), new Timeframe(applianceId, add48h(-21600), add48h(7200), 7199, 7200));
    applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
    Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
    log("Switch off");
    timeSwitchOff = toToday(17, 0, 0);
    sempController.em2Device(timeSwitchOff, createEM2Device(applianceId, false));
    log("Update timeframe intervals right after switch off");
    runningTimeMonitor.updateActiveTimeframeInterval(timeSwitchOff);
    log("Check values after switch off");
    assertRunningTime(timeSwitchOff, control, runningTimeMonitor, false, false, true, 7200, 0, null);
    assertPlanningRequest(timeSwitchOff, new Timeframe(applianceId, add24h(-25200), add24h(3600), 7199, 7200), new Timeframe(applianceId, add48h(-25200), add48h(3600), 7199, 7200));
    applianceStatusAfterSwitchOff = getApplianceStatus(timeSwitchOff);
    Assert.assertFalse(applianceStatusAfterSwitchOff.isOn());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Control(de.avanux.smartapplianceenabler.control.Control) ApplianceStatus(de.avanux.smartapplianceenabler.webservice.ApplianceStatus) TestBuilder(de.avanux.smartapplianceenabler.test.TestBuilder) Test(org.junit.Test)

Example 8 with Control

use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.

the class IntegrationTest method testSwitchOnBeforeTimeframeIntervalStart.

@Test
public void testSwitchOnBeforeTimeframeIntervalStart() {
    String applianceId = "F-001";
    TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(false).withMockMeter().withSchedule(10, 0, 18, 0, 3600, null).init();
    Appliance appliance = builder.getAppliance();
    Control control = (MockSwitch) appliance.getControl();
    RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
    log("Switch on");
    LocalDateTime timeSwitchOn = toToday(9, 59, 0);
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    Assert.assertTrue("It should be possible to set appliance control state to running before " + "the timeframe interval started", runningTimeMonitor.isRunning());
    log("Check values right after switch on before interval start");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, false, false, null, null, null);
    log("Check values after switch on right before interval start");
    LocalDateTime timeBeforeIntervalStart = toToday(9, 59, 59);
    runningTimeMonitor.updateActiveTimeframeInterval(timeBeforeIntervalStart);
    assertRunningTime(timeBeforeIntervalStart, control, runningTimeMonitor, true, true, false, false, null, null, null);
    log("Check values after switch on right after interval start");
    LocalDateTime timeIntervalStart = toToday(10, 0, 0);
    runningTimeMonitor.updateActiveTimeframeInterval(timeIntervalStart);
    assertRunningTime(timeIntervalStart, control, runningTimeMonitor, true, true, false, true, 60, 3540, null);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Control(de.avanux.smartapplianceenabler.control.Control) MockSwitch(de.avanux.smartapplianceenabler.control.MockSwitch) TestBuilder(de.avanux.smartapplianceenabler.test.TestBuilder) Test(org.junit.Test)

Aggregations

Control (de.avanux.smartapplianceenabler.control.Control)8 Test (org.junit.Test)5 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)3 LocalDateTime (org.joda.time.LocalDateTime)3 MockSwitch (de.avanux.smartapplianceenabler.control.MockSwitch)2 ApplianceStatus (de.avanux.smartapplianceenabler.webservice.ApplianceStatus)2 StartingCurrentSwitch (de.avanux.smartapplianceenabler.control.StartingCurrentSwitch)1 Meter (de.avanux.smartapplianceenabler.meter.Meter)1