refactor(alarms): harden ExtractTagAlarm severity parse (TryGetInt32) + trim projector prior-state (review nits)
This commit is contained in:
@@ -469,7 +469,7 @@ public static class Phase7Composer
|
||||
var type = a.TryGetProperty("alarmType", out var tEl) && tEl.ValueKind == JsonValueKind.String
|
||||
? (tEl.GetString() ?? "AlarmCondition") : "AlarmCondition";
|
||||
var sev = a.TryGetProperty("severity", out var sEl) && sEl.ValueKind == JsonValueKind.Number
|
||||
? sEl.GetInt32() : 500;
|
||||
&& sEl.TryGetInt32(out var sv) ? sv : 500;
|
||||
return new EquipmentTagAlarmInfo(type, sev);
|
||||
}
|
||||
catch (JsonException) { return null; }
|
||||
|
||||
@@ -666,7 +666,7 @@ public static class DeploymentArtifact
|
||||
var type = a.TryGetProperty("alarmType", out var tEl) && tEl.ValueKind == JsonValueKind.String
|
||||
? (tEl.GetString() ?? "AlarmCondition") : "AlarmCondition";
|
||||
var sev = a.TryGetProperty("severity", out var sEl) && sEl.ValueKind == JsonValueKind.Number
|
||||
? sEl.GetInt32() : 500;
|
||||
&& sEl.TryGetInt32(out var sv) ? sv : 500;
|
||||
return new EquipmentTagAlarmInfo(type, sev);
|
||||
}
|
||||
catch (JsonException) { return null; }
|
||||
|
||||
@@ -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