use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutor method executeForAlarmFilter.
private AccessResultCode executeForAlarmFilter(final DlmsConnectionManager conn, final AttributeAddress alarmFilterAttributeAddress, final AlarmNotificationsDto alarmNotifications, final DlmsObjectType alarmRegisterDlmsObjectType) throws ProtocolAdapterException {
try {
final AlarmNotificationsDto alarmNotificationsOnDevice = this.retrieveCurrentAlarmNotifications(conn, alarmFilterAttributeAddress, alarmRegisterDlmsObjectType);
LOGGER.info("Alarm Filter on device before setting notifications: {}", alarmNotificationsOnDevice);
final Set<AlarmTypeDto> alarmTypesForRegister = this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType);
final Set<AlarmNotificationDto> alarmNotificationsSet = alarmNotifications.getAlarmNotificationsSet().stream().filter(alarmNotificationDto -> alarmTypesForRegister.contains(alarmNotificationDto.getAlarmType())).collect(Collectors.toSet());
final long alarmFilterLongValueOnDevice = this.alarmFilterLongValue(alarmNotificationsOnDevice);
final long updatedAlarmFilterLongValue = this.calculateAlarmFilterLongValue(alarmNotificationsOnDevice, alarmNotificationsSet);
if (alarmFilterLongValueOnDevice == updatedAlarmFilterLongValue) {
return AccessResultCode.SUCCESS;
}
LOGGER.info("Modified Alarm Filter long value for device: {}", updatedAlarmFilterLongValue);
return this.writeUpdatedAlarmNotifications(conn, updatedAlarmFilterLongValue, alarmFilterAttributeAddress);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method testSetSettingEnabledAndDisabled.
@Test
void testSetSettingEnabledAndDisabled() throws OsgpException {
// Now we enable and disable something: CLOCK_INVALID to enabled and
// REPLACE_BATTERY to disabled.
final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true), new AlarmNotificationDto(AlarmTypeDto.REPLACE_BATTERY, false));
assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
assertThat(this.setParametersReceived.size()).isEqualTo(1);
// Expecting 9 (0b1001).
assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(9);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method testSetSettingEnabledRegister.
@ParameterizedTest
@CsvSource({ "1,VOLTAGE_SAG_IN_PHASE_DETECTED_L1", "2,VOLTAGE_SAG_IN_PHASE_DETECTED_L2", "4,VOLTAGE_SAG_IN_PHASE_DETECTED_L3", "8,VOLTAGE_SWELL_IN_PHASE_DETECTED_L1", "16,VOLTAGE_SWELL_IN_PHASE_DETECTED_L2", "32,VOLTAGE_SWELL_IN_PHASE_DETECTED_L3", "3,VOLTAGE_SAG_IN_PHASE_DETECTED_L1;VOLTAGE_SAG_IN_PHASE_DETECTED_L2", "7,VOLTAGE_SAG_IN_PHASE_DETECTED_L1;VOLTAGE_SAG_IN_PHASE_DETECTED_L2;VOLTAGE_SAG_IN_PHASE_DETECTED_L3" })
void testSetSettingEnabledRegister(final long expectedValue, final String alarmTypesInput) throws OsgpException {
final List<AlarmTypeDto> alarmTypes = Arrays.stream(alarmTypesInput.split(";")).map(AlarmTypeDto::valueOf).collect(toList());
final AccessResultCode res = this.execute(alarmTypes.stream().map(alarmType -> new AlarmNotificationDto(alarmType, true)).toArray(AlarmNotificationDto[]::new));
assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
assertThat(this.setParametersReceived.size()).isEqualTo(1);
assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(expectedValue);
}
Aggregations