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,100 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class CentralSceneCommandClassTests
{
[TestMethod]
public void ConfigurationSet_Create_SlowRefreshEnabled()
{
CentralSceneCommandClass.CentralSceneConfigurationSetCommand command =
CentralSceneCommandClass.CentralSceneConfigurationSetCommand.Create(slowRefresh: true);

Assert.AreEqual(CommandClassId.CentralScene, CentralSceneCommandClass.CentralSceneConfigurationSetCommand.CommandClassId);
Assert.AreEqual((byte)CentralSceneCommand.ConfigurationSet, CentralSceneCommandClass.CentralSceneConfigurationSetCommand.CommandId);
Assert.AreEqual(3, command.Frame.Data.Length); // CC + Cmd + Properties1
Assert.AreEqual((byte)0x80, command.Frame.CommandParameters.Span[0]); // Bit 7 set
}

[TestMethod]
public void ConfigurationSet_Create_SlowRefreshDisabled()
{
CentralSceneCommandClass.CentralSceneConfigurationSetCommand command =
CentralSceneCommandClass.CentralSceneConfigurationSetCommand.Create(slowRefresh: false);

Assert.AreEqual((byte)0x00, command.Frame.CommandParameters.Span[0]); // Bit 7 clear
}

[TestMethod]
public void ConfigurationGet_Create_HasCorrectFormat()
{
CentralSceneCommandClass.CentralSceneConfigurationGetCommand command =
CentralSceneCommandClass.CentralSceneConfigurationGetCommand.Create();

Assert.AreEqual(CommandClassId.CentralScene, CentralSceneCommandClass.CentralSceneConfigurationGetCommand.CommandClassId);
Assert.AreEqual((byte)CentralSceneCommand.ConfigurationGet, CentralSceneCommandClass.CentralSceneConfigurationGetCommand.CommandId);
Assert.AreEqual(2, command.Frame.Data.Length); // CC + Cmd only
}

[TestMethod]
public void ConfigurationReport_Parse_SlowRefreshEnabled()
{
// CC=0x5B, Cmd=0x06, Properties1=0x80 (SlowRefresh=1)
byte[] data = [0x5B, 0x06, 0x80];
CommandClassFrame frame = new(data);

CentralSceneConfigurationReport report =
CentralSceneCommandClass.CentralSceneConfigurationReportCommand.Parse(frame, NullLogger.Instance);

Assert.IsTrue(report.SlowRefresh);
}

[TestMethod]
public void ConfigurationReport_Parse_SlowRefreshDisabled()
{
// CC=0x5B, Cmd=0x06, Properties1=0x00 (SlowRefresh=0)
byte[] data = [0x5B, 0x06, 0x00];
CommandClassFrame frame = new(data);

CentralSceneConfigurationReport report =
CentralSceneCommandClass.CentralSceneConfigurationReportCommand.Parse(frame, NullLogger.Instance);

Assert.IsFalse(report.SlowRefresh);
}

[TestMethod]
public void ConfigurationReport_Parse_ReservedBitsIgnored()
{
// CC=0x5B, Cmd=0x06, Properties1=0x7F (SlowRefresh=0, Reserved bits set)
byte[] data = [0x5B, 0x06, 0x7F];
CommandClassFrame frame = new(data);

CentralSceneConfigurationReport report =
CentralSceneCommandClass.CentralSceneConfigurationReportCommand.Parse(frame, NullLogger.Instance);

Assert.IsFalse(report.SlowRefresh);
}

[TestMethod]
public void ConfigurationReport_Parse_TooShort_Throws()
{
// CC=0x5B, Cmd=0x06, no parameters
byte[] data = [0x5B, 0x06];
CommandClassFrame frame = new(data);

Assert.Throws<ZWaveException>(
() => CentralSceneCommandClass.CentralSceneConfigurationReportCommand.Parse(frame, NullLogger.Instance));
}

[TestMethod]
public void ConfigurationSet_Create_RoundTrips()
{
CentralSceneCommandClass.CentralSceneConfigurationSetCommand command =
CentralSceneCommandClass.CentralSceneConfigurationSetCommand.Create(slowRefresh: true);

CentralSceneConfigurationReport report =
CentralSceneCommandClass.CentralSceneConfigurationReportCommand.Parse(command.Frame, NullLogger.Instance);

Assert.IsTrue(report.SlowRefresh);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class CentralSceneCommandClassTests
{
[TestMethod]
public void Notification_Parse_Version1_KeyPressed()
{
// CC=0x5B, Cmd=0x03, SeqNum=0x01, Properties1=0x00 (KeyPressed), SceneNumber=0x01
byte[] data = [0x5B, 0x03, 0x01, 0x00, 0x01];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x01, notification.SequenceNumber);
Assert.AreEqual(CentralSceneKeyAttribute.KeyPressed, notification.KeyAttribute);
Assert.AreEqual((byte)0x01, notification.SceneNumber);
Assert.IsFalse(notification.SlowRefresh);
}

[TestMethod]
public void Notification_Parse_KeyReleased()
{
// CC=0x5B, Cmd=0x03, SeqNum=0x05, Properties1=0x01 (KeyReleased), SceneNumber=0x03
byte[] data = [0x5B, 0x03, 0x05, 0x01, 0x03];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x05, notification.SequenceNumber);
Assert.AreEqual(CentralSceneKeyAttribute.KeyReleased, notification.KeyAttribute);
Assert.AreEqual((byte)0x03, notification.SceneNumber);
}

[TestMethod]
public void Notification_Parse_KeyHeldDown()
{
// CC=0x5B, Cmd=0x03, SeqNum=0x0A, Properties1=0x02 (KeyHeldDown), SceneNumber=0x02
byte[] data = [0x5B, 0x03, 0x0A, 0x02, 0x02];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x0A, notification.SequenceNumber);
Assert.AreEqual(CentralSceneKeyAttribute.KeyHeldDown, notification.KeyAttribute);
Assert.AreEqual((byte)0x02, notification.SceneNumber);
}

