Search in sources :

Example 1 with RelayConfiguration

use of org.opensmartgridplatform.oslp.Oslp.RelayConfiguration in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method aSetConfigurationOslpMessageIsSentToDevice.

/**
 * Verify that a set configuration OSLP message is sent to the device.
 *
 * @param deviceIdentification The device identification expected in the message to the device.
 */
@Then("^a set configuration \"([^\"]*)\" message is sent to device \"([^\"]*)\"$")
public void aSetConfigurationOslpMessageIsSentToDevice(final String protocol, final String deviceIdentification, final Map<String, String> expectedResponseData) throws DeviceSimulatorException {
    final Message receivedMessage = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedResponseData), MessageType.SET_CONFIGURATION);
    assertThat(receivedMessage).isNotNull();
    assertThat(receivedMessage.hasSetConfigurationRequest()).isTrue();
    final SetConfigurationRequest receivedConfiguration = receivedMessage.getSetConfigurationRequest();
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_LIGHTTYPE)) && receivedConfiguration.getLightType() != null) {
        final LightType expectedLightType = getEnum(expectedResponseData, PlatformKeys.KEY_LIGHTTYPE, LightType.class);
        assertThat(receivedConfiguration.getLightType()).isEqualTo(expectedLightType);
        switch(expectedLightType) {
            case DALI:
                final DaliConfiguration receivedDaliConfiguration = receivedConfiguration.getDaliConfiguration();
                if (receivedDaliConfiguration != null) {
                    if (expectedResponseData.containsKey(PlatformKeys.DC_LIGHTS) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_LIGHTS))) {
                        assertThat(OslpUtils.byteStringToInteger(receivedDaliConfiguration.getNumberOfLights())).isEqualTo(getInteger(expectedResponseData, PlatformKeys.DC_LIGHTS));
                    }
                    if (expectedResponseData.containsKey(PlatformKeys.DC_MAP) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_MAP))) {
                        assertThat(receivedDaliConfiguration.getAddressMapList()).isNotNull();
                        final String[] expectedDcMapArray = getString(expectedResponseData, PlatformKeys.DC_MAP).split(";");
                        assertThat(receivedDaliConfiguration.getAddressMapList().size()).isEqualTo(expectedDcMapArray.length);
                        final List<IndexAddressMap> receivedIndexAddressMapList = receivedDaliConfiguration.getAddressMapList();
                        for (int i = 0; i < expectedDcMapArray.length; i++) {
                            final String[] expectedDcMapArrayElements = expectedDcMapArray[i].split(",");
                            assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getIndex())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[0]));
                            assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getAddress())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[1]));
                        }
                    }
                }
                break;
            case RELAY:
                final RelayConfiguration receivedRelayConfiguration = receivedConfiguration.getRelayConfiguration();
                if (receivedRelayConfiguration != null) {
                    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.RELAY_CONF)) && receivedRelayConfiguration.getAddressMapList() != null) {
                        // Construct sorted list of received relay maps
                        final List<RelayMap> receivedRelayMapList = RelayMapConverter.convertIndexAddressMapListToRelayMapList(receivedRelayConfiguration.getAddressMapList());
                        Collections.sort(receivedRelayMapList);
                        // Construct sorted list of expected relay maps
                        final String[] expectedRelayMapArray = getString(expectedResponseData, PlatformKeys.RELAY_CONF).split(";");
                        final List<RelayMap> expectedRelayMapList = RelayMapConverter.convertStringsListToRelayMapList(expectedRelayMapArray);
                        Collections.sort(expectedRelayMapList);
                        assertThat(CollectionUtils.isEmpty(receivedRelayMapList)).as("Either the expected or the received relay maps are empty, but not both").isEqualTo(CollectionUtils.isEmpty(expectedRelayMapList));
                        if (!CollectionUtils.isEmpty(receivedRelayMapList) && !CollectionUtils.isEmpty(expectedRelayMapList)) {
                            assertThat(receivedRelayMapList.size()).as("Size of expected and received relay map list differs").isEqualTo(expectedRelayMapList.size());
                        }
                        // Compare the contents of each relay map
                        for (int i = 0; i < expectedRelayMapList.size(); i++) {
                            assertThat(receivedRelayMapList.get(i)).as("Expected and received relay map differs for " + i).isEqualTo(expectedRelayMapList.get(i));
                        }
                    }
                }
                break;
            case ONE_TO_TEN_VOLT:
            case ONE_TO_TEN_VOLT_REVERSE:
            case LT_NOT_SET:
            default:
                assertThat(receivedConfiguration.getDaliConfiguration().getAddressMapList().size()).isEqualTo(0);
                assertThat(receivedConfiguration.getRelayConfiguration().getAddressMapList().size()).isEqualTo(0);
        }
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_PREFERRED_LINKTYPE)) && receivedConfiguration.getPreferredLinkType() != null) {
        assertThat(receivedConfiguration.getPreferredLinkType()).isEqualTo(getEnum(expectedResponseData, PlatformKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS))) {
        assertThat(OslpDeviceSteps.convertIpAddress(receivedConfiguration.getOspgIpAddress())).isEqualTo(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_PORT))) {
        assertThat(receivedConfiguration.getOsgpPortNumber()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.OSGP_PORT)));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET))) {
        assertThat(receivedConfiguration.getAstroGateSunRiseOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET)));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET))) {
        assertThat(receivedConfiguration.getAstroGateSunSetOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET)));
    }
}
Also used : LightType(org.opensmartgridplatform.oslp.Oslp.LightType) DaliConfiguration(org.opensmartgridplatform.oslp.Oslp.DaliConfiguration) Message(org.opensmartgridplatform.oslp.Oslp.Message) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap) SetConfigurationRequest(org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest) RelayConfiguration(org.opensmartgridplatform.oslp.Oslp.RelayConfiguration) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) LinkType(org.opensmartgridplatform.oslp.Oslp.LinkType) Then(io.cucumber.java.en.Then)

