Search in sources :

Example 1 with ApplianceLogger

use of de.avanux.smartapplianceenabler.log.ApplianceLogger in project SmartApplianceEnabler by camueller.

the class SempController method planningRequest.

@RequestMapping(value = BASE_URL + "/PlanningRequest", method = RequestMethod.GET, produces = "application/xml")
@ResponseBody
public String planningRequest(@RequestParam(value = "DeviceId", required = false) String deviceId) {
    LocalDateTime now = new LocalDateTime();
    List<PlanningRequest> planningRequests = new ArrayList<PlanningRequest>();
    if (deviceId != null) {
        ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, deviceId);
        applianceLogger.debug("Planning request requested");
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
        PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
        addPlanningRequest(planningRequests, planningRequest);
    } else {
        logger.debug("Planning request requested of all devices");
        List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
        for (Appliance appliance : appliances) {
            ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, appliance.getId());
            PlanningRequest planningRequest = createPlanningRequest(applianceLogger, now, appliance);
            addPlanningRequest(planningRequests, planningRequest);
        }
    }
    Device2EM device2EM = new Device2EM();
    if (planningRequests.size() > 0) {
        device2EM.setPlanningRequest(planningRequests);
    }
    return marshall(device2EM);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ArrayList(java.util.ArrayList) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger)

Example 2 with ApplianceLogger

use of de.avanux.smartapplianceenabler.log.ApplianceLogger in project SmartApplianceEnabler by camueller.

the class SempController method deviceStatus.

@RequestMapping(value = BASE_URL + "/DeviceStatus", method = RequestMethod.GET, produces = "application/xml")
@ResponseBody
public String deviceStatus(@RequestParam(value = "DeviceId", required = false) String deviceId) {
    List<DeviceStatus> deviceStatuses = new ArrayList<DeviceStatus>();
    if (deviceId != null) {
        ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, deviceId);
        applianceLogger.debug("Device status requested");
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
        DeviceStatus deviceStatus = createDeviceStatus(applianceLogger, appliance);
        deviceStatuses.add(deviceStatus);
    } else {
        logger.debug("Device status requested of all devices");
        List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
        for (Appliance appliance : appliances) {
            ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, appliance.getId());
            DeviceStatus deviceStatus = createDeviceStatus(applianceLogger, appliance);
            deviceStatuses.add(deviceStatus);
        }
    }
    Device2EM device2EM = new Device2EM();
    device2EM.setDeviceStatus(deviceStatuses);
    return marshall(device2EM);
}
Also used : ArrayList(java.util.ArrayList) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger)

Example 3 with ApplianceLogger

use of de.avanux.smartapplianceenabler.log.ApplianceLogger in project SmartApplianceEnabler by camueller.

the class SempController method em2Device.

@RequestMapping(value = BASE_URL, method = RequestMethod.POST, consumes = "application/xml")
@ResponseBody
public void em2Device(@RequestBody EM2Device em2Device) {
    List<DeviceControl> deviceControls = em2Device.getDeviceControl();
    for (DeviceControl deviceControl : deviceControls) {
        ApplianceLogger applianceLogger = ApplianceLogger.createForAppliance(logger, deviceControl.getDeviceId());
        applianceLogger.debug("Received control request");
        Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceControl.getDeviceId());
        if (appliance != null) {
            setApplianceState(applianceLogger, appliance, deviceControl.isOn(), "Setting appliance state to " + (deviceControl.isOn() ? "ON" : "OFF"));
        } else {
            applianceLogger.warn("No appliance configured for device id " + deviceControl.getDeviceId());
        }
    }
}
Also used : ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger)

Example 4 with ApplianceLogger

use of de.avanux.smartapplianceenabler.log.ApplianceLogger in project SmartApplianceEnabler by camueller.

the class SempControllerTest method createSempTimeFrame.

@Test
public void createSempTimeFrame() {
    ApplianceLogger logger = new ApplianceLogger(LoggerFactory.getLogger(Appliance.class));
    logger.setApplianceId(DEVICE_ID);
    LocalDateTime now = toToday(0, 30, 0);
    Schedule schedule = new Schedule(7200, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    de.avanux.smartapplianceenabler.semp.webservice.Timeframe sempTimeFrame = sempController.createSempTimeFrame(logger, DEVICE_ID, schedule, interval, 0, 0, now);
    Assert.assertEquals(1800, (long) sempTimeFrame.getEarliestStart());
    Assert.assertEquals(30600, (long) sempTimeFrame.getLatestEnd());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 5 with ApplianceLogger

use of de.avanux.smartapplianceenabler.log.ApplianceLogger in project SmartApplianceEnabler by camueller.

the class SempControllerTest method createSempTimeFrame_TimeFrameOverMidnight_BeforeMidnight.

@Test
public void createSempTimeFrame_TimeFrameOverMidnight_BeforeMidnight() {
    ApplianceLogger logger = new ApplianceLogger(LoggerFactory.getLogger(Appliance.class));
    logger.setApplianceId(DEVICE_ID);
    LocalDateTime now = toToday(23, 30, 0);
    Schedule schedule = new Schedule(7200, 7200, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    de.avanux.smartapplianceenabler.semp.webservice.Timeframe sempTimeFrame = sempController.createSempTimeFrame(logger, DEVICE_ID, schedule, interval, 0, 0, now);
    Assert.assertEquals(0, (long) sempTimeFrame.getEarliestStart());
    Assert.assertEquals(16200, (long) sempTimeFrame.getLatestEnd());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

ApplianceLogger (de.avanux.smartapplianceenabler.log.ApplianceLogger)9 LocalDateTime (org.joda.time.LocalDateTime)4 ArrayList (java.util.ArrayList)3 Interval (org.joda.time.Interval)3 Test (org.junit.Test)3 Appliance (de.avanux.smartapplianceenabler.appliance.Appliance)1 Schedule (de.avanux.smartapplianceenabler.appliance.Schedule)1