SetAlarmNotificationsCommandExecutor extends AbstractCommandExecutor<AlarmNotificationsDto, AccessResultCode> { @Override public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final AlarmNotificationsDto alarmNotifications) throws ProtocolAdapterException { try { final AttributeAddress alarmFilterValue = this.getAttributeAddress(device); final AlarmNotificationsDto alarmNotificationsOnDevice = this.retrieveCurrentAlarmNotifications(conn, alarmFilterValue); LOGGER.info("Alarm Filter on device before setting notifications: {}", alarmNotificationsOnDevice); final long alarmFilterLongValueOnDevice = this.alarmFilterLongValue(alarmNotificationsOnDevice); final long updatedAlarmFilterLongValue = this .calculateAlarmFilterLongValue(alarmNotificationsOnDevice, alarmNotifications); if (alarmFilterLongValueOnDevice == updatedAlarmFilterLongValue) { return AccessResultCode.SUCCESS; } LOGGER.info("Modified Alarm Filter long value for device: {}", updatedAlarmFilterLongValue); return this.writeUpdatedAlarmNotifications(conn, updatedAlarmFilterLongValue, alarmFilterValue); } catch (final IOException e) { throw new ConnectionException(e); } } @Autowired  SetAlarmNotificationsCommandExecutor(final DlmsObjectConfigService dlmsObjectConfigService); @Override AlarmNotificationsDto fromBundleRequestInput(final ActionRequestDto bundleInput); @Override ActionResponseDto asBundleResponse(final AccessResultCode executionResult); @Override AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device,
            final AlarmNotificationsDto alarmNotifications);  }
@Test public void testSetSettingThatIsAlreadySet() throws OsgpException { final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.REPLACE_BATTERY, true)); assertThat(res).isEqualTo(AccessResultCode.SUCCESS); assertThat(this.setParametersReceived.size()).isEqualTo(0); }
@Test public void testSetSettingEnabled() throws OsgpException { final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true)); assertThat(res).isEqualTo(AccessResultCode.SUCCESS); assertThat(this.setParametersReceived.size()).isEqualTo(1); assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(11); }
@Test public void testSetSettingEnabledAndDisabled() throws OsgpException { 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); assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(9); }