minor refactoring code to get OTA package id

This commit is contained in:
Peter Chen 2022-11-24 11:21:28 +11:00 committed by Andrii Shvaika
parent cc3372d963
commit 7914f3d1d0

View File

@ -181,22 +181,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
private void update(TenantId tenantId, DeviceProfile deviceProfile, OtaPackageType otaPackageType) {
Consumer<Device> updateConsumer;
OtaPackageId packageId = null;
if (otaPackageType.equals(FIRMWARE)) {
if (deviceProfile.getFirmwareId() != null) {
packageId = deviceProfile.getFirmwareId();
}
}
else if (otaPackageType.equals(SOFTWARE)) {
if (deviceProfile.getSoftwareId() != null) {
packageId = deviceProfile.getSoftwareId();
}
}
OtaPackageId packageId = otaPackageType.equals(FIRMWARE)? deviceProfile.getFirmwareId() : deviceProfile.getSoftwareId();
if (packageId != null) {
long ts = System.currentTimeMillis();
OtaPackageId finalPackageId = packageId;
updateConsumer = d -> send(d.getTenantId(), d.getId(), finalPackageId, ts, otaPackageType);
updateConsumer = d -> send(d.getTenantId(), d.getId(), packageId, ts, otaPackageType);
} else {
updateConsumer = d -> remove(d, otaPackageType);
}