public void GetMessageLightOFFTestShouldPass() { LightingMessage message = Lighting.GetMessage("*1*0*11##"); Assert.AreEqual <WHAT>(message.What, WHAT.LightOFF); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void GetMessageDimmerStrenghtTestShouldPass() { LightingMessage message = Lighting.GetMessage("*1*3*11##"); Assert.AreEqual <WHAT>(message.What, WHAT.DimmerStrenght); Assert.AreEqual <int>(message.DimmerStrenght, 30); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void GetMessageLightONAtSpeedTestShouldPass() { LightingMessage message = Lighting.GetMessage("*1*1#100*11##"); Assert.AreEqual <WHAT>(message.What, WHAT.LightOnAtSpeed); Assert.AreEqual <int>(message.Speed, 100); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void Invoke_LightingMessage_ToString_With_GetStatus_11() { var message = new LightingMessage(); message.Message = LIGHT_11_GETSTATUS; message.What = LightingWhat.GetStatus; message.Where = Where.GetWhere("11"); Assert.AreEqual(message.ToString(), LIGHT_11_GETSTATUS); }
public void Invoke_LightingMessage_ToString_With_Light_11_OFF() { var message = new LightingMessage(); message.Message = LIGHT_11_OFF; message.What = LightingWhat.LightOFF; message.Where = Where.GetWhere("11"); Assert.AreEqual(message.ToString(), LIGHT_11_OFF); }
public void GetMessageLuminousIntensityChangeTestShouldPass() { LightingMessage message = Lighting.GetMessage("*#1*11*2*200*100##"); Assert.AreEqual <WHAT>(message.What, WHAT.LightLuminousIntensityChange); Assert.AreEqual <int>(message.Level, 200); Assert.AreEqual <int>(message.Speed, 100); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void GetMessageDimmerDownOfYAtXSpeedTestShouldPass() { LightingMessage message = Lighting.GetMessage("*1*31#100#200*11##"); Assert.AreEqual <WHAT>(message.What, WHAT.DimmerDownAtSpeed); Assert.AreEqual <int>(message.Level, 100); Assert.AreEqual <int>(message.Speed, 200); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void Invoke_LightMessage_ToString_With_Dimmer_Strenght_30() { var message = new LightingMessage(); message.What = LightingWhat.DimmerStrenght; message.DimmerStrenght = 30; message.Where = Where.GetWhere("11"); message.Message = LIGHT_11_DIMMER_STRENGHT; Assert.AreEqual(message.ToString(), LIGHT_11_DIMMER_STRENGHT); }
public void Invoke_LightingMessage_ToString_With_Light_11_ON_At_Speed_100() { var message = new LightingMessage(); message.Message = LIGHT_11_ON_AT_SPEED_100; message.What = LightingWhat.LightOnAtSpeed; message.Speed = 100; message.Where = Where.GetWhere("11"); Assert.AreEqual(message.ToString(), LIGHT_11_ON_AT_SPEED_100); }
public void GetMessageTemporizationTestShouldPass() { LightingMessage message = Lighting.GetMessage("*#1*11*1*1*2*3##"); Assert.AreEqual <WHAT>(message.What, WHAT.LightTemporization); Assert.AreEqual <int>(message.Temporization.Hours, 1); Assert.AreEqual <int>(message.Temporization.Minutes, 2); Assert.AreEqual <int>(message.Temporization.Seconds, 3); Assert.AreEqual <int>(message.Where.A, 1); Assert.AreEqual <int>(message.Where.PL, 1); }
public void Set_LightingMessage_Properties() { var message = new LightingMessage(); message.Message = LIGHT_11_OFF; message.What = LightingWhat.LightOFF; message.Where = Where.GetWhere("11"); Assert.AreEqual(message.MessageType, MessageType.Command); Assert.AreEqual(message.Who, WHO.Lighting); Assert.AreEqual(message.What, LightingWhat.LightOFF); Assert.AreEqual(message.Message, LIGHT_11_OFF); Assert.AreEqual(message.Where.A, 1); Assert.AreEqual(message.Where.PL, 1); }
// parte di temporizzazione da controllare & blinking public static LightingMessage GetMessage(string data) { LightingMessage message = null; string[] content, parts; if (string.IsNullOrEmpty(data)) { return(null); } try { message = new LightingMessage(); content = data.Remove(data.Length - 2, 2).Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); if (content[0].Contains("#")) { // Could be a Temporization or a Luminous Intensity Changed command if (content[2] == "1") { message.What = WHAT.LightTemporization; message.Temporization = new TimeSpan(int.Parse(content[3]), int.Parse(content[4]), int.Parse(content[5])); } else if (content[2] == "2") { message.What = WHAT.LightLuminousIntensityChange; message.Level = int.Parse(content[3]); message.Speed = int.Parse(content[4]); } message.Where = Where.GetWhere(content[1]); } else { parts = content[1].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) { // Could be a "y levels at x speed" command switch (GetWhat(parts[0])) { case WHAT.DimmerUp: message.What = WHAT.DimmerUpAtSpeed; break; case WHAT.DimmerDown: message.What = WHAT.DimmerDownAtSpeed; break; } message.Level = int.Parse(parts[1]); message.Speed = int.Parse(parts[2]); } else if (parts.Length == 2) { // Could be a "at speed" command switch (GetWhat(parts[0])) { case WHAT.LightON: message.What = WHAT.LightOnAtSpeed; break; case WHAT.LightOFF: message.What = WHAT.LightOffAtSpeed; break; } message.Speed = int.Parse(parts[1]); } else { message.What = GetWhat(parts[0]); if (message.What == WHAT.DimmerStrenght) { message.DimmerStrenght = int.Parse(parts[0]) * 10; } } message.Where = Where.GetWhere(content[2]); } } catch (Exception) { return(null); } return(message); }