Search in sources :

Example 1 with PowerQualityValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto in project open-smart-grid-platform by OSGP.

the class GetActualPowerQualityCommandExecutorTest method executeAndAssert.

void executeAndAssert(final String profileType, final List<GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
    this.actualPowerQualityRequestDto = new ActualPowerQualityRequestDto(profileType);
    doReturn(this.generateMockedResult(metadatas, AccessResultCode.SUCCESS)).when(this.dlmsHelper).getAndCheck(eq(this.conn), eq(this.dlmsDevice), eq("retrieve actual power quality"), any(AttributeAddress.class));
    final GetActualPowerQualityCommandExecutor executor = new GetActualPowerQualityCommandExecutor(this.dlmsHelper);
    final ActualPowerQualityResponseDto responseDto = executor.execute(this.conn, this.dlmsDevice, this.actualPowerQualityRequestDto, this.messageMetadata);
    assertThat(responseDto.getActualPowerQualityData().getPowerQualityValues()).hasSize(metadatas.size());
    assertThat(responseDto.getActualPowerQualityData().getPowerQualityObjects()).hasSize(metadatas.size());
    for (int i = 0; i < metadatas.size(); i++) {
        final GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata metadata = metadatas.get(i);
        final Serializable expectedValue = this.getExpectedValue(i, metadata);
        final String expectedUnit = this.getExpectedUnit(metadata);
        final PowerQualityObjectDto powerQualityObjectDto = responseDto.getActualPowerQualityData().getPowerQualityObjects().get(i);
        assertThat(powerQualityObjectDto.getName()).isEqualTo(metadata.name());
        assertThat(powerQualityObjectDto.getUnit()).isEqualTo(expectedUnit);
        final PowerQualityValueDto powerQualityValue = responseDto.getActualPowerQualityData().getPowerQualityValues().get(i);
        assertThat(powerQualityValue.getValue()).isEqualTo(expectedValue);
    }
}
Also used : Serializable(java.io.Serializable) PowerQualityObjectMetadata(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata) ActualPowerQualityRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityRequestDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) ActualPowerQualityResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityResponseDto) PowerQualityValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto)

Example 2 with PowerQualityValueDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto in project open-smart-grid-platform by OSGP.

the class GetActualPowerQualityCommandExecutor method makeActualPowerQualityDataDto.

private ActualPowerQualityDataDto makeActualPowerQualityDataDto(final List<GetResult> resultList, final List<PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
    final List<PowerQualityObjectDto> powerQualityObjects = new ArrayList<>();
    final List<PowerQualityValueDto> powerQualityValues = new ArrayList<>();
    int idx = 0;
    for (final PowerQualityObjectMetadata metadata : metadatas) {
        final PowerQualityObjectDto powerQualityObject;
        final PowerQualityValueDto powerQualityValue;
        if (metadata.getClassId() == CLASS_ID_CLOCK) {
            final GetResult resultTime = resultList.get(idx++);
            final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(resultTime, "Actual Power Quality - Time");
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
            powerQualityValue = new PowerQualityValueDto(cosemDateTime.asDateTime().toDate());
        } else if (metadata.getClassId() == CLASS_ID_REGISTER) {
            final GetResult resultValue = resultList.get(idx++);
            final GetResult resultScalerUnit = resultList.get(idx++);
            final DlmsMeterValueDto meterValue = this.dlmsHelper.getScaledMeterValue(resultValue, resultScalerUnit, "Actual Power Quality - " + metadata.getObisCode());
            final BigDecimal value = meterValue != null ? meterValue.getValue() : null;
            final String unit = meterValue != null ? meterValue.getDlmsUnit().getUnit() : null;
            powerQualityValue = new PowerQualityValueDto(value);
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), unit);
        } else if (metadata.getClassId() == CLASS_ID_DATA) {
            final GetResult resultValue = resultList.get(idx++);
            final Integer meterValue = this.dlmsHelper.readInteger(resultValue, "Actual Power Quality - " + metadata.getObisCode());
            powerQualityValue = meterValue != null ? new PowerQualityValueDto(new BigDecimal(meterValue)) : null;
            powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
        } else {
            throw new ProtocolAdapterException(String.format("Unsupported ClassId {} for logical name {}", metadata.getClassId(), metadata.obisCode));
        }
        powerQualityObjects.add(powerQualityObject);
        powerQualityValues.add(powerQualityValue);
    }
    return new ActualPowerQualityDataDto(powerQualityObjects, powerQualityValues);
}
Also used : ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) PowerQualityValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Aggregations

PowerQualityObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto)2 PowerQualityValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto)2 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 GetResult (org.openmuc.jdlms.GetResult)1 PowerQualityObjectMetadata (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ActualPowerQualityDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto)1 ActualPowerQualityRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityRequestDto)1 ActualPowerQualityResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityResponseDto)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)1