use of de.avanux.smartapplianceenabler.control.Control 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;
}
use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.
the class SaeController method getControl.
@RequestMapping(value = CONTROL_URL, method = RequestMethod.GET, produces = "application/json")
@CrossOrigin(origins = CROSS_ORIGIN_URL)
public Control getControl(HttpServletResponse response, @RequestParam(value = "id") String applianceId) {
logger.debug("{}: Received request for control", applianceId);
Appliance appliance = getAppliance(applianceId);
if (appliance != null) {
Control control = appliance.getControl();
logger.debug("{}: Returning control {}", applianceId, control);
if (control == null) {
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
return control;
}
logger.error("{}: Appliance not found", applianceId);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return null;
}
use of de.avanux.smartapplianceenabler.control.Control 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());
}
use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.
the class TestBuilder method withMockSwitch.
public TestBuilder withMockSwitch(boolean asStartingCurrentSwitch) {
Control control = new MockSwitch();
if (asStartingCurrentSwitch) {
StartingCurrentSwitch startingCurrentSwitch = new StartingCurrentSwitch();
startingCurrentSwitch.setControl(control);
control = startingCurrentSwitch;
}
getAppliance().setControl(control);
return this;
}
use of de.avanux.smartapplianceenabler.control.Control in project SmartApplianceEnabler by camueller.
the class PulseElectricityMeterTest method getAveragePower_NHZ_NoIntervalIncreaseAboveFactor_TimestampMaxAgeExceeded.
/**
* The power before a power increase should not be reported anymore if there has been no
* timestamp for the time calculated by multiplying the factor with the number of seconds after
* which a timestamp was to be expected (based on power before increase).
* O-----O-----O---OOOO------------------------(---
*/
@Test
public void getAveragePower_NHZ_NoIntervalIncreaseAboveFactor_TimestampMaxAgeExceeded() {
addTimestamps(2085, 1535, 985, 685, 680, 675, 670);
Control control = mock(Control.class);
when(control.isOn()).thenReturn(true);
pulseElectricityMeter.setControl(control);
Assert.assertEquals(0, pulseElectricityMeter.getAveragePower(currentTimeMillis));
}
Aggregations