use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method isRelayOn.
private boolean isRelayOn(final boolean isHighTariff, final Ssld device, final Integer externalIndex) {
// The relay state is on, during the LOW tariff period
boolean state = !isHighTariff;
final DeviceOutputSetting setting = device.getOutputSetting(externalIndex);
if (setting != null && setting.getOutputType() == RelayType.TARIFF_REVERSED) {
// Invert the state because TARIFF_REVERSED uses inverse values.
state = !state;
}
return state;
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method setTariffSchedule.
// === SET TARIFF SCHEDULE ===
/**
* Set a tariff schedule.
*/
public void setTariffSchedule(final CorrelationIds ids, final List<ScheduleEntry> schedules, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
LOGGER.info("setTariffSchedule called with organisation {} and device {}.", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
this.findOrganisation(ids.getOrganisationIdentification());
final Device device = this.findActiveDevice(ids.getDeviceIdentification());
if (Ssld.PSLD_TYPE.equals(device.getDeviceType())) {
throw new FunctionalException(FunctionalExceptionType.TARIFF_SCHEDULE_NOT_ALLOWED_FOR_PSLD, ComponentType.DOMAIN_TARIFF_SWITCHING, new ValidationException("Set tariff schedule is not allowed for PSLD."));
}
// Reverse schedule switching for TARIFF_REVERSED relays.
for (final DeviceOutputSetting dos : this.getSsldForDevice(device).getOutputSettings()) {
if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
for (final ScheduleEntry schedule : schedules) {
for (final LightValue lightValue : schedule.getLightValue()) {
lightValue.invertIsOn();
}
}
}
}
LOGGER.info("Mapping to schedule DTO");
final List<org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto> schedulesDto = this.domainCoreMapper.mapAsList(schedules, org.opensmartgridplatform.dto.valueobjects.ScheduleEntryDto.class);
final ScheduleDto scheduleDto = new ScheduleDto(schedulesDto);
LOGGER.info("Sending message");
this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, scheduleDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleSsld.
private void handleSsld(final String deviceIdentification, final DeviceStatus status, final DomainType allowedDomainType, final GetStatusResponse response) {
// Find device and output settings.
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
// Create map with external relay number as key set.
final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
for (final DeviceOutputSetting dos : deviceOutputSettings) {
dosMap.put(dos.getExternalId(), dos);
}
if (status != null) {
// Map the DeviceStatus for SSLD.
final DeviceStatusMapped deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
// Update the relay overview with the relay information.
this.updateDeviceRelayStatusForGetStatus(ssld, deviceStatusMapped);
// Return mapped status using GetStatusResponse instance.
response.setDeviceStatusMapped(deviceStatusMapped);
} else {
// No status received, create bad response.
response.setDeviceStatusMapped(null);
response.setOsgpException(new TechnicalException(ComponentType.DOMAIN_PUBLIC_LIGHTING, "SSLD was not able to report relay status", new NoDeviceResponseException()));
response.setResult(ResponseMessageResultType.NOT_OK);
}
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertTo.
@Override
public org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device convertTo(final Ssld source, final Type<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device destination = this.helper.initJaxb(source);
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(source.getDeviceIdentification());
if (ssld != null) {
final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting();
newDeviceOutputSetting.setExternalId(deviceOutputSetting.getExternalId());
newDeviceOutputSetting.setInternalId(deviceOutputSetting.getInternalId());
newDeviceOutputSetting.setRelayType(deviceOutputSetting.getOutputType() == null ? null : RelayType.valueOf(deviceOutputSetting.getOutputType().name()));
newDeviceOutputSetting.setAlias(deviceOutputSetting.getAlias());
deviceOutputSettings.add(newDeviceOutputSetting);
}
destination.getOutputSettings().addAll(deviceOutputSettings);
destination.setPublicKeyPresent(ssld.isPublicKeyPresent());
destination.setHasSchedule(ssld.getHasSchedule());
final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean> eans = new ArrayList<>();
for (final org.opensmartgridplatform.domain.core.entities.Ean ean : ssld.getEans()) {
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean newEan = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean();
newEan.setCode(ean.getCode());
newEan.setDescription(ean.getDescription());
eans.add(newEan);
}
destination.getEans().addAll(eans);
this.addRelayStatuses(destination, ssld);
}
return destination;
}
Aggregations