Example 2 with RelayConfiguration

use of org.opensmartgridplatform.oslp.Oslp.RelayConfiguration in project open-smart-grid-platform by OSGP.

the class OslpChannelHandler method createRelayConfiguration.

/**
 * Create relay configuration based on stored configuration values.
 */
private static RelayConfiguration createRelayConfiguration(final List<DeviceOutputSetting> outputSettings) {
    final RelayConfiguration.Builder configuration = RelayConfiguration.newBuilder();
    for (final DeviceOutputSetting dos : outputSettings) {
        final IndexAddressMap.Builder relayMap = IndexAddressMap.newBuilder().setIndex(OslpUtils.integerToByteString(dos.getInternalId())).setAddress(OslpUtils.integerToByteString(dos.getExternalId()));
        // Map device-simulator enum OutputType to OSLP enum RelayType
        if (dos.getOutputType() == OutputType.LIGHT) {
            relayMap.setRelayType(RelayType.LIGHT);
        } else if (dos.getOutputType() == OutputType.TARIFF) {
            relayMap.setRelayType(RelayType.TARIFF);
        } else {
            relayMap.setRelayType(RelayType.RT_NOT_SET);
        }
        configuration.addAddressMap(relayMap);
    }
    return configuration.build();
}
Also used : RelayConfiguration(org.opensmartgridplatform.oslp.Oslp.RelayConfiguration) DeviceOutputSetting(org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)

Aggregations

IndexAddressMap (org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)2 RelayConfiguration (org.opensmartgridplatform.oslp.Oslp.RelayConfiguration)2 ByteString (com.google.protobuf.ByteString)1 Then (io.cucumber.java.en.Then)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)1 DaliConfiguration (org.opensmartgridplatform.oslp.Oslp.DaliConfiguration)1 LightType (org.opensmartgridplatform.oslp.Oslp.LightType)1 LinkType (org.opensmartgridplatform.oslp.Oslp.LinkType)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1 SetConfigurationRequest (org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest)1 DeviceOutputSetting (org.opensmartgridplatform.webdevicesimulator.domain.entities.DeviceOutputSetting)1