use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.
the class OslpChannelHandler method performDeviceRegistration.
private DeviceMessageStatus performDeviceRegistration(final Device device) {
if (device == null) {
return DeviceMessageStatus.FAILURE;
}
final String deviceIdentification = device.getDeviceIdentification();
if (!StringUtils.hasText(deviceIdentification)) {
return DeviceMessageStatus.FAILURE;
}
try {
LOGGER.info("Sending DeviceRegistrationRequest for device: {}", deviceIdentification);
this.finishRebooting(device.getDeviceUid());
final DeviceMessageStatus deviceMessageStatus = OslpChannelHandler.this.registerDevice.sendRegisterDeviceCommand(device.getId(), true);
if (DeviceMessageStatus.OK.equals(deviceMessageStatus)) {
LOGGER.info("Sending ConfirmDeviceRegistrationRequest for device: {}", deviceIdentification);
return OslpChannelHandler.this.registerDevice.sendConfirmDeviceRegistrationCommand(device.getId());
} else {
LOGGER.info("Not sending ConfirmDeviceRegistrationRequest for device: {} because DeviceRegistrationRequest ended with status: {}", deviceIdentification, deviceMessageStatus);
}
} catch (final Exception e) {
LOGGER.error("Exception during registration process of device: {}", deviceIdentification, e);
}
return DeviceMessageStatus.FAILURE;
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.
the class OslpChannelHandler method simulateReboot.
private CompletableFuture<DeviceMessageStatus> simulateReboot(final Device device) {
final String deviceUid = device.getDeviceUid();
this.startRebooting(deviceUid);
return CompletableFuture.supplyAsync(() -> {
DeviceMessageStatus result = DeviceMessageStatus.FAILURE;
try {
result = Executors.newSingleThreadScheduledExecutor().schedule(() -> this.performDeviceRegistration(device), this.deviceManagementService.getRebootDelay(), TimeUnit.SECONDS).get();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.error("simulateReboot was interrupted", e);
} catch (final ExecutionException e) {
LOGGER.error("simulateReboot threw an Exception", e);
}
this.finishRebooting(deviceUid);
return result;
});
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.
the class DeviceManagementController method sendEventNotificationCommandAll.
@PostMapping(value = COMMAND_SENDNOTIFICATION_URL)
@ResponseBody
public String sendEventNotificationCommandAll(@RequestBody final SendEventNotificationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendEventNotificationCommand(request.getDeviceId(), request.getEvent(), request.getDescription(), request.getIndex(), request.getHasTimestamp());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_EVENTNOTIFICATION_SENT, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.
the class DeviceManagementController method sendConfirmDeviceRegistrationCommand.
@PostMapping(value = COMMAND_REGISTER_CONFIRM_URL)
@ResponseBody
public String sendConfirmDeviceRegistrationCommand(@RequestBody final ConfirmDeviceRegistrationRequest request) {
// Find device
final Device device = this.deviceManagementService.findDevice(request.getDeviceId());
final DeviceMessageStatus status = this.registerDevice.sendConfirmDeviceRegistrationCommand(request.getDeviceId());
if (status == DeviceMessageStatus.OK) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_REGISTERED_CONFIRM, device.getDeviceIdentification());
} else if (status == DeviceMessageStatus.FAILURE) {
return this.getFeedbackMessage(FEEDBACK_MESSAGE_KEY_DEVICE_ERROR, device.getDeviceIdentification(), this.registerDevice.getErrorMessage());
} else {
return FAILURE_URL;
}
}
use of org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus in project open-smart-grid-platform by OSGP.
the class EventNotificationTransition method run.
@Override
public void run() {
if (Boolean.TRUE.equals(this.deviceManagementService.getEventNotification())) {
// The original list with listofeventtobesent
final List<EventNotificationToBeSent> listeventNotificationToBeSent = this.deviceManagementService.getEventNotificationToBeSent();
// The local list of events
final List<EventNotificationToBeSent> listOfEvents = new ArrayList<>();
// add content of the original list into the local list of events
listOfEvents.addAll(listeventNotificationToBeSent);
// run through the list of events and send each
for (final EventNotificationToBeSent event : listOfEvents) {
DeviceMessageStatus status;
if (Boolean.TRUE.equals(event.getLightOn())) {
// Send EventNotifications for Light Transition ON
LOGGER.info("Sending LIGHT_EVENTS_LIGHT_ON_VALUE event for device: {}", event.getdeviceId());
status = this.registerDevice.sendEventNotificationCommand(event.getdeviceId(), Oslp.Event.LIGHT_EVENTS_LIGHT_ON_VALUE, "LIGHT_EVENTS_LIGHT_ON_VALUE event occurred on Light Switching on ", null);
} else {
// Send EventNotifications for Light Transition OFF
LOGGER.info("Sending LIGHT_EVENTS_LIGHT_OFF_VALUE event for device: {}", event.getdeviceId());
status = this.registerDevice.sendEventNotificationCommand(event.getdeviceId(), Oslp.Event.LIGHT_EVENTS_LIGHT_OFF_VALUE, "LIGHT_EVENTS_LIGHT_OFF_VALUE event occurred on light Switching off ", null);
}
// device then this doesnt work.
if (status == DeviceMessageStatus.OK) {
listeventNotificationToBeSent.remove(event);
}
}
// The local list of events
listOfEvents.clear();
}
}
Aggregations