Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class SimulatedAlarmObjectSteps {
private static final ObisCode OBIS_CODE_ALARM_OBJECT_2 = new ObisCode(0, 0, 97, 98, 1, 255);
private static final ObisCode OBIS_CODE_ALARM_OBJECT_3 = new ObisCode(0, 0, 97, 98, 2, 255);

private static final String ALARM_VALUE = "33693956";
private static final String ALARM_VALUE_1 = "33693956";
private static final String ALARM_VALUE_2 = "3";
private static final String ALARM_VALUE_3 = "3";

@Autowired private DeviceSimulatorSteps deviceSimulatorSteps;

Expand All @@ -37,7 +39,8 @@ public void deviceHasSomeAlarmsRegistered(

final ObisCode alarmRegisterObisCode = this.getAlarmRegisterObisCode(alarmRegisterNr);
final ObjectNode attributeValue =
this.jsonObjectCreator.createAttributeValue("double-long-unsigned", ALARM_VALUE);
this.jsonObjectCreator.createAttributeValue(
"double-long-unsigned", this.getAlarmRegisterValue(alarmRegisterNr));
this.deviceSimulatorSteps.setDlmsAttributeValue(
CLASS_ID, alarmRegisterObisCode, ATTRIBUTE_ID_VALUE, attributeValue, OBJECT_DESCRIPTION);
}
Expand Down Expand Up @@ -78,4 +81,17 @@ private ObisCode getAlarmRegisterObisCode(final int alarmRegisterNr) {
throw new IllegalArgumentException("There is no alarmRegister: " + alarmRegisterNr);
}
}

private String getAlarmRegisterValue(final int alarmRegisterNr) {
switch (alarmRegisterNr) {
case 1:
return ALARM_VALUE_1;
case 2:
return ALARM_VALUE_2;
case 3:
return ALARM_VALUE_3;
default:
throw new IllegalArgumentException("There is no alarmRegister: " + alarmRegisterNr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.opensmartgridplatform.dlms.objectconfig.DlmsObjectType;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionRequestDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.ClearAlarmRegisterRequestDto;
import org.opensmartgridplatform.shared.infra.jms.MessageMetadata;
import org.springframework.stereotype.Component;
Expand All @@ -31,13 +32,16 @@
public class ClearAlarmRegisterCommandExecutor
extends AbstractCommandExecutor<ClearAlarmRegisterRequestDto, AccessResultCode> {

private final ReadAlarmRegisterCommandExecutor readAlarmRegisterCommandExecutor;
final ObjectConfigServiceHelper objectConfigServiceHelper;

private static final int ALARM_CODE = 0;

public ClearAlarmRegisterCommandExecutor(
final ReadAlarmRegisterCommandExecutor readAlarmRegisterCommandExecutor,
final ObjectConfigServiceHelper objectConfigServiceHelper) {
super(ClearAlarmRegisterRequestDto.class);
this.readAlarmRegisterCommandExecutor = readAlarmRegisterCommandExecutor;
this.objectConfigServiceHelper = objectConfigServiceHelper;
}

Expand Down Expand Up @@ -67,6 +71,9 @@ public AccessResultCode execute(
final MessageMetadata messageMetadata)
throws ProtocolAdapterException {

if (!this.alarmsArePresent(conn, device)) {
return AccessResultCode.SUCCESS;
}
// Clear alarm 1
final Optional<AccessResultCode> optionalResultCodeAlarm1 =
this.clearAlarmRegister(conn, device, DlmsObjectType.ALARM_REGISTER_1);
Expand Down Expand Up @@ -95,6 +102,17 @@ public AccessResultCode execute(
return optionalResultCodeAlarm3.orElse(resultCodeAlarmRegister2);
}

private boolean alarmsArePresent(final DlmsConnectionManager conn, final DlmsDevice device) {
try {
final AlarmRegisterResponseDto alarmRegisterResponse =
this.readAlarmRegisterCommandExecutor.execute(conn, device, null, null);

return !alarmRegisterResponse.getAlarmTypes().isEmpty();
} catch (final ProtocolAdapterException e) {
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block silently returns false without logging the exception. This could mask important errors and make debugging difficult. Consider logging the exception or providing more specific error handling.

Suggested change
} catch (final ProtocolAdapterException e) {
} catch (final ProtocolAdapterException e) {
log.error("Exception occurred while reading alarm register in alarmsArePresent", e);

Copilot uses AI. Check for mistakes.

return false;
}
}

private Optional<AccessResultCode> clearAlarmRegister(
final DlmsConnectionManager conn, final DlmsDevice device, final DlmsObjectType objectType)
throws ProtocolAdapterException {
Expand Down
Loading