Search in sources :

Example 1 with ApplianceStatus

use of de.avanux.smartapplianceenabler.webservice.ApplianceStatus in project SmartApplianceEnabler by camueller.

the class IntegrationTest method testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval.

@Test
public void testSwitchOnAndOff_startingCurrentDetectedDuringTimeframeInterval() {
    String applianceId = "F-001";
    TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(true).withMockMeter().withSchedule(10, 0, 18, 0, 3600, null).init();
    Appliance appliance = builder.getAppliance();
    StartingCurrentSwitch control = (StartingCurrentSwitch) appliance.getControl();
    Meter meter = appliance.getMeter();
    RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
    log("Check initial values");
    assertRunningTime(null, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
    log("Detect starting current");
    LocalDateTime timeBeforeStartingCurrent = toToday(11, 29, 0);
    Mockito.when(meter.getAveragePower()).thenReturn(StartingCurrentSwitchDefaults.getPowerThreshold() + 1);
    control.detectStartingCurrent(timeBeforeStartingCurrent, meter);
    assertRunningTime(timeBeforeStartingCurrent, control, runningTimeMonitor, false, true, false, false, false, null, null, null);
    Assert.assertEquals(0, sempController.createDevice2EM(timeBeforeStartingCurrent).getPlanningRequest().size());
    LocalDateTime timeStartingCurrent = toToday(11, 30, 0);
    control.detectStartingCurrent(toToday(11, 30, 0), meter);
    assertRunningTime(timeStartingCurrent, control, runningTimeMonitor, false, false, false, false, true, 0, 3600, null);
    assertPlanningRequest(timeStartingCurrent, new Timeframe(applianceId, 0, 23400, 3599, 3600));
    log("Switch on");
    LocalDateTime timeSwitchOn = toToday(12, 0, 0);
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    log("Check values after switch on");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, true, false, true, 0, 3600, null);
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 21600, 3599, 3600));
    ApplianceStatus applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
    Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
    log("Switch off");
    LocalDateTime timeSwitchOff = toToday(13, 0, 0);
    sempController.em2Device(timeSwitchOff, createEM2Device(applianceId, false));
    log("Check values after switch off");
    assertRunningTime(timeSwitchOff, control, runningTimeMonitor, false, true, false, true, true, 3600, 0, null);
    Assert.assertEquals(0, sempController.createDevice2EM(timeSwitchOff).getPlanningRequest().size());
// TODO nochmal an/aus schalten
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) StartingCurrentSwitch(de.avanux.smartapplianceenabler.control.StartingCurrentSwitch) Meter(de.avanux.smartapplianceenabler.meter.Meter) ApplianceStatus(de.avanux.smartapplianceenabler.webservice.ApplianceStatus) TestBuilder(de.avanux.smartapplianceenabler.test.TestBuilder) Test(org.junit.Test)

Example 2 with ApplianceStatus

use of de.avanux.smartapplianceenabler.webservice.ApplianceStatus in project SmartApplianceEnabler by camueller.

the class IntegrationTest method testClickGoLight.

@Test
public void testClickGoLight() {
    String applianceId = "F-001";
    TestBuilder builder = new TestBuilder().appliance(applianceId).withMockSwitch(false).withSchedule(10, 0, 18, 0, 3600, null).init();
    Appliance appliance = builder.getAppliance();
    Control control = appliance.getControl();
    RunningTimeMonitor runningTimeMonitor = appliance.getRunningTimeMonitor();
    log("Check initial values");
    Assert.assertFalse(control.isOn());
    Assert.assertNull(runningTimeMonitor.getActiveTimeframeInterval());
    log("Set runtime creates timeframe to be set");
    LocalDateTime timeSwitchOn = toToday(11, 0, 0);
    Assert.assertEquals(3600, saeController.suggestRuntime(applianceId).intValue());
    saeController.setRuntime(timeSwitchOn, applianceId, 1800);
    Assert.assertNotNull(runningTimeMonitor.getActiveTimeframeInterval());
    log("Switch on");
    sempController.em2Device(timeSwitchOn, createEM2Device(applianceId, true));
    log("Check values after switch on");
    assertRunningTime(timeSwitchOn, control, runningTimeMonitor, true, true, false, 0, 1800, null);
    assertPlanningRequest(timeSwitchOn, new Timeframe(applianceId, 0, 1800, 1799, 1800), new Timeframe(applianceId, add24h(-3600), add24h(25200), 3599, 3600), new Timeframe(applianceId, add48h(-3600), add48h(25200), 3599, 3600));
    ApplianceStatus applianceStatusAfterSwitchOn = getApplianceStatus(timeSwitchOn);
    Assert.assertTrue(applianceStatusAfterSwitchOn.isOn());
    log("Update timeframe intervals right after min running time is reached");
    log("Timeframe interval created is deactivated and timeframe interval of schedule is activated");
    LocalDateTime timeAfterExpiration = toToday(11, 30, 1);
    runningTimeMonitor.updateActiveTimeframeInterval(timeAfterExpiration);
    log("Check values after expiration");
    assertRunningTime(timeAfterExpiration, control, runningTimeMonitor, false, false, false, 0, 3600, null);
    assertPlanningRequest(timeAfterExpiration, new Timeframe(applianceId, 0, 23399, 3599, 3600), new Timeframe(applianceId, add24h(-5401), add24h(23399), 3599, 3600), new Timeframe(applianceId, add48h(-5401), add48h(23399), 3599, 3600));
    ApplianceStatus applianceStatusAfterSwitchOff = getApplianceStatus(timeAfterExpiration);
    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 3 with ApplianceStatus

use of de.avanux.smartapplianceenabler.webservice.ApplianceStatus 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)

Aggregations

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