bunti/src/main/java/de/ctdo/bunti/web/DeviceControlController.java

41 lines
1.4 KiB
Java

package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.model.DeviceUpdate;
import de.ctdo.bunti.web.model.DeviceUpdates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(value = "/control")
public class DeviceControlController {
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceControlController.class);
@Autowired
private BuntiController controller;
@RequestMapping(value = "/devices", method = RequestMethod.POST)
@ResponseBody
public String setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle POST /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
}
return "{\"status\":\"OK\"}";
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
@ResponseBody
public DeviceUpdate getDeviceValues(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/{id} " + id );
return controller.getDeviceValues(id);
}
}