Search in sources :

Example 1 with MeterReadsGasResponseDto

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);
}
Also used : MeterReadsGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReadsGas) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) BigDecimal(java.math.BigDecimal) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 2 with MeterReadsGasResponseDto

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);
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ObisCode(org.openmuc.jdlms.ObisCode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)

Example 3 with MeterReadsGasResponseDto

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

Example 4 with MeterReadsGasResponseDto

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);
    });
}
Also used : MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) BigDecimal(java.math.BigDecimal) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 5 with MeterReadsGasResponseDto

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();
}
Also used : MeterReadsGas(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReadsGas) MeterReadsGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto) Date(java.util.Date) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Aggregations

MeterReadsGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsGasResponseDto)5 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)4 Date (java.util.Date)3 Test (org.junit.jupiter.api.Test)3 BigDecimal (java.math.BigDecimal)2 MeterReadsGas (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.MeterReadsGas)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 GetResult (org.openmuc.jdlms.GetResult)1 ObisCode (org.openmuc.jdlms.ObisCode)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 MeterReadsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MeterReadsResponseDto)1