use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceByChannelCommandExecutorTest method testHappyFlow.
@Test
public void testHappyFlow() throws ProtocolAdapterException {
final short channel = (short) 1;
final Short primaryAddress = 9;
final String manufacturerIdentification = "manufacturerIdentification";
final short version = 123;
final short deviceTypeIdentification = 456;
final String identificationNumber = "identificationNumber";
final ChannelElementValuesDto dto = new ChannelElementValuesDto(channel, primaryAddress, identificationNumber, manufacturerIdentification, version, deviceTypeIdentification);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.coupleMbusDeviceByChannelRequestDataDto.getChannel()).thenReturn(channel);
when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(dto);
final CoupleMbusDeviceByChannelResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.coupleMbusDeviceByChannelRequestDataDto, messageMetadata);
assertThat(responseDto).isNotNull();
assertThat(responseDto.getChannelElementValues()).isNotNull();
assertThat(responseDto.getChannelElementValues().getChannel()).isEqualTo(channel);
assertThat(responseDto.getChannelElementValues().getDeviceTypeIdentification()).isEqualTo(deviceTypeIdentification);
assertThat(responseDto.getChannelElementValues().getIdentificationNumber()).isEqualTo(identificationNumber);
assertThat(responseDto.getChannelElementValues().getManufacturerIdentification()).isEqualTo(manufacturerIdentification);
assertThat(responseDto.getChannelElementValues().getPrimaryAddress()).isEqualTo(primaryAddress);
assertThat(responseDto.getChannelElementValues().getVersion()).isEqualTo(version);
verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto in project open-smart-grid-platform by OSGP.
the class BundleService method checkIfAdditionalActionIsNeeded.
private void checkIfAdditionalActionIsNeeded(final MessageMetadata messageMetadata, final BundleMessagesRequestDto bundleMessagesRequestDto) throws FunctionalException {
for (final ActionResponseDto action : bundleMessagesRequestDto.getAllResponses()) {
if (action instanceof CoupleMbusDeviceByChannelResponseDto) {
this.mBusGatewayService.handleCoupleMbusDeviceByChannelResponse(messageMetadata, (CoupleMbusDeviceByChannelResponseDto) action);
} else if (action instanceof DecoupleMbusDeviceResponseDto) {
this.mBusGatewayService.handleDecoupleMbusDeviceResponse(messageMetadata, (DecoupleMbusDeviceResponseDto) action);
} else if (action instanceof SetDeviceLifecycleStatusByChannelResponseDto) {
this.managementService.setDeviceLifecycleStatusByChannel((SetDeviceLifecycleStatusByChannelResponseDto) action);
} else if (action instanceof EventMessageDataResponseDto) {
this.eventService.enrichEvents(messageMetadata, (EventMessageDataResponseDto) action);
} else if (action instanceof FirmwareVersionResponseDto) {
final List<FirmwareVersion> firmwareVersions = this.configurationMapper.mapAsList(((FirmwareVersionResponseDto) action).getFirmwareVersions(), FirmwareVersion.class);
this.firmwareService.saveFirmwareVersionsReturnedFromDevice(messageMetadata.getDeviceIdentification(), firmwareVersions);
} else if (action instanceof FirmwareVersionGasResponseDto) {
final FirmwareVersionGasResponseDto firmwareVersionGasResponseDto = (FirmwareVersionGasResponseDto) action;
final FirmwareVersion firmwareVersion = this.configurationMapper.map(firmwareVersionGasResponseDto.getFirmwareVersion(), FirmwareVersion.class);
this.firmwareService.saveFirmwareVersionsReturnedFromDevice(firmwareVersionGasResponseDto.getFirmwareVersion().getMbusDeviceIdentification(), Arrays.asList(firmwareVersion));
}
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto in project open-smart-grid-platform by OSGP.
the class CoupleMbusDeviceByChannelCommandExecutor method execute.
@Override
public CoupleMbusDeviceByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final CoupleMbusDeviceByChannelRequestDataDto requestDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
log.info("Retrieving values for mbus channel {} on device {}", requestDto.getChannel(), device.getDeviceIdentification());
final ChannelElementValuesDto channelElementValuesDto = this.deviceChannelsHelper.getChannelElementValues(conn, device, requestDto.getChannel());
/*
* Couple M-Bus device by channel is created to couple the M-Bus device
* in the platform based on a new M-Bus device discovered alarm for a
* particular channel. As such there is no write action to the M-Bus
* Client Setup involved, since the platform depends on the attributes
* on the gateway device to be able to determine which M-Bus device was
* actually involved when the alarm was triggered for the channel from
* the request.
*/
return new CoupleMbusDeviceByChannelResponseDto(channelElementValuesDto);
}
Aggregations