use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto in project open-smart-grid-platform by OSGP.
the class DecoupleMBusDeviceCommandExecutorTest method testHappyFlow.
@Test
public void testHappyFlow() throws ProtocolAdapterException {
final short channel = (short) 1;
final ChannelElementValuesDto channelElementValuesDto = mock(ChannelElementValuesDto.class);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.deviceChannelsHelper.getObisCode(this.device, channel)).thenReturn(new ObisCode("0.1.24.1.0.255"));
when(this.decoupleMbusDto.getChannel()).thenReturn(channel);
when(this.deviceChannelsHelper.deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class))).thenReturn(MethodResultCode.SUCCESS);
when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(channelElementValuesDto);
final DecoupleMbusDeviceResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.decoupleMbusDto, messageMetadata);
assertThat(responseDto).isNotNull();
assertThat(responseDto.getChannelElementValues()).isEqualTo(channelElementValuesDto);
verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
verify(this.deviceChannelsHelper, times(1)).deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class));
verify(this.deviceChannelsHelper, times(1)).resetMBusClientAttributeValues(eq(this.conn), eq(this.device), any(Short.class), any(String.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto 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.DecoupleMbusDeviceResponseDto in project open-smart-grid-platform by OSGP.
the class DecoupleMBusDeviceCommandExecutor method execute.
@Override
public DecoupleMbusDeviceResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final DecoupleMbusDeviceDto decoupleMbusDto, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final Short channel = decoupleMbusDto.getChannel();
log.debug("Decouple channel {} on gateway device {}", channel, device.getDeviceIdentification());
final ObisCode obisCode = this.deviceChannelsHelper.getObisCode(device, channel);
// Get the current channel element values before resetting the channel
final ChannelElementValuesDto channelElementValues = this.deviceChannelsHelper.getChannelElementValues(conn, device, channel);
// Deinstall and reset channel
final CosemObjectAccessor mBusSetup = new CosemObjectAccessor(conn, obisCode, InterfaceClass.MBUS_CLIENT.id());
this.deviceChannelsHelper.deinstallSlave(conn, device, channel, mBusSetup);
this.deviceChannelsHelper.resetMBusClientAttributeValues(conn, device, channel, this.getClass().getSimpleName());
// return the channel element values as before decoupling
return new DecoupleMbusDeviceResponseDto(channelElementValues);
}
Aggregations