Skip to content
Merged
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
@@ -0,0 +1,106 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class BarrierOperatorCommandClassTests
{
[TestMethod]
public void EventSignalSetCommand_Create_On()
{
var command = BarrierOperatorCommandClass.EventSignalSetCommand.Create(
BarrierOperatorSignalingSubsystemType.AudibleNotification,
on: true);

Assert.AreEqual(4, command.Frame.Data.Length);
Assert.AreEqual(CommandClassId.BarrierOperator, command.Frame.CommandClassId);
Assert.AreEqual((byte)BarrierOperatorCommand.EventSignalSet, command.Frame.CommandId);
Assert.AreEqual((byte)BarrierOperatorSignalingSubsystemType.AudibleNotification, command.Frame.CommandParameters.Span[0]);
Assert.AreEqual((byte)0xFF, command.Frame.CommandParameters.Span[1]);
}

[TestMethod]
public void EventSignalSetCommand_Create_Off()
{
var command = BarrierOperatorCommandClass.EventSignalSetCommand.Create(
BarrierOperatorSignalingSubsystemType.VisualNotification,
on: false);

Assert.AreEqual(4, command.Frame.Data.Length);
Assert.AreEqual((byte)BarrierOperatorSignalingSubsystemType.VisualNotification, command.Frame.CommandParameters.Span[0]);
Assert.AreEqual((byte)0x00, command.Frame.CommandParameters.Span[1]);
}

[TestMethod]
public void EventSignalingGetCommand_Create()
{
var command = BarrierOperatorCommandClass.EventSignalingGetCommand.Create(
BarrierOperatorSignalingSubsystemType.AudibleNotification);

Assert.AreEqual(3, command.Frame.Data.Length);
Assert.AreEqual(CommandClassId.BarrierOperator, command.Frame.CommandClassId);
Assert.AreEqual((byte)BarrierOperatorCommand.EventSignalingGet, command.Frame.CommandId);
Assert.AreEqual((byte)BarrierOperatorSignalingSubsystemType.AudibleNotification, command.Frame.CommandParameters.Span[0]);
}

[TestMethod]
public void EventSignalingReportCommand_Parse_On()
{
byte[] data = [0x66, 0x08, 0x01, 0xFF];
CommandClassFrame frame = new(data);

BarrierOperatorEventSignalReport report =
BarrierOperatorCommandClass.EventSignalingReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorSignalingSubsystemType.AudibleNotification, report.SubsystemType);
Assert.AreEqual((byte)0xFF, report.SubsystemState);
Assert.IsTrue(report.IsOn);
}

[TestMethod]
public void EventSignalingReportCommand_Parse_Off()
{
byte[] data = [0x66, 0x08, 0x02, 0x00];
CommandClassFrame frame = new(data);

BarrierOperatorEventSignalReport report =
BarrierOperatorCommandClass.EventSignalingReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorSignalingSubsystemType.VisualNotification, report.SubsystemType);
Assert.AreEqual((byte)0x00, report.SubsystemState);
Assert.IsFalse(report.IsOn);
}

[TestMethod]
public void EventSignalingReportCommand_Parse_ReservedState()
{
byte[] data = [0x66, 0x08, 0x01, 0x55];
CommandClassFrame frame = new(data);

BarrierOperatorEventSignalReport report =
BarrierOperatorCommandClass.EventSignalingReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorSignalingSubsystemType.AudibleNotification, report.SubsystemType);
Assert.AreEqual((byte)0x55, report.SubsystemState);
Assert.IsNull(report.IsOn);
}

[TestMethod]
public void EventSignalingReportCommand_Parse_TooShort_Throws()
{
byte[] data = [0x66, 0x08, 0x01];
CommandClassFrame frame = new(data);

Assert.ThrowsExactly<ZWaveException>(
() => BarrierOperatorCommandClass.EventSignalingReportCommand.Parse(frame, NullLogger.Instance));
}