[TestMethod]
public void Notification_Parse_Version2_KeyPressed2Times()
{
// CC=0x5B, Cmd=0x03, SeqNum=0x10, Properties1=0x03 (KeyPressed2Times), SceneNumber=0x01
byte[] data = [0x5B, 0x03, 0x10, 0x03, 0x01];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x10, notification.SequenceNumber);
Assert.AreEqual(CentralSceneKeyAttribute.KeyPressed2Times, notification.KeyAttribute);
Assert.AreEqual((byte)0x01, notification.SceneNumber);
}

[TestMethod]
public void Notification_Parse_Version3_SlowRefreshEnabled()
{
// CC=0x5B, Cmd=0x03, SeqNum=0x20, Properties1=0x82 (SlowRefresh=1, KeyHeldDown=0x02), SceneNumber=0x01
byte[] data = [0x5B, 0x03, 0x20, 0x82, 0x01];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)0x20, notification.SequenceNumber);
Assert.AreEqual(CentralSceneKeyAttribute.KeyHeldDown, notification.KeyAttribute);
Assert.AreEqual((byte)0x01, notification.SceneNumber);
Assert.IsTrue(notification.SlowRefresh);
}

[TestMethod]
public void Notification_Parse_KeyAttributeExtractedFromLower3Bits()
{
// Properties1=0xFD: bits 7-3 = 11111, bits 2-0 = 101 (KeyPressed4Times=0x05)
byte[] data = [0x5B, 0x03, 0x01, 0xFD, 0x01];
CommandClassFrame frame = new(data);

CentralSceneNotification notification =
CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual(CentralSceneKeyAttribute.KeyPressed4Times, notification.KeyAttribute);
}

[TestMethod]
public void Notification_Parse_TooShort_Throws()
{
// CC=0x5B, Cmd=0x03, only 2 parameter bytes (need 3)
byte[] data = [0x5B, 0x03, 0x01, 0x00];
CommandClassFrame frame = new(data);

Assert.Throws<ZWaveException>(
() => CentralSceneCommandClass.CentralSceneNotificationCommand.Parse(frame, NullLogger.Instance));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using Microsoft.Extensions.Logging.Abstractions;

namespace ZWave.CommandClasses.Tests;

public partial class CentralSceneCommandClassTests
{
[TestMethod]
public void SupportedGet_Create_HasCorrectFormat()
{
CentralSceneCommandClass.CentralSceneSupportedGetCommand command =
CentralSceneCommandClass.CentralSceneSupportedGetCommand.Create();

Assert.AreEqual(CommandClassId.CentralScene, CentralSceneCommandClass.CentralSceneSupportedGetCommand.CommandClassId);
Assert.AreEqual((byte)CentralSceneCommand.SupportedGet, CentralSceneCommandClass.CentralSceneSupportedGetCommand.CommandId);
Assert.AreEqual(2, command.Frame.Data.Length); // CC + Cmd only
}

[TestMethod]
public void SupportedReport_Parse_Version1_SupportedScenesOnly()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=4
byte[] data = [0x5B, 0x02, 0x04];
CommandClassFrame frame = new(data);

CentralSceneSupportedReport report =
CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)4, report.SupportedScenes);
Assert.IsNull(report.SlowRefreshSupport);
Assert.IsNull(report.Identical);
Assert.IsNull(report.SupportedKeyAttributesPerScene);
}

[TestMethod]
public void SupportedReport_Parse_Version2_IdenticalScenes()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=3, Properties1=0x03 (Identical=1, BitMaskBytes=1),
// KeyAttributes for all scenes: 0b00001111 (KeyPressed, KeyReleased, KeyHeldDown, KeyPressed2Times)
byte[] data = [0x5B, 0x02, 0x03, 0x03, 0x0F];
CommandClassFrame frame = new(data);

