feat(commons): enrich AlarmStateChanged with unified condition state (additive)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
|
||||
@@ -26,4 +27,48 @@ public record AlarmStateChanged(
|
||||
/// surface this to operators.
|
||||
/// </summary>
|
||||
public string Message { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this alarm is computed at the site or mirrored from a native
|
||||
/// source. Defaults to <see cref="AlarmKind.Computed"/>.
|
||||
/// </summary>
|
||||
public AlarmKind Kind { get; init; } = AlarmKind.Computed;
|
||||
|
||||
private AlarmConditionState? _condition;
|
||||
|
||||
/// <summary>
|
||||
/// Unified A&C-style condition (active/acked/shelved/suppressed + severity).
|
||||
/// When not explicitly set, defaults to a computed mapping of
|
||||
/// <see cref="State"/> + <see cref="Priority"/> so existing callers and
|
||||
/// computed alarms carry a correct condition without extra work.
|
||||
/// </summary>
|
||||
public AlarmConditionState Condition
|
||||
{
|
||||
get => _condition ?? AlarmConditionStateFactory.ForComputed(State, Priority);
|
||||
init => _condition = value;
|
||||
}
|
||||
|
||||
/// <summary>Native per-condition key (e.g. "Tank01.Level.HiHi"); empty for computed alarms.</summary>
|
||||
public string SourceReference { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>Native alarm type name (e.g. "AnalogLimitAlarm.HiHi"); empty for computed alarms.</summary>
|
||||
public string AlarmTypeName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>Native alarm category/taxonomy; empty for computed alarms.</summary>
|
||||
public string Category { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>Operator who acknowledged at the source (display-only); empty otherwise.</summary>
|
||||
public string OperatorUser { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>Operator comment captured at the source (display-only); empty otherwise.</summary>
|
||||
public string OperatorComment { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>When the native condition originally became active, if known.</summary>
|
||||
public DateTimeOffset? OriginalRaiseTime { get; init; }
|
||||
|
||||
/// <summary>Current source value (display-only); empty for computed alarms.</summary>
|
||||
public string CurrentValue { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>Limit/threshold value for native limit alarms (display-only); empty otherwise.</summary>
|
||||
public string LimitValue { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
||||
|
||||
/// <summary>Builds <see cref="AlarmConditionState"/> values for the supported alarm kinds.</summary>
|
||||
public static class AlarmConditionStateFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Computed alarms have no native ack/shelve/suppress lifecycle: they are
|
||||
/// auto-acked, never shelved or suppressed, not confirmable, and their
|
||||
/// severity is the configured priority. Active mirrors the alarm State.
|
||||
/// </summary>
|
||||
public static AlarmConditionState ForComputed(AlarmState state, int priority) =>
|
||||
new(Active: state == AlarmState.Active, Acknowledged: true, Confirmed: null,
|
||||
Shelve: AlarmShelveState.Unshelved, Suppressed: false, Severity: priority);
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Messages;
|
||||
|
||||
public class AlarmStateChangedEnrichmentTests
|
||||
{
|
||||
[Fact]
|
||||
public void Defaults_AreComputedKind_WithAutoAck()
|
||||
{
|
||||
var m = new AlarmStateChanged("inst", "HiAlarm", AlarmState.Active, 700, DateTimeOffset.UnixEpoch);
|
||||
Assert.Equal(AlarmKind.Computed, m.Kind);
|
||||
Assert.True(m.Condition.Acknowledged); // computed = auto-acked
|
||||
Assert.Equal(700, m.Condition.Severity); // severity defaults to Priority
|
||||
Assert.True(m.Condition.Active); // derived from State
|
||||
Assert.Equal("", m.SourceReference);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Factory_ForComputed_MapsPriorityAndState()
|
||||
{
|
||||
var c = AlarmConditionStateFactory.ForComputed(AlarmState.Normal, priority: 250);
|
||||
Assert.False(c.Active);
|
||||
Assert.True(c.Acknowledged);
|
||||
Assert.Equal(250, c.Severity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user