Search in sources :

Example 1 with RelayType

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

the class RelayMapConverter method convertIndexAddressMapToRelayMap.

/**
 * Converts an IndexAddressMap received from an OSLP device to a RelayMap
 *
 * @param indexAddressMap the IndexAddressMap to convert.
 * @return the created RelayMap.
 */
private static RelayMap convertIndexAddressMapToRelayMap(final IndexAddressMap indexAddressMap) {
    final RelayType relayType = RelayType.valueOf(indexAddressMap.getRelayType().toString());
    final Integer relayIndex = OslpUtils.byteStringToInteger(indexAddressMap.getIndex());
    final Integer relayAddress = OslpUtils.byteStringToInteger(indexAddressMap.getAddress());
    return new RelayMap(relayIndex, relayAddress, relayType, null);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap)

Example 2 with RelayType

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

the class SsldDeviceSteps method createAnSsldDevice.

private Ssld createAnSsldDevice(final Map<String, String> settings) {
    // Set the required stuff
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final Ssld ssld = new Ssld(deviceIdentification);
    ssld.setPublicKeyPresent(getBoolean(settings, PlatformKeys.KEY_PUBLICKEYPRESENT, PlatformDefaults.DEFAULT_PUBLICKEYPRESENT));
    ssld.setHasSchedule(getBoolean(settings, PlatformKeys.KEY_HAS_SCHEDULE, PlatformDefaults.DEFAULT_HASSCHEDULE));
    if (settings.containsKey(PlatformKeys.KEY_INTERNALID) || settings.containsKey(PlatformKeys.KEY_EXTERNALID) || settings.containsKey(PlatformKeys.KEY_RELAY_TYPE)) {
        final List<DeviceOutputSetting> dosList = new ArrayList<>();
        final int internalId = getInteger(settings, PlatformKeys.KEY_INTERNALID, PlatformDefaults.DEFAULT_INTERNALID), externalId = getInteger(settings, PlatformKeys.KEY_EXTERNALID, PlatformDefaults.DEFAULT_EXTERNALID);
        final RelayType relayType = getEnum(settings, PlatformKeys.KEY_RELAY_TYPE, RelayType.class, RelayType.LIGHT);
        if (relayType != null) {
            dosList.add(new DeviceOutputSetting(internalId, externalId, relayType));
            ssld.updateOutputSettings(dosList);
        }
    }
    ssld.updateInMaintenance(getBoolean(settings, PlatformKeys.DEVICE_IN_MAINTENANCE, PlatformDefaults.DEVICE_IN_MAINTENANCE));
    ssld.setFailedConnectionCount(getInteger(settings, PlatformKeys.KEY_FAILED_CONNECTION_COUNT, PlatformDefaults.DEFAULT_FAILED_CONNECTION_COUNT));
    final DateTime lastSuccessfulConnectionTimestamp = getDate(settings, PlatformKeys.KEY_LAST_COMMUNICATION_TIME, DateTime.now());
    ssld.setLastSuccessfulConnectionTimestamp(lastSuccessfulConnectionTimestamp.toDate());
    if (settings.containsKey(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION)) {
        final LightMeasurementDevice lmd = this.lmdRepository.findByDeviceIdentification(settings.get(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION));
        ssld.setLightMeasurementDevice(lmd);
    }
    this.ssldRepository.save(ssld);
    // now update the common stuff of the SSLD device.
    this.updateDevice(deviceIdentification, settings);
    // Return the updated ssld device.
    return this.ssldRepository.findByDeviceIdentification(deviceIdentification);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DateTime(org.joda.time.DateTime) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)1 RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)1