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);
}
}
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);
}
Aggregations