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