[TestMethod]
public void EventSignalingReportCommand_Parse_Empty_Throws()
{
byte[] data = [0x66, 0x08];
CommandClassFrame frame = new(data);

Assert.ThrowsExactly<ZWaveException>(
() => BarrierOperatorCommandClass.EventSignalingReportCommand.Parse(frame, NullLogger.Instance));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class BarrierOperatorCommandClassTests
{
[TestMethod]
public void SetCommand_Create_Open()
{
var command = BarrierOperatorCommandClass.BarrierOperatorSetCommand.Create(BarrierOperatorTargetValue.Open);

Assert.AreEqual(3, command.Frame.Data.Length);
Assert.AreEqual(CommandClassId.BarrierOperator, command.Frame.CommandClassId);
Assert.AreEqual((byte)BarrierOperatorCommand.Set, command.Frame.CommandId);
Assert.AreEqual((byte)0xFF, command.Frame.CommandParameters.Span[0]);
}

[TestMethod]
public void SetCommand_Create_Close()
{
var command = BarrierOperatorCommandClass.BarrierOperatorSetCommand.Create(BarrierOperatorTargetValue.Close);

Assert.AreEqual(3, command.Frame.Data.Length);
Assert.AreEqual((byte)0x00, command.Frame.CommandParameters.Span[0]);
}

[TestMethod]
public void GetCommand_Create()
{
var command = BarrierOperatorCommandClass.BarrierOperatorGetCommand.Create();

Assert.AreEqual(2, command.Frame.Data.Length);
Assert.AreEqual(CommandClassId.BarrierOperator, command.Frame.CommandClassId);
Assert.AreEqual((byte)BarrierOperatorCommand.Get, command.Frame.CommandId);
}

[TestMethod]
public void ReportCommand_Parse_Closed()
{
byte[] data = [0x66, 0x03, 0x00];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x00, report.StateValue);
Assert.AreEqual(BarrierOperatorState.Closed, report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_Open()
{
byte[] data = [0x66, 0x03, 0xFF];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0xFF, report.StateValue);
Assert.AreEqual(BarrierOperatorState.Open, report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_Opening()
{
byte[] data = [0x66, 0x03, 0xFE];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Opening, report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_Closing()
{
byte[] data = [0x66, 0x03, 0xFC];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Closing, report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_Stopped()
{
byte[] data = [0x66, 0x03, 0xFD];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Stopped, report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_StoppedAtPosition_50Percent()
{
byte[] data = [0x66, 0x03, 0x32];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Stopped, report.State);
Assert.AreEqual((byte)50, report.Position);
}

[TestMethod]
public void ReportCommand_Parse_StoppedAtPosition_1Percent()
{
byte[] data = [0x66, 0x03, 0x01];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Stopped, report.State);
Assert.AreEqual((byte)1, report.Position);
}

[TestMethod]
public void ReportCommand_Parse_StoppedAtPosition_99Percent()
{
byte[] data = [0x66, 0x03, 0x63];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(BarrierOperatorState.Stopped, report.State);
Assert.AreEqual((byte)99, report.Position);
}

[TestMethod]
public void ReportCommand_Parse_ReservedValue()
{
byte[] data = [0x66, 0x03, 0xAA];
CommandClassFrame frame = new(data);

BarrierOperatorReport report = BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0xAA, report.StateValue);
Assert.IsNull(report.State);
Assert.IsNull(report.Position);
}

[TestMethod]
public void ReportCommand_Parse_TooShort_Throws()
{
byte[] data = [0x66, 0x03];
CommandClassFrame frame = new(data);

Assert.ThrowsExactly<ZWaveException>(
() => BarrierOperatorCommandClass.BarrierOperatorReportCommand.Parse(frame, NullLogger.Instance));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class BarrierOperatorCommandClassTests
{
[TestMethod]
public void SignalSupportedGetCommand_Create()
{
var command = BarrierOperatorCommandClass.SignalSupportedGetCommand.Create();

Assert.AreEqual(2, command.Frame.Data.Length);
Assert.AreEqual(CommandClassId.BarrierOperator, command.Frame.CommandClassId);
Assert.AreEqual((byte)BarrierOperatorCommand.SignalSupportedGet, command.Frame.CommandId);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_BothSubsystems()
{
// Bit 0 = type 0x01 (Audible), bit 1 = type 0x02 (Visual) → 0x03
byte[] data = [0x66, 0x05, 0x03];
CommandClassFrame frame = new(data);

IReadOnlySet<BarrierOperatorSignalingSubsystemType> supported =
BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.HasCount(2, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.AudibleNotification, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.VisualNotification, supported);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_AudibleOnly()
{
// Bit 0 = type 0x01 (Audible) → 0x01
byte[] data = [0x66, 0x05, 0x01];
CommandClassFrame frame = new(data);

IReadOnlySet<BarrierOperatorSignalingSubsystemType> supported =
BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.HasCount(1, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.AudibleNotification, supported);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_VisualOnly()
{
// Bit 1 = type 0x02 (Visual) → 0x02
byte[] data = [0x66, 0x05, 0x02];
CommandClassFrame frame = new(data);

IReadOnlySet<BarrierOperatorSignalingSubsystemType> supported =
BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.HasCount(1, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.VisualNotification, supported);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_NoneSupported()
{
// All bits zero — no subsystems supported
byte[] data = [0x66, 0x05, 0x00];
CommandClassFrame frame = new(data);

IReadOnlySet<BarrierOperatorSignalingSubsystemType> supported =
BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.IsEmpty(supported);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_MultiByteMask()
{
// 2-byte bitmask: byte 0 = 0x03 (types 1,2), byte 1 = 0x01 (type 9)
byte[] data = [0x66, 0x05, 0x03, 0x01];
CommandClassFrame frame = new(data);

IReadOnlySet<BarrierOperatorSignalingSubsystemType> supported =
BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.HasCount(3, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.AudibleNotification, supported);
Assert.Contains(BarrierOperatorSignalingSubsystemType.VisualNotification, supported);
Assert.Contains((BarrierOperatorSignalingSubsystemType)9, supported);
}

[TestMethod]
public void SignalSupportedReportCommand_Parse_TooShort_Throws()
{
byte[] data = [0x66, 0x05];
CommandClassFrame frame = new(data);

Assert.ThrowsExactly<ZWaveException>(
() => BarrierOperatorCommandClass.SignalSupportedReportCommand.Parse(frame, NullLogger.Instance));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ZWave.CommandClasses.Tests;

[TestClass]
public partial class BarrierOperatorCommandClassTests
{
}
Loading