Search in sources :

Example 1 with DeviceMessageStatus

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;
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) ByteString(com.google.protobuf.ByteString) DeviceSimulatorException(org.opensmartgridplatform.webdevicesimulator.exceptions.DeviceSimulatorException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with DeviceMessageStatus

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;
    });
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with DeviceMessageStatus

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;
    }
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) RegisterDevice(org.opensmartgridplatform.webdevicesimulator.service.RegisterDevice) Device(org.opensmartgridplatform.webdevicesimulator.domain.entities.Device) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with DeviceMessageStatus

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;
    }
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) RegisterDevice(org.opensmartgridplatform.webdevicesimulator.service.RegisterDevice) Device(org.opensmartgridplatform.webdevicesimulator.domain.entities.Device) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with DeviceMessageStatus

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();
    }
}
Also used : DeviceMessageStatus(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus) EventNotificationToBeSent(org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent) ArrayList(java.util.ArrayList)

Aggregations

DeviceMessageStatus (org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceMessageStatus)6 Device (org.opensmartgridplatform.webdevicesimulator.domain.entities.Device)3 RegisterDevice (org.opensmartgridplatform.webdevicesimulator.service.RegisterDevice)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EventNotificationToBeSent (org.opensmartgridplatform.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent)1 DeviceSimulatorException (org.opensmartgridplatform.webdevicesimulator.exceptions.DeviceSimulatorException)1