Search in sources :

Example 21 with ChannelElementValuesDto

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();
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 22 with ChannelElementValuesDto

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));
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 23 with ChannelElementValuesDto

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;
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)

Aggregations

ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)23 Test (org.junit.jupiter.api.Test)14 MbusChannelElementsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto)7 ArrayList (java.util.ArrayList)4 GetResult (org.openmuc.jdlms.GetResult)3 ObisCode (org.openmuc.jdlms.ObisCode)3 GetMBusDeviceOnChannelRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)3 CosemObjectAccessor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 CoupleMbusDeviceByChannelResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto)2 DecoupleMbusDeviceResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto)2 MbusChannelElementsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)1 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)1 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)1 EncryptionKeyStatusTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EncryptionKeyStatusTypeDto)1 GMeterInfoDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto)1