use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto in project open-smart-grid-platform by OSGP.
the class MeterReadsGasMappingTest method testMeterReadsGasMappingTest.
// Test the mapping of a complete MeterReadsGasDto object
@Test
public void testMeterReadsGasMappingTest() {
// build test data
final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
final MeterReadsGasResponseDto meterReadsGasDto = new MeterReadsGasResponseDto(new Date(), consumption, new Date());
// actual mapping
final MeterReadsGas meterReadsGas = this.monitoringMapper.map(meterReadsGasDto, MeterReadsGas.class);
// test mapping
assertThat(meterReadsGas).isNotNull();
assertThat(meterReadsGas.getLogTime()).isEqualTo(meterReadsGasDto.getLogTime());
assertThat(meterReadsGas.getCaptureTime()).isEqualTo(meterReadsGasDto.getCaptureTime());
final BigDecimal bigDecimal1 = consumption.getValue();
final BigDecimal bigDecimal2 = meterReadsGas.getConsumption().getValue();
assertThat(bigDecimal1.compareTo(bigDecimal2) == 0).isTrue();
assertThat(meterReadsGas.getConsumption().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto in project open-smart-grid-platform by OSGP.
the class GetActualMeterReadsGasCommandExecutor method execute.
@Override
public MeterReadsGasResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActualMeterReadsQueryDto actualMeterReadsRequest, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final ObisCode obisCodeMbusMasterValue = this.masterValueForChannel(actualMeterReadsRequest.getChannel());
LOGGER.debug("Retrieving current MBUS master value for ObisCode: {}", obisCodeMbusMasterValue);
final AttributeAddress mbusValue = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_VALUE);
LOGGER.debug("Retrieving current MBUS master capture time for ObisCode: {}", obisCodeMbusMasterValue);
final AttributeAddress mbusTime = new AttributeAddress(CLASS_ID_MBUS, obisCodeMbusMasterValue, ATTRIBUTE_ID_TIME);
final AttributeAddress scalerUnit = new AttributeAddress(CLASS_ID_MBUS, this.masterValueForChannel(actualMeterReadsRequest.getChannel()), ATTRIBUTE_ID_SCALER_UNIT);
conn.getDlmsMessageListener().setDescription("GetActualMeterReadsGas for channel " + actualMeterReadsRequest.getChannel() + ", retrieve attributes: " + JdlmsObjectToStringUtil.describeAttributes(mbusValue, mbusTime, scalerUnit));
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "retrieve actual meter reads for mbus " + actualMeterReadsRequest.getChannel(), mbusValue, mbusTime, scalerUnit);
final DlmsMeterValueDto consumption = this.dlmsHelper.getScaledMeterValue(getResultList.get(0), getResultList.get(2), "retrieve scaled value for mbus " + actualMeterReadsRequest.getChannel());
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(getResultList.get(1), "captureTime gas");
final Date captureTime;
if (cosemDateTime.isDateTimeSpecified()) {
captureTime = cosemDateTime.asDateTime().toDate();
} else {
throw new ProtocolAdapterException("Unexpected null/unspecified value for M-Bus Capture Time");
}
return new MeterReadsGasResponseDto(new Date(), consumption, captureTime);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto in project open-smart-grid-platform by OSGP.
the class ActualMeterReadsResponseMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) {
if (responseMessage.getDataObject() instanceof MeterReadsResponseDto) {
final MeterReadsResponseDto actualMeterReadsDto = (MeterReadsResponseDto) responseMessage.getDataObject();
this.monitoringService.handleActualMeterReadsResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, actualMeterReadsDto);
} else if (responseMessage.getDataObject() instanceof MeterReadsGasResponseDto) {
final MeterReadsGasResponseDto meterReadsGas = (MeterReadsGasResponseDto) responseMessage.getDataObject();
this.monitoringService.handleActualMeterReadsResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, meterReadsGas);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto in project open-smart-grid-platform by OSGP.
the class MeterReadsGasMappingTest method testWithNullDates.
// Dates can never be null, because of the way the constructor for a
// MeterReadsGasDto is defined.
@Test
public void testWithNullDates() {
final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> {
new MeterReadsGasResponseDto(null, consumption, null);
});
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto in project open-smart-grid-platform by OSGP.
the class MeterReadsGasMappingTest method testWithNullDlmsMeterValueDto.
// Test mapping when DlmsMeterValue is null;
@Test
public void testWithNullDlmsMeterValueDto() {
// build test data
final DlmsMeterValueDto consumption = null;
final MeterReadsGasResponseDto meterReadsGasDto = new MeterReadsGasResponseDto(new Date(), consumption, new Date());
// actual mapping
final MeterReadsGas meterReadsGas = this.monitoringMapper.map(meterReadsGasDto, MeterReadsGas.class);
// test mapping
assertThat(meterReadsGas).isNotNull();
assertThat(meterReadsGas.getLogTime()).isEqualTo(meterReadsGasDto.getLogTime());
assertThat(meterReadsGas.getCaptureTime()).isEqualTo(meterReadsGasDto.getCaptureTime());
assertThat(meterReadsGas.getConsumption()).isNull();
}
Aggregations