Search in sources :

Example 1 with AlarmNotificationDto

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

the class SetAlarmNotificationsCommandExecutor method alarmNotifications.

private AlarmNotificationsDto alarmNotifications(final long alarmFilterLongValue, final DlmsObjectType alarmRegisterDlmsObjectType) {
    final BitSet bitSet = BitSet.valueOf(new long[] { alarmFilterLongValue });
    final Set<AlarmNotificationDto> notifications = new TreeSet<>();
    for (final AlarmTypeDto alarmType : this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType)) {
        final boolean enabled = bitSet.get(this.alarmHelperService.getAlarmRegisterBitIndex(alarmType));
        notifications.add(new AlarmNotificationDto(alarmType, enabled));
    }
    return new AlarmNotificationsDto(notifications);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) TreeSet(java.util.TreeSet) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) BitSet(java.util.BitSet) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)

Example 2 with AlarmNotificationDto

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

the class AlarmNotificationsMappingTest method testWithSet.

// Tests if mapping with a Set with an entry succeeds.
@Test
public void testWithSet() {
    // create test data
    final AlarmNotification alarmNotification = new AlarmNotification(AlarmType.CLOCK_INVALID, true);
    final Set<AlarmNotification> alarmNotificationSet = new TreeSet<>();
    alarmNotificationSet.add(alarmNotification);
    final AlarmNotifications alarmNotifications = new AlarmNotifications(alarmNotificationSet);
    // actual mapping
    final AlarmNotificationsDto alarmNotificationsDto = this.configurationMapper.map(alarmNotifications, AlarmNotificationsDto.class);
    // check if mapping was successful
    assertThat(alarmNotificationsDto).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet()).isNotNull();
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().size()).isEqualTo(alarmNotificationSet.size());
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().isEmpty()).isFalse();
    // To see if there is an AlarmNotifictionDto with the same variables as
    // the AlarmNotification in the Set.
    final AlarmNotificationDto alarmNotificationDto = new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true);
    assertThat(alarmNotificationsDto.getAlarmNotificationsSet().contains(alarmNotificationDto)).isTrue();
}
Also used : AlarmNotifications(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotifications) AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) TreeSet(java.util.TreeSet) AlarmNotification(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) Test(org.junit.jupiter.api.Test)

Example 3 with AlarmNotificationDto

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

the class SetAlarmNotificationsCommandExecutorTest method testSetSettingEnabled.

@Test
void testSetSettingEnabled() throws OsgpException {
    // Now we enable something: CLOCK_INVALID to enabled.
    final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true));
    assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
    assertThat(this.setParametersReceived.size()).isEqualTo(1);
    // Expecting 11 (0b1011).
    assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(11);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with AlarmNotificationDto

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

the class SetAlarmNotificationsCommandExecutorTest method execute.

private AccessResultCode execute(final AlarmNotificationDto... alarmNotificationDtos) throws OsgpException {
    final Set<AlarmNotificationDto> alarmNotificationDtoSet = new HashSet<>(Arrays.asList(alarmNotificationDtos));
    final AlarmNotificationsDto alarmNotificationsDto = new AlarmNotificationsDto(alarmNotificationDtoSet);
    return this.executor.execute(this.connMgr, this.device, alarmNotificationsDto, this.messageMetadata);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) HashSet(java.util.HashSet)

Example 5 with AlarmNotificationDto

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

the class SetAlarmNotificationsCommandExecutorTest method testSetSettingThatIsAlreadySet.

@Test
void testSetSettingThatIsAlreadySet() throws OsgpException {
    // Setting notifications that are not different from what is on the
    // meter already,
    // should always be successful.
    final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.REPLACE_BATTERY, true));
    assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
    // Since nothing changed, not a single message should have been sent to
    // the meter.
    assertThat(this.setParametersReceived.size()).isZero();
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)8 AccessResultCode (org.openmuc.jdlms.AccessResultCode)5 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 AlarmNotificationsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)4 TreeSet (java.util.TreeSet)3 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)3 BitSet (java.util.BitSet)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 AttributeAddress (org.openmuc.jdlms.AttributeAddress)1 GetResult (org.openmuc.jdlms.GetResult)1 SetParameter (org.openmuc.jdlms.SetParameter)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 AbstractCommandExecutor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor)1 DlmsObjectConfigService (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService)1