use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method updateDeviceOutputSettings.
private void updateDeviceOutputSettings(final Device device, final Configuration configuration) {
// Check if device output settings can/should be updated
if (device == null || configuration == null || configuration.getRelayConfiguration() == null) {
// Nothing to update
return;
}
if (configuration.getRelayConfiguration().getRelayMap() == null || configuration.getRelayConfiguration().getRelayMap().isEmpty()) {
// Nothing to update
return;
}
final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
outputSettings.add(new DeviceOutputSetting(rm.getAddress(), rm.getIndex(), rm.getRelayType(), rm.getAlias()));
}
final Ssld ssld = this.findSsldForDevice(device);
ssld.updateOutputSettings(outputSettings);
this.ssldRepository.save(ssld);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertFrom.
@Override
public Ssld convertFrom(final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device source, final Type<Ssld> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final Ssld destination = this.helper.initEntity(source);
final List<org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting> deviceOutputSettings = new ArrayList<>();
for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceOutputSetting deviceOutputSetting : source.getOutputSettings()) {
final org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting newDeviceOutputSetting = new org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting(deviceOutputSetting.getInternalId(), deviceOutputSetting.getExternalId(), deviceOutputSetting.getRelayType() == null ? null : org.opensmartgridplatform.domain.core.valueobjects.RelayType.valueOf(deviceOutputSetting.getRelayType().name()), deviceOutputSetting.getAlias());
deviceOutputSettings.add(newDeviceOutputSetting);
}
destination.updateOutputSettings(deviceOutputSettings);
if (source.isPublicKeyPresent() != null) {
destination.setPublicKeyPresent(source.isPublicKeyPresent());
}
if (source.isHasSchedule() != null) {
destination.setHasSchedule(source.isHasSchedule());
}
if (source.isActivated() != null) {
destination.setActivated(source.isActivated());
}
if (source.getDeviceLifecycleStatus() != null) {
destination.setDeviceLifecycleStatus(DeviceLifecycleStatus.valueOf(source.getDeviceLifecycleStatus().name()));
}
// clearing the existing Eans to prevent duplication
destination.setEans(new ArrayList<Ean>());
for (final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Ean ean : source.getEans()) {
final Ean newEan = new Ean(destination, ean.getCode(), ean.getDescription());
destination.getEans().add(newEan);
}
return destination;
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleSwitchDeviceEvents.
private void handleSwitchDeviceEvents(final Device device, final List<Event> switchDeviceEvents) throws UnknownEntityException {
LOGGER.info("handleSwitchDeviceEvents() called for device: {} with lightSwitchingEvents.size(): {}", device.getDeviceIdentification(), switchDeviceEvents.size());
if (switchDeviceEvents.isEmpty()) {
return;
}
// Determine light and tariff relays for SSLD.
final Ssld ssld = this.eventNotificationHelperService.findSsld(device.getId());
final Set<Integer> indexesLightRelays = new TreeSet<>();
final Set<Integer> indexesTariffRelays = new TreeSet<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
indexesLightRelays.add(deviceOutputSetting.getExternalId());
}
if (deviceOutputSetting.getOutputType().equals(RelayType.TARIFF) || deviceOutputSetting.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
indexesTariffRelays.add(deviceOutputSetting.getExternalId());
}
}
this.printRelayIndexes(indexesLightRelays, indexesTariffRelays, device.getDeviceIdentification());
final Map<Integer, RelayStatus> lastRelayStatusPerIndex = new TreeMap<>();
for (final Event lightSwitchingEvent : switchDeviceEvents) {
final Integer index = lightSwitchingEvent.getIndex();
if (index == 0) {
this.handleLightSwitchingEventForIndex0(indexesLightRelays, device, lightSwitchingEvent, lastRelayStatusPerIndex);
} else {
this.createRelayStatus(device, lightSwitchingEvent, index, lastRelayStatusPerIndex);
}
}
this.printRelayStatuses(lastRelayStatusPerIndex, device.getDeviceIdentification());
if (!lastRelayStatusPerIndex.isEmpty()) {
LOGGER.info("calling ssld.updateSwitchingEventRelayStatuses() for device: {} with lastRelayStatusPerIndex.size(): {}", ssld.getDeviceIdentification(), lastRelayStatusPerIndex.size());
ssld.updateSwitchingEventRelayStatuses(lastRelayStatusPerIndex);
this.eventNotificationHelperService.saveSsld(ssld);
this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), ssld.getDeviceIdentification(), null);
}
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class EventNotificationMessageService method handleSwitchingEvent.
private void handleSwitchingEvent(final String deviceIdentification, final Date dateTime, final EventType eventType, final int index) throws UnknownEntityException {
final Ssld ssld = this.eventNotificationHelperService.findSsld(deviceIdentification);
// index.
if (index == 0) {
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
if (deviceOutputSetting.getOutputType().equals(RelayType.LIGHT)) {
this.updateRelayStatusForEvent(deviceOutputSetting.getExternalId(), ssld, dateTime, eventType);
}
}
} else {
this.updateRelayStatusForEvent(index, ssld, dateTime, eventType);
}
this.eventNotificationHelperService.saveSsld(ssld);
this.sendRequestMessageToDomainCore(MessageType.RELAY_STATUS_UPDATED_EVENTS.name(), deviceIdentification, null);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method handleSsld.
private void handleSsld(final String deviceIdentification, final DeviceStatus status, 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, DomainType.TARIFF_SWITCHING), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, DomainType.PUBLIC_LIGHTING), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
deviceStatusMapped.setBootLoaderVersion(status.getBootLoaderVersion());
deviceStatusMapped.setCurrentConfigurationBackUsed(status.getCurrentConfigurationBackUsed());
deviceStatusMapped.setCurrentIp(status.getCurrentIp());
deviceStatusMapped.setCurrentTime(status.getCurrentTime());
deviceStatusMapped.setDcOutputVoltageCurrent(status.getDcOutputVoltageCurrent());
deviceStatusMapped.setDcOutputVoltageMaximum(status.getDcOutputVoltageMaximum());
deviceStatusMapped.setEventNotificationsMask(status.getEventNotificationsMask());
deviceStatusMapped.setExternalFlashMemSize(status.getExternalFlashMemSize());
deviceStatusMapped.setFirmwareVersion(status.getFirmwareVersion());
deviceStatusMapped.setHardwareId(status.getHardwareId());
deviceStatusMapped.setInternalFlashMemSize(status.getInternalFlashMemSize());
deviceStatusMapped.setLastInternalTestResultCode(status.getLastInternalTestResultCode());
deviceStatusMapped.setMacAddress(status.getMacAddress());
deviceStatusMapped.setMaximumOutputPowerOnDcOutput(status.getMaximumOutputPowerOnDcOutput());
deviceStatusMapped.setName(status.getName());
deviceStatusMapped.setNumberOfOutputs(status.getNumberOfOutputs());
deviceStatusMapped.setSerialNumber(status.getSerialNumber());
deviceStatusMapped.setStartupCounter(status.getStartupCounter());
// 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_CORE, "SSLD was not able to report relay status", new NoDeviceResponseException()));
response.setResult(ResponseMessageResultType.NOT_OK);
}
}
Aggregations