bunti/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java

56 lines
1.6 KiB
Java

package de.ctdo.bunti.control;
import java.util.Map;
import de.ctdo.bunti.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
@Component
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
private ApplicationEventPublisher applicationEventPublisher = null;
@Autowired
private BuntiDevicesDAO devicesDAO;
@Autowired
private DeviceValueCache deviceCache;
@Override
public final void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.applicationEventPublisher = publisher;
}
@Override
public final boolean updateDeviceData(int deviceId, Map<String, Object> options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) {
LOGGER.debug("publishEvent in BuntiController");
deviceCache.updateData(deviceId, options);
device.setValuesFromOptions(options) ;
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
return true;
}
return false;
}
@Override
public DeviceUpdate getDeviceValues(int deviceId) {
return deviceCache.getData(deviceId);
}
}