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

34 lines
1.2 KiB
Java

package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.webmodel.DeviceUpdate;
import de.ctdo.bunti.webmodel.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);
private BuntiController controller;
@Autowired
public final void setController(BuntiController controller) {
this.controller = controller;
}
@RequestMapping(value = "/devices", method = RequestMethod.POST)
public void setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
}
}
}