use of org.thingsboard.rule.engine.profile.state.PersistedAlarmState in project thingsboard by thingsboard.
the class DeviceState method getOrInitPersistedAlarmState.
private PersistedAlarmState getOrInitPersistedAlarmState(DeviceProfileAlarm alarm) {
if (pds != null) {
PersistedAlarmState alarmState = pds.getAlarmStates().get(alarm.getId());
if (alarmState == null) {
alarmState = new PersistedAlarmState();
alarmState.setCreateRuleStates(new HashMap<>());
pds.getAlarmStates().put(alarm.getId(), alarmState);
}
return alarmState;
} else {
return null;
}
}
use of org.thingsboard.rule.engine.profile.state.PersistedAlarmState in project thingsboard by thingsboard.
the class AlarmState method updateState.
public void updateState(DeviceProfileAlarm alarm, PersistedAlarmState alarmState) {
this.alarmDefinition = alarm;
this.createRulesSortedBySeverityDesc = new ArrayList<>();
alarmDefinition.getCreateRules().forEach((severity, rule) -> {
PersistedAlarmRuleState ruleState = null;
if (alarmState != null) {
ruleState = alarmState.getCreateRuleStates().get(severity);
if (ruleState == null) {
ruleState = new PersistedAlarmRuleState();
alarmState.getCreateRuleStates().put(severity, ruleState);
}
}
createRulesSortedBySeverityDesc.add(new AlarmRuleState(severity, rule, deviceProfile.getCreateAlarmKeys(alarm.getId(), severity), ruleState, dynamicPredicateValueCtx));
});
createRulesSortedBySeverityDesc.sort(Comparator.comparingInt(state -> state.getSeverity().ordinal()));
PersistedAlarmRuleState ruleState = alarmState == null ? null : alarmState.getClearRuleState();
if (alarmDefinition.getClearRule() != null) {
clearState = new AlarmRuleState(null, alarmDefinition.getClearRule(), deviceProfile.getClearAlarmKeys(alarm.getId()), ruleState, dynamicPredicateValueCtx);
}
}
Aggregations