refactor(alarms): harden ExtractTagAlarm severity parse (TryGetInt32) + trim projector prior-state (review nits)
This commit is contained in:
@@ -12,8 +12,7 @@ namespace ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
/// </summary>
|
||||
public sealed class NativeAlarmProjector
|
||||
{
|
||||
private readonly Dictionary<string, (bool Active, bool Acked, ushort Severity, string Message)> _prior =
|
||||
new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, (bool Active, bool Acked)> _prior = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Project an alarm transition onto the full condition snapshot for <paramref name="nodeId"/>.</summary>
|
||||
/// <param name="nodeId">The materialised condition node's id (the projection's state key).</param>
|
||||
@@ -21,9 +20,7 @@ public sealed class NativeAlarmProjector
|
||||
/// <returns>The full Part 9 condition snapshot to write to the node.</returns>
|
||||
public AlarmConditionSnapshot Project(string nodeId, AlarmEventArgs e)
|
||||
{
|
||||
var prev = _prior.TryGetValue(nodeId, out var p)
|
||||
? p
|
||||
: (Active: false, Acked: true, Severity: (ushort)0, Message: string.Empty);
|
||||
var prev = _prior.TryGetValue(nodeId, out var p) ? p : (Active: false, Acked: true);
|
||||
var sev = MapSeverity(e.Severity);
|
||||
var (active, acked) = e.Kind switch
|
||||
{
|
||||
@@ -32,7 +29,7 @@ public sealed class NativeAlarmProjector
|
||||
AlarmTransitionKind.Clear => (false, prev.Acked),
|
||||
_ => (prev.Active, prev.Acked),
|
||||
};
|
||||
_prior[nodeId] = (active, acked, sev, e.Message);
|
||||
_prior[nodeId] = (active, acked);
|
||||
return new AlarmConditionSnapshot(
|
||||
Active: active, Acknowledged: acked, Confirmed: true, Enabled: true,
|
||||
Shelving: AlarmShelvingKind.Unshelved, Severity: sev, Message: e.Message);
|
||||
|
||||
Reference in New Issue
Block a user