use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class DeviceChannelsHelperTest method testGetChannelElementValuesIdenfiticationNumberNull.
@Test
public void testGetChannelElementValuesIdenfiticationNumberNull() throws Exception {
final GetResult identificationNumberNull = new GetResultImpl(null);
final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, identificationNumberNull, this.manufacturerIdentification, this.version, this.deviceType));
when(this.device.isWithListSupported()).thenReturn(true);
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
final ChannelElementValuesDto values = this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
assertThat(values.getIdentificationNumber()).isNull();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceCommandExecutorTest method testNoMatchButEmptyChannel.
@Test
public void testNoMatchButEmptyChannel() throws ProtocolAdapterException {
// Add empty channel to the list of candidate channels
final ChannelElementValuesDto emptyChannel = new ChannelElementValuesDto((short) 2, (short) 0, "00000000", null, (short) 0, (short) 0);
final List<ChannelElementValuesDto> candidateChannelElementValuesWithEmptyChannel = Arrays.asList(this.candidateChannelElementValues.get(0), emptyChannel);
final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) -1, "noMatch", "noMatch", "noMatch", (short) -1, (short) -1);
when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(candidateChannelElementValuesWithEmptyChannel);
when(this.deviceChannelsHelper.findEmptyChannel(candidateChannelElementValuesWithEmptyChannel)).thenReturn(emptyChannel);
when(this.deviceChannelsHelper.writeUpdatedMbus(eq(this.conn), eq(this.device), eq(mbusChannelElementsDto), eq(emptyChannel.getChannel()), any(String.class))).thenReturn(new ChannelElementValuesDto(emptyChannel.getChannel(), mbusChannelElementsDto.getPrimaryAddress(), mbusChannelElementsDto.getMbusIdentificationNumber(), mbusChannelElementsDto.getMbusManufacturerIdentification(), mbusChannelElementsDto.getMbusVersion(), mbusChannelElementsDto.getMbusDeviceTypeIdentification()));
when(this.deviceChannelsHelper.correctFirstChannelOffset(any(ChannelElementValuesDto.class))).thenReturn((short) (emptyChannel.getChannel() - 1));
final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
assertThat(responseDto.getChannel()).isEqualTo((short) 2);
assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.
the class FindMatchingChannelHelper method bestMatch.
public static ChannelElementValuesDto bestMatch(final MbusChannelElementsDto mbusChannelElements, final List<ChannelElementValuesDto> channelElementValuesList) {
if (channelElementValuesList == null || channelElementValuesList.isEmpty()) {
return null;
}
ChannelElementValuesDto bestMatch = null;
int bestScore = -1;
for (final ChannelElementValuesDto channelElementValues : channelElementValuesList) {
if (matches(mbusChannelElements, channelElementValues)) {
return channelElementValues;
}
if (!matchesPartially(mbusChannelElements, channelElementValues)) {
continue;
}
final int score = score(mbusChannelElements, channelElementValues);
if (score > bestScore) {
bestMatch = channelElementValues;
bestScore = score;
}
}
return bestMatch;
}
Aggregations