Search in sources :

Example 1 with Meter

use of de.avanux.smartapplianceenabler.meter.Meter in project SmartApplianceEnabler by camueller.

the class SempController method createDeviceStatus.

private DeviceStatus createDeviceStatus(Appliance appliance) {
    DeviceStatus deviceStatus = new DeviceStatus();
    deviceStatus.setDeviceId(appliance.getId());
    Meter meter = appliance.getMeter();
    Control control = appliance.getControl();
    if (control != null) {
        deviceStatus.setStatus(control.isOn() ? Status.On : Status.Off);
        deviceStatus.setEMSignalsAccepted(appliance.isAcceptControlRecommendations());
        logger.debug("{}: Reporting device status from control", appliance.getId());
    } else {
        // there is no control for the appliance ...
        if (meter != null) {
            // ... but we can derive the status from power consumption
            deviceStatus.setStatus(meter.isOn() ? Status.On : Status.Off);
            logger.debug("{}: Reporting device status based on power consumption", appliance.getId());
        } else {
            // ... and no meter; we have to assume the appliance is switched off
            deviceStatus.setStatus(Status.Offline);
            logger.debug("{}: Appliance has neither control nor meter.", appliance.getId());
        }
        // an appliance without control cannot be controlled ;-)
        deviceStatus.setEMSignalsAccepted(false);
    }
    logger.debug("{}: {}", appliance.getId(), deviceStatus.toString());
    PowerInfo powerInfo = new PowerInfo();
    if (meter != null) {
        logger.debug("{}: Reporting power info from meter.", appliance.getId());
        powerInfo.setAveragePower(meter.getAveragePower());
        powerInfo.setMinPower(meter.getMinPower());
        powerInfo.setMaxPower(meter.getMaxPower());
        // always report 60 for SEMP regardless of real averaging interval
        powerInfo.setAveragingInterval(60);
    } else {
        logger.debug("{}: Reporting power info from device characteristics.", appliance.getId());
        DeviceInfo deviceInfo = ApplianceManager.getInstance().getDeviceInfo(appliance.getId());
        if (deviceStatus.getStatus() == Status.On) {
            powerInfo.setAveragePower(deviceInfo.getCharacteristics().getMaxPowerConsumption());
        } else {
            powerInfo.setAveragePower(0);
        }
        powerInfo.setAveragingInterval(60);
    }
    powerInfo.setTimestamp(0);
    logger.debug("{}: {}", appliance.getId(), powerInfo.toString());
    PowerConsumption powerConsumption = new PowerConsumption();
    powerConsumption.setPowerInfo(Collections.singletonList(powerInfo));
    deviceStatus.setPowerConsumption(Collections.singletonList(powerConsumption));
    return deviceStatus;
}
Also used : Control(de.avanux.smartapplianceenabler.control.Control) Meter(de.avanux.smartapplianceenabler.meter.Meter)

Example 2 with Meter

use of de.avanux.smartapplianceenabler.meter.Meter 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 3 with Meter

use of de.avanux.smartapplianceenabler.meter.Meter in project SmartApplianceEnabler by camueller.

the class TestBuilder method withMockMeter.

public TestBuilder withMockMeter() {
    Meter meter = Mockito.mock(Meter.class);
    getAppliance().setMeter(meter);
    return this;
}
Also used : Meter(de.avanux.smartapplianceenabler.meter.Meter)

Aggregations

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