private void x10_SendX10Result(object sender, X10EventArgs e) { if (e.ResultCode == 0) //OK { X10Event2XPLMsg(e, true); } else //error { XplMsg x = xL.GetPreparedXplMessage(XplMsg.xPLMsgType.trig, true); x.Class = "log"; x.Type = "basic"; x.AddKeyValuePair("type", "err"); x.AddKeyValuePair("code", "x10"); x.AddKeyValuePair("text", "error " + e.Devices + " " + X10Enum2String(e.X10Command)); x.Send(); // string xplMsg = "type=err" + '\n' + "code=x10" + '\n' + "text=error " + e.Devices + " " + X10Enum2String(e.X10Command) + '\n'; // xL.SendMessage("xpl-cmnd", "*", "log.basic", xplMsg); } }
private void InitRunSpace() { //create Powershell runspace runspace = null; runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); //expose the xPL message this rule reacted on if (ScriptInfo.xPLMessageString != null) { XplMsg xpl = new XplMsg(ScriptInfo.xPLMessageString); runspace.SessionStateProxy.SetVariable("Msg", xpl); } else { //provide the object anyway runspace.SessionStateProxy.SetVariable("Msg", null); } runspace.SessionStateProxy.SetVariable("Sys", new Sys(ScriptInfo.HalIPAddress)); }
private void X10Event2XPLMsg(X10EventArgs e, bool confirmation) { //string xplMsg = string.Empty; XplMsg x = xL.GetPreparedXplMessage(XplMsg.xPLMsgType.trig, true); x.Class = "x10"; if (e.Devices.Length == 1) //housecode, no devices { //xplMsg = "command=" + X10Enum2String(e.X10Command) + '\n' + "house=" + e.Devices + '\n'; x.AddKeyValuePair("command", X10Enum2String(e.X10Command)); x.AddKeyValuePair("house", e.Devices); if (e.X10Command == (byte)X10_COMMANDS.BRIGHT || e.X10Command == (byte)X10_COMMANDS.DIM || e.X10Command == (byte)X10_COMMANDS.PRESET_DIM1 || e.X10Command == (byte)X10_COMMANDS.PRESET_DIM2) { //xplMsg += "level=" + e.Brightness.ToString() + '\n'; x.AddKeyValuePair("level", e.Brightness.ToString()); } else if (e.X10Command == (byte)X10_COMMANDS.EXTENDED) { //xplMsg += "data1=" + e.Data1.ToString() + '\n' + "data2=" + e.Data2.ToString() + '\n'; x.AddKeyValuePair("data1", e.Data1.ToString()); x.AddKeyValuePair("data2", e.Data2.ToString()); } if (confirmation) { //xL.SendMessage("xpl-trig", "*", "x10.confirm", xplMsg); x.Type = "confirm"; } else { //xL.SendMessage("xpl-trig", "*", "x10.basic", xplMsg); x.Type = "basic"; } x.Send(); } else //devices, send an xpl msg per device { string[] ardev = e.Devices.Split(','); for (int i = 0; i < ardev.Length; i++) { //xplMsg = "command=" + X10Enum2String(e.X10Command) + '\n' + "device=" + (i>0?ardev[0].Substring(0,1):"") + ardev[i] + '\n'; x.AddKeyValuePair("command", X10Enum2String(e.X10Command)); x.AddKeyValuePair("device", (i > 0 ? ardev[0].Substring(0, 1) : "") + ardev[i]); if (e.X10Command == (byte)X10_COMMANDS.BRIGHT || e.X10Command == (byte)X10_COMMANDS.DIM || e.X10Command == (byte)X10_COMMANDS.PRESET_DIM1 || e.X10Command == (byte)X10_COMMANDS.PRESET_DIM2) { //xplMsg += "level=" + e.Brightness.ToString() + '\n'; x.AddKeyValuePair("level", e.Brightness.ToString()); } else if (e.X10Command == (byte)X10_COMMANDS.EXTENDED) { //xplMsg += "data1=" + e.Data1.ToString() + '\n' + "data2=" + e.Data2.ToString() + '\n'; x.AddKeyValuePair("data1", e.Data1.ToString()); x.AddKeyValuePair("data2", e.Data2.ToString()); } if (confirmation) { //xL.SendMessage("xpl-trig", "*", "x10.confirm", xplMsg); x.Type = "confirm"; } else { //xL.SendMessage("xpl-trig", "*", "x10.basic", xplMsg); x.Type = "basic"; } x.Send(); } } }