use of org.opensmartgridplatform.oslp.Oslp.LightValue in project open-smart-grid-platform by OSGP.
the class MockOslpServer method mockGetLightStatusResponse.
public void mockGetLightStatusResponse(final String deviceUid, final LinkType preferred, final LinkType actual, final LightType lightType, final int eventNotificationMask, final Oslp.Status status, final List<LightValue> lightValues) {
final Builder response = GetStatusResponse.newBuilder().setPreferredLinktype(preferred).setActualLinktype(actual).setLightType(lightType).setEventNotificationMask(eventNotificationMask).setStatus(status);
for (final LightValue lightValue : lightValues) {
response.addValue(lightValue);
}
LOGGER.info(MOCKING_MESSAGE_TYPE, deviceUid, MessageType.GET_LIGHT_STATUS);
this.devicesContext.getDeviceState(deviceUid).addMockedResponse(MessageType.GET_LIGHT_STATUS, Oslp.Message.newBuilder().setGetStatusResponse(response).build());
}
use of org.opensmartgridplatform.oslp.Oslp.LightValue in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theDeviceReturnsAGetStatusResponseWithResultOverOslp.
/**
* Setup method to set the status which should be returned by the mock.
*/
@Given("^the device returns a get status response \"([^\"]*)\" over \"([^\"]*)\"$")
public void theDeviceReturnsAGetStatusResponseWithResultOverOslp(final String result, final String protocol, final Map<String, String> requestParameters) {
int eventNotificationTypes = 0;
if (getString(requestParameters, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONTYPES).trim().split(PlatformPubliclightingKeys.SEPARATOR_COMMA).length > 0) {
for (final String eventNotificationType : getString(requestParameters, PlatformPubliclightingKeys.KEY_EVENTNOTIFICATIONTYPES, PlatformPubliclightingDefaults.DEFAULT_EVENTNOTIFICATIONTYPES).trim().split(PlatformPubliclightingKeys.SEPARATOR_COMMA)) {
if (!eventNotificationType.isEmpty()) {
eventNotificationTypes = eventNotificationTypes + Enum.valueOf(EventNotificationType.class, eventNotificationType.trim()).getValue();
}
}
}
final List<LightValue> lightValues = new ArrayList<>();
if (!getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).isEmpty() && getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON).length > 0) {
for (final String lightValueString : getString(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTVALUES, PlatformPubliclightingDefaults.DEFAULT_LIGHTVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON)) {
final String[] parts = lightValueString.split(PlatformPubliclightingKeys.SEPARATOR_COMMA);
final LightValue lightValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(Integer.parseInt(parts[0]))).setOn(parts[1].toLowerCase().equals("true")).setDimValue(OslpUtils.integerToByteString(Integer.parseInt(parts[2]))).build();
lightValues.add(lightValue);
}
}
final List<LightValue> tariffValues = new ArrayList<>();
if (!getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).isEmpty() && getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON).length > 0) {
for (final String tariffValueString : getString(requestParameters, PlatformPubliclightingKeys.KEY_TARIFFVALUES, PlatformPubliclightingDefaults.DEFAULT_TARIFFVALUES).split(PlatformPubliclightingKeys.SEPARATOR_SEMICOLON)) {
final String[] parts = tariffValueString.split(PlatformPubliclightingKeys.SEPARATOR_COMMA);
final LightValue tariffValue = LightValue.newBuilder().setIndex(OslpUtils.integerToByteString(Integer.parseInt(parts[0]))).setOn(parts[1].toLowerCase().equals("true")).build();
tariffValues.add(tariffValue);
}
}
this.oslpMockServer.mockGetStatusResponse(this.getDeviceUid(requestParameters), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_PREFERRED_LINKTYPE, LinkType.class, PlatformPubliclightingDefaults.DEFAULT_PREFERRED_LINKTYPE), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_ACTUAL_LINKTYPE, LinkType.class, PlatformPubliclightingDefaults.DEFAULT_ACTUAL_LINKTYPE), getEnum(requestParameters, PlatformPubliclightingKeys.KEY_LIGHTTYPE, LightType.class, PlatformPubliclightingDefaults.DEFAULT_LIGHTTYPE), eventNotificationTypes, Enum.valueOf(Status.class, result), lightValues, tariffValues);
}
use of org.opensmartgridplatform.oslp.Oslp.LightValue in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method aSetLightOslpMessageWithOneLightvalueIsSentToTheDevice.
/**
* Verify that a set light OSLP message is sent to the device.
*
* @param expectedParameters The parameters expected in the message of the device.
*/
@Then("^a set light \"([^\"]*)\" message with one light value is sent to the device$")
public void aSetLightOslpMessageWithOneLightvalueIsSentToTheDevice(final String protocol, final Map<String, String> expectedParameters) throws DeviceSimulatorException {
final Message message = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedParameters), MessageType.SET_LIGHT);
assertThat(message).isNotNull();
assertThat(message.hasSetLightRequest()).isTrue();
final LightValue lightValue = message.getSetLightRequest().getValues(0);
assertThat(OslpUtils.byteStringToInteger(lightValue.getIndex())).isEqualTo(getInteger(expectedParameters, PlatformPubliclightingKeys.KEY_INDEX, PlatformPubliclightingDefaults.DEFAULT_INDEX));
if (expectedParameters.containsKey(PlatformPubliclightingKeys.KEY_DIMVALUE) && !StringUtils.isEmpty(expectedParameters.get(PlatformPubliclightingKeys.KEY_DIMVALUE))) {
assertThat(OslpUtils.byteStringToInteger(lightValue.getDimValue())).isEqualTo(getInteger(expectedParameters, PlatformPubliclightingKeys.KEY_DIMVALUE, PlatformPubliclightingDefaults.DEFAULT_DIMVALUE));
}
assertThat(lightValue.getOn()).isEqualTo(getBoolean(expectedParameters, PlatformPubliclightingKeys.KEY_ON, PlatformPubliclightingDefaults.DEFAULT_ON));
}
use of org.opensmartgridplatform.oslp.Oslp.LightValue in project open-smart-grid-platform by OSGP.
the class MockOslpServer method mockGetStatusResponse.
public void mockGetStatusResponse(final String deviceUid, final LinkType preferred, final LinkType actual, final LightType lightType, final int eventNotificationMask, final Oslp.Status status, final List<LightValue> lightValues, final List<LightValue> tariffValues) {
final Builder response = GetStatusResponse.newBuilder().setPreferredLinktype(preferred).setActualLinktype(actual).setLightType(lightType).setEventNotificationMask(eventNotificationMask).setStatus(status);
for (final LightValue lightValue : lightValues) {
response.addValue(lightValue);
}
for (final LightValue tariffValue : tariffValues) {
response.addValue(tariffValue);
}
LOGGER.info(MOCKING_MESSAGE_TYPE, deviceUid, MessageType.GET_STATUS);
this.devicesContext.getDeviceState(deviceUid).addMockedResponse(MessageType.GET_STATUS, Oslp.Message.newBuilder().setGetStatusResponse(response).build());
}
use of org.opensmartgridplatform.oslp.Oslp.LightValue in project open-smart-grid-platform by OSGP.
the class OslpChannelHandler method createGetStatusResponse.
private Message createGetStatusResponse(final Device device) {
final List<LightValue> outputValues = new ArrayList<>();
for (final DeviceOutputSetting dos : device.getOutputSettings()) {
final Builder lightValue = this.getLightValueForDeviceOutputSetting(device, dos);
outputValues.add(lightValue.build());
}
// Fallback in case output settings are not yet defined.
if (outputValues.isEmpty()) {
final Builder lightValue = this.getDefaultLightValue(device);
outputValues.add(lightValue.build());
}
final Oslp.GetStatusResponse.Builder builder = GetStatusResponse.newBuilder();
builder.setStatus(Oslp.Status.OK);
builder.addAllValue(outputValues);
builder.setPreferredLinktype(Enum.valueOf(Oslp.LinkType.class, device.getPreferredLinkType().name()));
builder.setActualLinktype(Enum.valueOf(Oslp.LinkType.class, device.getActualLinkType().name()));
builder.setLightType(Enum.valueOf(Oslp.LightType.class, device.getLightType().name()));
builder.setEventNotificationMask(device.getEventNotificationMask());
LOGGER.info("device.getProtocol(): {}", device.getProtocol());
LOGGER.info("ProtocolType.OSLP_ELSTER.name(): {}", ProtocolType.OSLP_ELSTER);
if (device.getProtocol().equals(ProtocolType.OSLP_ELSTER.toString())) {
builder.setNumberOfOutputs(4);
builder.setDcOutputVoltageMaximum(24000);
builder.setDcOutputVoltageCurrent(24000);
builder.setMaximumOutputPowerOnDcOutput(15000);
builder.setSerialNumber(ByteString.copyFrom(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
builder.setMacAddress(ByteString.copyFrom(new byte[] { 1, 2, 3, 4, 5, 6 }));
builder.setHardwareId("Hardware ID").setInternalFlashMemSize(1024);
builder.setExternalFlashMemSize(2048).setLastInternalTestResultCode(0).setStartupCounter(42);
builder.setBootLoaderVersion("1.1.1").setFirmwareVersion("2.8.5");
builder.setCurrentConfigurationBackUsed(ByteString.copyFrom(new byte[] { 0 }));
builder.setName("ELS_DEV-SIM-DEVICE").setCurrentTime("20251231155959");
builder.setCurrentIp(this.statusInternalIpAddress);
}
return Oslp.Message.newBuilder().setGetStatusResponse(builder.build()).build();
}
Aggregations