Skip to content
Snippets Groups Projects
Commit 16419e29 authored by Georgios Katsikas's avatar Georgios Katsikas
Browse files

fix(automation): ztpUpdate loop resolved

parent 568149a1
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!6fix(automation): ztpUpdate loop resolved
...@@ -50,33 +50,34 @@ public class AutomationServiceImpl implements AutomationService { ...@@ -50,33 +50,34 @@ public class AutomationServiceImpl implements AutomationService {
device -> { device -> {
final var id = deviceId; final var id = deviceId;
if (!device.isEnabled()) { if (device.isEnabled()) {
LOGGER.infof(MESSAGE, device); LOGGER.warnf("%s has already been enabled. Ignoring...", device);
return;
final var initialConfiguration =
deviceService.getInitialConfiguration(device.getDeviceId());
device.enableDevice();
LOGGER.infof("Enabled device [%s]", id);
initialConfiguration
.subscribe()
.with(
deviceConfig -> {
device.setDeviceConfiguration(deviceConfig);
final var configuredDeviceIdUni = deviceService.configureDevice(device);
configuredDeviceIdUni
.subscribe()
.with(
configuredDeviceId ->
LOGGER.infof(
"Device [%s] has been enabled and configured successfully with %s.\n",
id, deviceConfig));
});
} else {
LOGGER.infof("%s has been already enabled. Ignoring...", device);
} }
LOGGER.infof(MESSAGE, device);
final var initialConfiguration =
deviceService.getInitialConfiguration(device.getDeviceId());
device.enableDevice();
LOGGER.infof("Enabled device [%s]", id);
initialConfiguration
.subscribe()
.with(
deviceConfig -> {
device.setDeviceConfiguration(deviceConfig);
final var configuredDeviceIdUni = deviceService.configureDevice(device);
configuredDeviceIdUni
.subscribe()
.with(
configuredDeviceId ->
LOGGER.infof(
"Device [%s] has been successfully enabled and configured with %s.\n",
id, deviceConfig));
});
}); });
return deserializedDeviceUni; return deserializedDeviceUni;
...@@ -92,13 +93,23 @@ public class AutomationServiceImpl implements AutomationService { ...@@ -92,13 +93,23 @@ public class AutomationServiceImpl implements AutomationService {
device -> { device -> {
final var id = deviceId; final var id = deviceId;
if (device.isDisabled()) {
LOGGER.warnf("%s has already been disabled. Ignoring...", device);
return;
}
device.disableDevice();
LOGGER.infof("Disabled device [%s]", id);
LOGGER.infof(MESSAGE, device); LOGGER.infof(MESSAGE, device);
final var empty = deviceService.deleteDevice(device.getDeviceId()); final var empty = deviceService.deleteDevice(device.getDeviceId());
empty empty
.subscribe() .subscribe()
.with(emptyMessage -> LOGGER.infof("Device [%s] has been deleted.\n", id)); .with(
emptyMessage ->
LOGGER.infof("Device [%s] has been successfully deleted.\n", id));
}); });
return deserializedDeviceUni; return deserializedDeviceUni;
...@@ -114,6 +125,11 @@ public class AutomationServiceImpl implements AutomationService { ...@@ -114,6 +125,11 @@ public class AutomationServiceImpl implements AutomationService {
device -> { device -> {
final var id = deviceId; final var id = deviceId;
if (!device.isEnabled()) {
LOGGER.warnf("Cannot update disabled device %s. Ignoring...", device);
return;
}
LOGGER.infof(MESSAGE, device); LOGGER.infof(MESSAGE, device);
device.setDeviceConfiguration(deviceConfig); device.setDeviceConfiguration(deviceConfig);
final var updatedDeviceIdUni = deviceService.configureDevice(device); final var updatedDeviceIdUni = deviceService.configureDevice(device);
...@@ -123,7 +139,7 @@ public class AutomationServiceImpl implements AutomationService { ...@@ -123,7 +139,7 @@ public class AutomationServiceImpl implements AutomationService {
.with( .with(
configuredDeviceId -> configuredDeviceId ->
LOGGER.infof( LOGGER.infof(
"Device [%s] has been updated successfully with %s.\n", "Device [%s] has been successfully updated with %s.\n",
id, deviceConfig)); id, deviceConfig));
}); });
......
...@@ -78,9 +78,11 @@ public class ContextSubscriber { ...@@ -78,9 +78,11 @@ public class ContextSubscriber {
automationService.deleteDevice(deviceEvent.getDeviceId()); automationService.deleteDevice(deviceEvent.getDeviceId());
break; break;
case UPDATE: case UPDATE:
LOGGER.infof("Received %s for device [%s]", event, deviceId); LOGGER.warnf(
automationService.updateDevice( "Received %s for device [%s]. " +
deviceEvent.getDeviceId(), deviceEvent.getDeviceConfig().orElse(null)); "No automation action on an already updated device",
event, deviceId);
break;
case UNDEFINED: case UNDEFINED:
logWarningMessage(event, deviceId, eventType); logWarningMessage(event, deviceId, eventType);
break; break;
......
...@@ -61,10 +61,18 @@ public class Device { ...@@ -61,10 +61,18 @@ public class Device {
return deviceOperationalStatus == DeviceOperationalStatus.ENABLED; return deviceOperationalStatus == DeviceOperationalStatus.ENABLED;
} }
public boolean isDisabled() {
return deviceOperationalStatus == DeviceOperationalStatus.DISABLED;
}
public void enableDevice() { public void enableDevice() {
this.deviceOperationalStatus = DeviceOperationalStatus.ENABLED; this.deviceOperationalStatus = DeviceOperationalStatus.ENABLED;
} }
public void disableDevice() {
this.deviceOperationalStatus = DeviceOperationalStatus.DISABLED;
}
public String getDeviceId() { public String getDeviceId() {
return deviceId; return deviceId;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment