Search in sources :

Example 1 with EventNotificationToBeSent

use of com.alliander.osgp.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent in project Protocol-Adapter-OSLP by OSGP.

the class EventNotificationTransition method run.

@Override
public void run() {
    if (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 (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(com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus) EventNotificationToBeSent(com.alliander.osgp.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent) ArrayList(java.util.ArrayList)

Aggregations

DeviceMessageStatus (com.alliander.osgp.webdevicesimulator.domain.entities.DeviceMessageStatus)1 EventNotificationToBeSent (com.alliander.osgp.webdevicesimulator.domain.valueobjects.EventNotificationToBeSent)1 ArrayList (java.util.ArrayList)1