Search in sources :

Example 1 with RelayStatus

use of org.opensmartgridplatform.domain.core.entities.RelayStatus in project open-smart-grid-platform by OSGP.

the class SsldDeviceSteps method aSwitchingEventRelayStatus.

@Given("^a switching event relay status$")
@Transactional("txMgrCore")
public void aSwitchingEventRelayStatus(final Map<String, String> settings) {
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, PlatformDefaults.DEVICE_OUTPUT_SETTINGS).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final String[] relayStatuses = getString(settings, PlatformKeys.RELAY_STATUSES, PlatformDefaults.RELAY_STATUSES).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final List<DeviceOutputSetting> dosList = new ArrayList<>();
    for (final String dos : deviceOutputSettings) {
        final String[] deviceOutputSetting = dos.split(PlatformKeys.SEPARATOR_COMMA);
        dosList.add(new DeviceOutputSetting(Integer.parseInt(deviceOutputSetting[0]), Integer.parseInt(deviceOutputSetting[1]), RelayType.valueOf(deviceOutputSetting[2]), deviceOutputSetting[3]));
    }
    ssld.updateOutputSettings(dosList);
    for (final String rs : relayStatuses) {
        final String[] relayStatus = rs.split(PlatformKeys.SEPARATOR_COMMA);
        final int index = Integer.parseInt(relayStatus[0]);
        final boolean lastSwitchingEventState = Boolean.parseBoolean(relayStatus[1]);
        final Date lastSwitchingEventTime = getDateTime2(relayStatus[2], DateTime.now()).toDate();
        final RelayStatus currentRelayStatus = ssld.getRelayStatusByIndex(index);
        if (currentRelayStatus == null) {
            this.relayStatusRepository.save(new RelayStatus.Builder(ssld, index).withLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime).build());
        } else {
            currentRelayStatus.updateLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime);
            this.relayStatusRepository.save(currentRelayStatus);
        }
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Date(java.util.Date) ReadSettingsHelper.getDate(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getDate) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RelayStatus

use of org.opensmartgridplatform.domain.core.entities.RelayStatus in project open-smart-grid-platform by OSGP.

the class DeviceOutputSettingsSteps method saveDeviceOutputSettingsAndRelayStatuses.

private void saveDeviceOutputSettingsAndRelayStatuses(final List<DeviceOutputSetting> deviceOutputSettings, final Ssld device) {
    device.updateOutputSettings(deviceOutputSettings);
    this.ssldRepository.save(device);
    // Create a dummy relay status for each device output setting
    for (final DeviceOutputSetting deviceOutputSetting : deviceOutputSettings) {
        final RelayStatus relayStatus = new RelayStatus.Builder(device, deviceOutputSetting.getExternalId()).withLastSwitchingEventState(false, new Date()).build();
        this.relayStatusRepository.save(relayStatus);
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Date(java.util.Date)

Example 3 with RelayStatus

use of org.opensmartgridplatform.domain.core.entities.RelayStatus in project open-smart-grid-platform by OSGP.

the class RelayStatusSteps method thereIsADeviceRelayStatusWithARecentLastKnownTime.

@Then("^there is a device relay status with a recent last known state time$")
public void thereIsADeviceRelayStatusWithARecentLastKnownTime(final Map<String, String> settings) {
    final RelayStatus expected = this.relayStatusFactory.fromMap(settings);
    Wait.until(() -> {
        final RelayStatus actual = this.relayStatusFactory.fromDb(settings);
        this.assertLastSwitchingEventEquals(expected, actual);
        // Check if the last known state time is at most 3 minutes in the
        // past
        final Date startDate = DateTime.now().minusMinutes(3).toDate();
        assertThat(actual.getLastKnownStateTime().after(startDate)).isTrue();
        assertThat(actual.isLastKnownState()).isEqualTo(expected.isLastKnownState());
    });
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) Date(java.util.Date) Then(io.cucumber.java.en.Then)

Example 4 with RelayStatus

use of org.opensmartgridplatform.domain.core.entities.RelayStatus in project open-smart-grid-platform by OSGP.

the class RelayStatusFactory method fromMap.

public RelayStatus fromMap(final Ssld ssld, final Map<String, String> settings) {
    final Integer index = getInteger(settings, PlatformKeys.KEY_INDEX);
    final boolean lastSwitchingEventState = "On".equals(getString(settings, PlatformKeys.LAST_SWITCHING_EVENT_STATE));
    final DateTime lastSwitchingEventTime = getDate(settings, PlatformKeys.LAST_SWITCHING_EVENT_TIME);
    final boolean lastKnownState = "On".equals(getString(settings, PlatformKeys.LAST_KNOWN_STATE));
    final DateTime lastKnownStateTime = getDate(settings, PlatformKeys.LAST_KNOWN_STATE_TIME);
    final RelayStatus relayStatus = new RelayStatus.Builder(ssld, index).withLastKnownState(lastKnownState, lastKnownStateTime.toDate()).withLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime.toDate()).build();
    return relayStatus;
}
Also used : ReadSettingsHelper.getInteger(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger) RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) DateTime(org.joda.time.DateTime)

Example 5 with RelayStatus

use of org.opensmartgridplatform.domain.core.entities.RelayStatus in project open-smart-grid-platform by OSGP.

the class EventNotificationMessageService method createRelayStatus.

private void createRelayStatus(final Device device, final Event switchingEvent, final Integer relayIndex, final Map<Integer, RelayStatus> lastRelayStatusPerIndex) {
    final EventType eventType = switchingEvent.getEventType();
    final boolean isRelayOn = EventType.LIGHT_EVENTS_LIGHT_ON.equals(eventType) || EventType.TARIFF_EVENTS_TARIFF_ON.equals(eventType);
    if (lastRelayStatusPerIndex.get(relayIndex) == null || switchingEvent.getDateTime().after(lastRelayStatusPerIndex.get(relayIndex).getLastSwitchingEventTime())) {
        final RelayStatus relayStatus = new RelayStatus.Builder(device, relayIndex).withLastSwitchingEventState(isRelayOn, switchingEvent.getDateTime()).build();
        lastRelayStatusPerIndex.put(relayIndex, relayStatus);
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType)

Aggregations

RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)13 Date (java.util.Date)6 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 Then (io.cucumber.java.en.Then)3 ReadSettingsHelper.getInteger (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getInteger)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)3 Given (io.cucumber.java.en.Given)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 Event (org.opensmartgridplatform.domain.core.entities.Event)2 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ReadSettingsHelper.getDate (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getDate)1 EventType (org.opensmartgridplatform.domain.core.valueobjects.EventType)1 LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)1 TariffValue (org.opensmartgridplatform.domain.core.valueobjects.TariffValue)1 Transactional (org.springframework.transaction.annotation.Transactional)1