CentralSceneSupportedReport report =
CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)3, report.SupportedScenes);
Assert.IsNotNull(report.SlowRefreshSupport);
Assert.IsFalse(report.SlowRefreshSupport.Value);
Assert.IsNotNull(report.Identical);
Assert.IsTrue(report.Identical.Value);
Assert.IsNotNull(report.SupportedKeyAttributesPerScene);
Assert.HasCount(1, report.SupportedKeyAttributesPerScene); // Identical=true, only 1 set
Assert.Contains(CentralSceneKeyAttribute.KeyPressed, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyReleased, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyHeldDown, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed2Times, report.SupportedKeyAttributesPerScene[0]);
}

[TestMethod]
public void SupportedReport_Parse_Version2_DifferentScenes()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=2, Properties1=0x02 (Identical=0, BitMaskBytes=1),
// Scene 1: 0b00000111 (KeyPressed, KeyReleased, KeyHeldDown)
// Scene 2: 0b00000001 (KeyPressed only)
byte[] data = [0x5B, 0x02, 0x02, 0x02, 0x07, 0x01];
CommandClassFrame frame = new(data);

CentralSceneSupportedReport report =
CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)2, report.SupportedScenes);
Assert.IsNotNull(report.Identical);
Assert.IsFalse(report.Identical.Value);
Assert.IsNotNull(report.SupportedKeyAttributesPerScene);
Assert.HasCount(2, report.SupportedKeyAttributesPerScene);

// Scene 1
Assert.Contains(CentralSceneKeyAttribute.KeyPressed, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyReleased, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyHeldDown, report.SupportedKeyAttributesPerScene[0]);
Assert.HasCount(3, report.SupportedKeyAttributesPerScene[0]);

// Scene 2
Assert.Contains(CentralSceneKeyAttribute.KeyPressed, report.SupportedKeyAttributesPerScene[1]);
Assert.HasCount(1, report.SupportedKeyAttributesPerScene[1]);
}

[TestMethod]
public void SupportedReport_Parse_Version3_SlowRefreshSupport()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=2, Properties1=0x83 (SlowRefresh=1, Identical=1, BitMaskBytes=1),
// KeyAttributes: 0b00000111
byte[] data = [0x5B, 0x02, 0x02, 0x83, 0x07];
CommandClassFrame frame = new(data);

CentralSceneSupportedReport report =
CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)2, report.SupportedScenes);
Assert.IsNotNull(report.SlowRefreshSupport);
Assert.IsTrue(report.SlowRefreshSupport.Value);
Assert.IsNotNull(report.Identical);
Assert.IsTrue(report.Identical.Value);
}

[TestMethod]
public void SupportedReport_Parse_MultiByteBitmask()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=1, Properties1=0x05 (Identical=1, BitMaskBytes=2),
// KeyAttributes: 0b01111111 0b00000000 (bits 0-6 set in first byte)
byte[] data = [0x5B, 0x02, 0x01, 0x05, 0x7F, 0x00];
CommandClassFrame frame = new(data);

CentralSceneSupportedReport report =
CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance);

Assert.AreEqual((byte)1, report.SupportedScenes);
Assert.IsNotNull(report.SupportedKeyAttributesPerScene);
Assert.HasCount(1, report.SupportedKeyAttributesPerScene);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyReleased, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyHeldDown, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed2Times, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed3Times, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed4Times, report.SupportedKeyAttributesPerScene[0]);
Assert.Contains(CentralSceneKeyAttribute.KeyPressed5Times, report.SupportedKeyAttributesPerScene[0]);
Assert.HasCount(7, report.SupportedKeyAttributesPerScene[0]);
}

[TestMethod]
public void SupportedReport_Parse_TooShort_Throws()
{
// CC=0x5B, Cmd=0x02, no parameters
byte[] data = [0x5B, 0x02];
CommandClassFrame frame = new(data);

Assert.Throws<ZWaveException>(
() => CentralSceneCommandClass.CentralSceneSupportedReportCommand.Parse(frame, NullLogger.Instance));
}

[TestMethod]
public void SupportedReport_Parse_BitmaskDataTooShort_Throws()
{
// CC=0x5B, Cmd=0x02, SupportedScenes=2, Properties1=0x02 (Identical=0, BitMaskBytes=1)
// Missing bitmask data for 2 scenes
byte[] data = [0x5B, 0x02, 0x02, 0x02, 0x07]; // Only 1 bitmask byte, need 2
CommandClassFrame frame = new(data);

Assert.Throws<ZWaveException>(
() => CentralSceneCommandClass.CentralSceneSupportedReportCommand.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 CentralSceneCommandClassTests
{
}
Loading