Search in sources :

Example 1 with TariffValue

use of org.opensmartgridplatform.domain.core.valueobjects.TariffValue in project open-smart-grid-platform by OSGP.

the class FilterLightAndTariffValuesHelper method filterTariffValues.

/**
 * Filter light values based on TariffSwitching domain. Only matching values will be returned.
 *
 * @param source list to filter
 * @param dosMap mapping of output settings
 * @param allowedDomainType type of domain allowed
 * @return list with filtered values or empty list when domain is not allowed.
 */
public static List<TariffValue> filterTariffValues(final List<LightValue> source, final Map<Integer, DeviceOutputSetting> dosMap, final DomainType allowedDomainType) {
    final List<TariffValue> filteredValues = new ArrayList<>();
    if (allowedDomainType != DomainType.TARIFF_SWITCHING) {
        // Return empty list
        return filteredValues;
    }
    for (final LightValue lv : source) {
        if (dosMap.containsKey(lv.getIndex()) && dosMap.get(lv.getIndex()).getOutputType().domainType().equals(allowedDomainType)) {
            // Map light value to tariff value
            final TariffValue tf = new TariffValue();
            tf.setIndex(lv.getIndex());
            if (dosMap.get(lv.getIndex()).getOutputType().equals(RelayType.TARIFF_REVERSED)) {
                // Reversed means copy the 'isOn' value to the 'isHigh'
                // value without inverting the boolean value
                tf.setHigh(lv.isOn());
            } else {
                // Not reversed means copy the 'isOn' value to the 'isHigh'
                // value inverting the boolean value
                tf.setHigh(!lv.isOn());
            }
            filteredValues.add(tf);
        }
    }
    return filteredValues;
}
Also used : LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue)

Example 2 with TariffValue

use of org.opensmartgridplatform.domain.core.valueobjects.TariffValue in project open-smart-grid-platform by OSGP.

the class DeviceInstallationServiceTest method testHandleGetStatusResponseOkLmdStatusNotNull.

@Test
public void testHandleGetStatusResponseOkLmdStatusNotNull() throws FunctionalException, ValidationException {
    final TariffValue editedTariffValue = new TariffValue();
    editedTariffValue.setHigh(true);
    editedTariffValue.setIndex(10);
    final DeviceStatusMapped deviceStatus = new DeviceStatusMapped(null, Arrays.asList(new LightValue(0, true, 50), new LightValue(MESSAGE_PRIORITY, true, 75), new LightValue(2, false, 0)), LinkType.ETHERNET, LinkType.GPRS, LightType.ONE_TO_TEN_VOLT, 0);
    when(this.domainCoreMapper.map(null, DeviceStatus.class)).thenReturn(deviceStatus);
    final Device mockedDevice = Mockito.mock(Device.class);
    when(mockedDevice.getDeviceType()).thenReturn(LightMeasurementDevice.LMD_TYPE);
    when(this.deviceDomainService.searchDevice(TEST_DEVICE)).thenReturn(mockedDevice);
    this.deviceInstallationService.handleGetStatusResponse(null, CORRELATION_IDS, TEST_MESSAGE_TYPE, MESSAGE_PRIORITY, ResponseMessageResultType.OK, null);
    verify(this.webServiceResponseMessageSender).send(this.argumentResponseMessage.capture());
    assertThat(this.argumentResponseMessage.getValue()).usingRecursiveComparison().isEqualTo(this.createNewResponseMessage(ResponseMessageResultType.OK, null, deviceStatus));
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue) Test(org.junit.jupiter.api.Test)

Example 3 with TariffValue

use of org.opensmartgridplatform.domain.core.valueobjects.TariffValue in project open-smart-grid-platform by OSGP.

the class StatusMappingTest method properlyMapsDeviceStatusMapped.

@Test
void properlyMapsDeviceStatusMapped() {
    final TariffValue tv1 = new TariffValue();
    tv1.setHigh(true);
    final List<TariffValue> tariffValues = Arrays.asList(tv1);
    final Status domainStatus = new DeviceStatusMapped(tariffValues, LIGHT_VALUES, PREFERRED_LINK_TYPE, ACTUAL_LINK_TYPE, LIGHT_TYPE, EVENT_NOTIFICATIONS_MASK);
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status wsStatus = this.adHocManagementMapper.map(domainStatus, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status.class);
    final org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus expected = expectedDeviceStatus();
    assertThat(wsStatus).isInstanceOf(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DeviceStatus.class).usingRecursiveComparison().isEqualTo(expected);
}
Also used : Status(org.opensmartgridplatform.domain.core.valueobjects.Status) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) LightSensorStatus(org.opensmartgridplatform.domain.core.valueobjects.LightSensorStatus) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue) Test(org.junit.jupiter.api.Test)

Example 4 with TariffValue

use of org.opensmartgridplatform.domain.core.valueobjects.TariffValue in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method updateDeviceRelayOverview.

/**
 * Updates the relay overview from a device based on the given device status.
 */
private void updateDeviceRelayOverview(final Ssld device, final DeviceStatusMapped deviceStatusMapped) {
    final List<RelayStatus> relayStatuses = device.getRelayStatuses();
    for (final TariffValue tariffValue : deviceStatusMapped.getTariffValues()) {
        final Integer externalIndex = tariffValue.getIndex();
        final boolean state = this.isRelayOn(tariffValue.isHigh(), device, externalIndex);
        final RelayStatus oldRelayStatus = device.getRelayStatusByIndex(externalIndex);
        if (oldRelayStatus != null) {
            // Update the old relay status value
            oldRelayStatus.updateLastKnownState(state, new Date());
        } else {
            // Create a new relay status value
            final RelayStatus newRelayStatus = new RelayStatus.Builder(device, externalIndex).withLastKnownState(state, new Date()).build();
            relayStatuses.add(newRelayStatus);
        }
    }
    this.ssldRepository.save(device);
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) TariffValue(org.opensmartgridplatform.domain.core.valueobjects.TariffValue) Date(java.util.Date)

Aggregations

TariffValue (org.opensmartgridplatform.domain.core.valueobjects.TariffValue)4 Test (org.junit.jupiter.api.Test)2 DeviceStatusMapped (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped)2 LightValue (org.opensmartgridplatform.domain.core.valueobjects.LightValue)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)1 DeviceStatus (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus)1 LightSensorStatus (org.opensmartgridplatform.domain.core.valueobjects.LightSensorStatus)1 Status (org.opensmartgridplatform.domain.core.valueobjects.Status)1