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);
}
}
}
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);
}
}
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());
});
}
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;
}
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);
}
}
Aggregations