Merge pull request #5758 from YevhenBondarenko/fix/ota-state-service

[3.3.3] fixed removing fw/sw attributes if fw/sw is not set
This commit is contained in:
Igor Kulikov 2021-12-21 17:28:42 +02:00 committed by GitHub
commit f441058c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,17 +122,17 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
newFirmwareId = newDeviceProfile.getFirmwareId(); newFirmwareId = newDeviceProfile.getFirmwareId();
} }
if (oldDevice != null) { if (oldDevice != null) {
if (newFirmwareId != null) {
OtaPackageId oldFirmwareId = oldDevice.getFirmwareId(); OtaPackageId oldFirmwareId = oldDevice.getFirmwareId();
if (oldFirmwareId == null) { if (oldFirmwareId == null) {
DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId());
oldFirmwareId = oldDeviceProfile.getFirmwareId(); oldFirmwareId = oldDeviceProfile.getFirmwareId();
} }
if (newFirmwareId != null) {
if (!newFirmwareId.equals(oldFirmwareId)) { if (!newFirmwareId.equals(oldFirmwareId)) {
// Device was updated and new firmware is different from previous firmware. // Device was updated and new firmware is different from previous firmware.
send(device.getTenantId(), device.getId(), newFirmwareId, System.currentTimeMillis(), FIRMWARE); send(device.getTenantId(), device.getId(), newFirmwareId, System.currentTimeMillis(), FIRMWARE);
} }
} else { } else if (oldFirmwareId != null){
// Device was updated and new firmware is not set. // Device was updated and new firmware is not set.
remove(device, FIRMWARE); remove(device, FIRMWARE);
} }
@ -149,17 +149,17 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
newSoftwareId = newDeviceProfile.getSoftwareId(); newSoftwareId = newDeviceProfile.getSoftwareId();
} }
if (oldDevice != null) { if (oldDevice != null) {
if (newSoftwareId != null) {
OtaPackageId oldSoftwareId = oldDevice.getSoftwareId(); OtaPackageId oldSoftwareId = oldDevice.getSoftwareId();
if (oldSoftwareId == null) { if (oldSoftwareId == null) {
DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId()); DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId());
oldSoftwareId = oldDeviceProfile.getSoftwareId(); oldSoftwareId = oldDeviceProfile.getSoftwareId();
} }
if (newSoftwareId != null) {
if (!newSoftwareId.equals(oldSoftwareId)) { if (!newSoftwareId.equals(oldSoftwareId)) {
// Device was updated and new firmware is different from previous firmware. // Device was updated and new firmware is different from previous firmware.
send(device.getTenantId(), device.getId(), newSoftwareId, System.currentTimeMillis(), SOFTWARE); send(device.getTenantId(), device.getId(), newSoftwareId, System.currentTimeMillis(), SOFTWARE);
} }
} else { } else if (oldSoftwareId != null){
// Device was updated and new firmware is not set. // Device was updated and new firmware is not set.
remove(device, SOFTWARE); remove(device, SOFTWARE);
} }