use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class BaseTask method findDevices.
/**
* Try to find all devices which are not 'in maintenance' for a list of device models.
*/
protected List<Device> findDevices(final List<DeviceModel> deviceModels, final String deviceType) {
LOGGER.info("Trying to find devices for device models for manufacturer...");
final List<Device> devices = new ArrayList<>();
for (final DeviceModel deviceModel : deviceModels) {
final List<Device> devsInUse = this.deviceRepository.findByDeviceModelAndDeviceTypeAndInMaintenanceAndDeviceLifecycleStatus(deviceModel, deviceType, false, DeviceLifecycleStatus.IN_USE);
final List<Device> devsRegistered = this.deviceRepository.findByDeviceModelAndDeviceTypeAndInMaintenanceAndDeviceLifecycleStatus(deviceModel, deviceType, false, DeviceLifecycleStatus.REGISTERED);
devices.addAll(devsInUse);
devices.addAll(devsRegistered);
}
if (devices.isEmpty()) {
LOGGER.warn("No devices found for device models for manufacturer");
} else {
LOGGER.info("{} devices found for device models for manufacturer", devices.size());
for (final Device device : devices) {
LOGGER.info(" device: {}", device.getDeviceIdentification());
}
}
return devices;
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class BaseTask method getGatewayLastCommunicationTime.
private long getGatewayLastCommunicationTime(final LightMeasurementDevice lightMeasurementDevice, final long valueForMissingTime) {
final Device gatewayDevice = lightMeasurementDevice.getGatewayDevice();
if (gatewayDevice == null) {
return valueForMissingTime;
}
final long lastSuccessFullConnectionTimestampGateway = getTime(gatewayDevice.getLastSuccessfulConnectionTimestamp(), valueForMissingTime);
final long lastCommunicationTimeRtuGateway = this.rtuDeviceRepository.findById(gatewayDevice.getId()).map(rtu -> getTime(rtu.getLastCommunicationTime(), valueForMissingTime)).orElse(valueForMissingTime);
return Long.max(lastSuccessFullConnectionTimestampGateway, lastCommunicationTimeRtuGateway);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class SetEncryptionKeyExchangeOnGMeterDataConverter method convert.
@Override
public GMeterInfoDto convert(final SetEncryptionKeyExchangeOnGMeterRequestData value, final SmartMeter smartMeter) throws FunctionalException {
final SmartMeter gasDevice = this.domainHelperService.findSmartMeter(value.getDeviceIdentification());
final Device gatewayDevice = gasDevice.getGatewayDevice();
if (gatewayDevice == null) {
/*
* For now throw a FunctionalException, based on the same reasoning
* as with the channel a couple of lines up. As soon as we have
* scenario's with direct communication with gas meters this will
* have to be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have an energy meter as gateway device."));
}
return new GMeterInfoDto(gasDevice.getChannel(), gasDevice.getDeviceIdentification());
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class MonitoringService method requestActualMeterReads.
public void requestActualMeterReads(final MessageMetadata messageMetadata, final ActualMeterReadsQuery actualMeterReadsQuery) throws FunctionalException {
LOGGER.info("requestActualMeterReads for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
if (actualMeterReadsQuery.isMbusDevice()) {
if (smartMeter.getChannel() == null) {
/*
* For now, throw a FunctionalException. As soon as we can
* communicate with some types of gas meters directly, and not
* through an M-Bus port of an energy meter, this will have to
* be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have a channel configured."));
}
final Device gatewayDevice = smartMeter.getGatewayDevice();
if (gatewayDevice == null) {
/*
* For now throw a FunctionalException, based on the same
* reasoning as with the channel a couple of lines up. As soon
* as we have scenario's with direct communication with gas
* meters this will have to be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have an energy meter as gateway device."));
}
final ActualMeterReadsQueryDto requestDto = new ActualMeterReadsQueryDto(ChannelDto.fromNumber(smartMeter.getChannel()));
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
} else {
this.osgpCoreRequestMessageSender.send(new ActualMeterReadsQueryDto(), messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class AddDeviceSteps method findDeviceByDeviceIdentification.
private Device findDeviceByDeviceIdentification(final String deviceIdentification) {
final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
assertThat(device).as("Device must exist for identification " + deviceIdentification).isNotNull();
return device;
}
Aggregations