From: <Ba...@us...> - 2012-01-15 23:50:27
|
Revision: 4405 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4405&view=rev Author: BartEv Date: 2012-01-15 23:50:18 +0000 (Sun, 15 Jan 2012) Log Message: ----------- Modified Paths: -------------- trunk/plugins/VeraControl/DeviceDimmer.cs trunk/plugins/VeraControl/DeviceGeneric.cs trunk/plugins/VeraControl/DialogDeviceControl.cs trunk/plugins/VeraControl/Properties/AssemblyInfo.cs trunk/plugins/VeraControl/Scene.cs trunk/plugins/VeraControl/VeraCommunication.cs trunk/plugins/VeraControl/VeraControl.cs trunk/plugins/VeraControl/VeraControl.csproj trunk/plugins/VeraControl/VeraHelper.cs trunk/plugins/VeraControl/VeraSetupForm.Designer.cs trunk/plugins/VeraControl/VeraSetupForm.cs trunk/plugins/VeraControl/releases/VeraControl.xmp2 trunk/plugins/VeraControl/releases/update.xml trunk/plugins/VeraControl/skin/Default/VeraControl.xml trunk/plugins/VeraControl/skin/Default/VeraDialogDeviceControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogDeviceControl.xml Added Paths: ----------- trunk/plugins/VeraControl/DeviceCam.cs trunk/plugins/VeraControl/DeviceSceneController.cs trunk/plugins/VeraControl/DeviceSystem.cs trunk/plugins/VeraControl/DialogSceneControl.cs trunk/plugins/VeraControl/releases/VeraControl_v0.6.0.1.mpe1 trunk/plugins/VeraControl/skin/Default/VeraDialogSceneControl.xml trunk/plugins/VeraControl/skin/DefaultWide/VeraDialogSceneControl.xml trunk/plugins/VeraControl/skin/Media/Vera/IR_Transmitter.png trunk/plugins/VeraControl/skin/Media/Vera/USB_UIRT.png trunk/plugins/VeraControl/skin/Media/Vera/Zwave.png trunk/plugins/VeraControl/skin/Media/Vera/music_audio.png trunk/plugins/VeraControl/skin/Media/Vera/plugins.png trunk/plugins/VeraControl/skin/Media/Vera/users.png Added: trunk/plugins/VeraControl/DeviceCam.cs =================================================================== --- trunk/plugins/VeraControl/DeviceCam.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceCam.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -0,0 +1,88 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 7-1-2012 + * Time: 21:42 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceCam. + /// </summary> + public class DeviceCam : DeviceGeneric + { + private string m_sIp = "127.0.0.1"; + private string m_sUrl = "/"; + private string m_sStream = ""; + private string m_sVideoUrl = ""; + private int m_refresh = 10; + + public DeviceCam( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_sIp = helper.getAttrAsString(xn, "ip", m_sIp); + m_sUrl = helper.getAttrAsString(xn, "url", m_sUrl); + m_sStream = helper.getAttrAsString(xn, "streaming", m_sStream); + m_sVideoUrl = helper.getAttrAsString(xn, "videourls", m_sVideoUrl); + + return base.update(xn); + } + + public string imgUrl + { + get { return "http://" + m_sIp + "/" + m_sUrl.Replace("%2F", "/"); } + set { } + } + + public int refreshRate + { + get { return m_refresh; } + set { m_refresh = value; } + } + + private bool refreshDelayPassed(long lastcheck) + { + return ((helper.getSecondsSince1970() - refreshRate) > (lastcheck / 10000000)); + } + + public override string getIconName() + { + return "Ip_Camera"; + } + + public override bool newScreenUpdateWaitingAndClearFlag( ) + { + // Invoking this method will clear the update ready flag -> so caller need to handle the update + // A cam device requires an update every refreshRate seconds + bool b = m_bScreenUpdateRequired || refreshDelayPassed(DateTime.Now.Ticks); + m_bScreenUpdateRequired = false; + if (b) + { + m_lLastUpdate = DateTime.Now.Ticks; + } + return b; + } + + public override bool newUpdateSince(long lTimePreviousCheck) + { + bool b = (lTimePreviousCheck <= m_lLastUpdate) || refreshDelayPassed(m_lLastUpdate); + if (b) + { + m_lLastUpdate = DateTime.Now.Ticks; + } + return b; + } + } +} Modified: trunk/plugins/VeraControl/DeviceDimmer.cs =================================================================== --- trunk/plugins/VeraControl/DeviceDimmer.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/DeviceDimmer.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -57,14 +57,14 @@ { get { return m_iLevel; } set - { + { int newValue = value; if (newValue > 100) { newValue = 100; } else { if (newValue < 0) { newValue = 0; } } - if (id > 0) // Only send when a valid ID is found + if ((id > 0) && (newValue != m_iLevel)) // Only send when a valid ID is found { // Do something with vera string cmd = "?id=lu_action&DeviceNum="+id.ToString()+ @@ -97,9 +97,9 @@ { string leveltxt = "0"; if (level > 0) { leveltxt = "25"; } - if (level > 35) { leveltxt = "50"; } - if (level > 65) { leveltxt = "75"; } - if (level > 85) { leveltxt = "100"; } + if (level > 25) { leveltxt = "50"; } + if (level > 50) { leveltxt = "75"; } + if (level > 75) { leveltxt = "100"; } return "Dimmable_Light_"+leveltxt; } Modified: trunk/plugins/VeraControl/DeviceGeneric.cs =================================================================== --- trunk/plugins/VeraControl/DeviceGeneric.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/DeviceGeneric.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -21,11 +21,13 @@ /// </summary> public class DeviceGeneric { - private string m_sName = "unknown device"; - private int m_iId = 0; - private string m_sAltId = ""; - private int m_iCategory = 0; - private int m_iRoom = 0; + public long m_lLastUpdate = 0; + public bool m_bScreenUpdateRequired = false; + private string m_sName = "unknown device"; + private int m_iId = 0; + private string m_sAltId = ""; + private int m_iCategory = 0; + private int m_iRoom = 0; // not connected (-2), none (-1), pending (0,1,5,6), success(4), error (2,3) private DevState m_dsState = DevState.NONE; @@ -56,7 +58,7 @@ if (m_iId == 0) { // void device no further processing needed - return true; + return false; } // Make sure room exists if (m_iRoom == 0 || !vera.status.isRoomFound(m_iRoom)) @@ -67,6 +69,11 @@ } m_iRoom = 0; } + + // Set update flag + m_bScreenUpdateRequired = true; + m_lLastUpdate = DateTime.Now.Ticks; + return true; } @@ -176,5 +183,18 @@ { return new string [] {"Off", "On"}; } + + public virtual bool newScreenUpdateWaitingAndClearFlag( ) + { + // Invoking this method will clear the update ready flag -> so caller need to handle the update + bool b = m_bScreenUpdateRequired; + m_bScreenUpdateRequired = false; + return b; + } + + public virtual bool newUpdateSince(long lTimePreviousCheck) + { + return (lTimePreviousCheck <= m_lLastUpdate); + } } } Added: trunk/plugins/VeraControl/DeviceSceneController.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSceneController.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceSceneController.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -0,0 +1,70 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 8-1-2012 + * Time: 0:15 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Xml; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceSceneController. + /// </summary> + public class DeviceSceneController: DeviceGeneric + { + private bool m_bTripped = false; + + public DeviceSceneController( XmlNode xn ): base (xn) + { + if (xn != null) + { + update(xn); + } + } + + public override bool update(XmlNode xn) + { + m_bTripped = helper.getAttrAsBool(xn, "status", m_bTripped); + m_bTripped = helper.getAttrAsBool(xn, "tripped", m_bTripped); + return base.update(xn); + } + + public override bool status + { + get { return m_bTripped; } + set { } + } + + public bool tripped + { + get { return m_bTripped; } + set { } + } + + public override int level + { + get { return (m_bTripped ? 1 : 0); } + set { } + } + + public override string ToString() + { + return name + " [" + getStatusText() + "]"; + } + + public override string getIconName() + { + return "Motion_Sensor_" + (m_bTripped ? "100" : "0"); + } + + public override string getStatusText() + { + return (status ? "ACTIVE" : "standby"); + } + + } +} Added: trunk/plugins/VeraControl/DeviceSystem.cs =================================================================== --- trunk/plugins/VeraControl/DeviceSystem.cs (rev 0) +++ trunk/plugins/VeraControl/DeviceSystem.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -0,0 +1,177 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 12-1-2012 + * Time: 10:32 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Xml; +// using VeraControl.Properties.Devstate; + +namespace VeraControl.Properties +{ + /// <summary> + /// Description of DeviceSystem. + /// </summary> + public class DeviceSystem + { + public DeviceSystem() + { + } + + public VeraHelper helper = VeraHelper.Instance; + + public long m_lLastUpdate = 0; + public bool m_bScreenUpdateRequired = false; + private bool m_bFullReload = true; + private string m_sVersion = ""; + private string m_sModel = ""; + private bool m_zWaveHeal = false; + private bool m_bMetric = true; + private string m_sSerial = ""; + private string m_sFwd1Server = ""; + private string m_sFwd2Server = ""; + private string m_sLoadTime = "0"; + private string m_sDataVersion = "0"; + private string m_sComment = ""; + private DevState m_dsVeraState = DevState.NONE; + + + public bool update(XmlNode xn) + { + m_bFullReload = helper.getAttrAsBool (xn, "full", m_bFullReload); + m_sVersion = helper.getAttrAsString (xn, "version", m_sVersion); + m_sModel = helper.getAttrAsString (xn, "model", m_sModel); + m_zWaveHeal = helper.getAttrAsBool (xn, "zwave_heal", m_zWaveHeal); + m_sSerial = helper.getAttrAsString (xn, "serial_number", m_sSerial); + m_sFwd1Server = helper.getAttrAsString (xn, "fwd1", m_sFwd1Server); + m_sFwd2Server = helper.getAttrAsString (xn, "fwd2", m_sFwd2Server); + m_sLoadTime = helper.getAttrAsString (xn, "loadtime", m_sLoadTime); + + // Set update flag + string tempDataversion = helper.getAttrAsString (xn, "dataversion", m_sDataVersion); + DevState tempVeraState = helper.toDevState(helper.getAttrAsInt(xn, "state", -1)); + string tempComment = helper.getAttrAsString (xn, "comment", ""); + + if ((m_sDataVersion != tempDataversion) || m_sComment != tempComment || m_dsVeraState != tempVeraState) + { + m_bScreenUpdateRequired = true; + m_lLastUpdate = DateTime.Now.Ticks; + } + m_sDataVersion = tempDataversion; + m_dsVeraState = tempVeraState; + m_sComment = tempComment; + + m_dsVeraState = helper.toDevState(helper.getAttrAsInt(xn, "state", -1)); + m_sComment = helper.getAttrAsString (xn, "comment", ""); + m_bMetric = (helper.getAttrAsString(xn, "temperature", "C") == "C"); + + return true; + } + + public void clearFullReloadFlag() + { + m_bFullReload = false; + } + + public void setFullReloadFlag() + { + m_bFullReload = true; + } + public bool fullReload + { + get { return m_bFullReload; } + set { } + } + + public string versionInfo + { + get { return m_sModel + " " + m_sVersion; } + set { } + } + + public bool bZWaveHeal + { + get { return m_zWaveHeal; } + set { } + } + + public string serialno + { + get { return m_sSerial; } + set { } + } + + public string fwd + { + get { return m_sFwd1Server; } + set { } + } + + public string fwdBackup + { + get { return m_sFwd2Server; } + set { } + } + + public string loadtime + { + get { return m_sLoadTime; } + set { } + } + + public string dataversion + { + get { return m_sDataVersion; } + set { } + } + + public DevState state + { + get { return m_dsVeraState; } + set { } + } + + public string comment + { + get { return m_sComment; } + set { } + } + + public void reportConnectionError( string errmsg ) + { + m_dsVeraState = DevState.CONNECTION_ERROR; + m_sComment = errmsg; + m_bScreenUpdateRequired = true; + m_lLastUpdate = DateTime.Now.Ticks; + } + + public void clearConnectionError( ) + { + m_dsVeraState = DevState.NONE; + m_sComment = ""; + m_bScreenUpdateRequired = true; + m_lLastUpdate = DateTime.Now.Ticks; + } + + public bool isMetric() + { + return m_bMetric; + } + + public bool newScreenUpdateWaitingAndClearFlag( ) + { + // Invoking this method will clear the update ready flag -> so caller need to handle the update + bool b = m_bScreenUpdateRequired; + m_bScreenUpdateRequired = false; + return b; + } + + public bool newUpdateSince(float fTimePreviousCheck) + { + return (fTimePreviousCheck <= m_lLastUpdate); + } + } +} Modified: trunk/plugins/VeraControl/DialogDeviceControl.cs =================================================================== --- trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -4,8 +4,8 @@ * Date: 24-12-2011 * Time: 14:17 * - * Copyright: 2012 GPL - Bart Eversdijk - * MediaPort plugin - MicasaVerde (TM) Vera Controller + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller * E-mail: ba...@ev... */ using System; @@ -27,47 +27,100 @@ /// </summar`y> public class DialogDeviceControl : GUIDialogWindow { - [SkinControl(2)] protected GUIButtonControl btnClose = null; - [SkinControl(4)] protected GUILabelControl lblHeading = null; - [SkinControl(5)] protected GUIImage imgLogo = null; + [SkinControl(2)] protected GUIButtonControl btnClose = null; + [SkinControl(4)] protected GUILabelControl lblHeading = null; + [SkinControl(5)] protected GUIImage imgLogo = null; - [SkinControlAttribute(6)] protected GUILabelControl label1=null; + [SkinControlAttribute(6)] protected GUILabelControl label1=null; [SkinControlAttribute(7)] protected GUILabelControl label2=null; [SkinControlAttribute(8)] protected GUILabelControl label3=null; [SkinControl(10)] protected GUIButtonControl btnLeft = null; - [SkinControl(11)] protected GUIButtonControl btnRight = null; - [SkinControl(12)] protected GUIButtonControl btnMode1 = null; + [SkinControl(11)] protected GUIButtonControl btnRight = null; + [SkinControl(12)] protected GUIButtonControl btnMode1 = null; [SkinControl(13)] protected GUIButtonControl btnMode2 = null; [SkinControl(14)] protected GUIButtonControl btnMode3 = null; - [SkinControl(15)] protected GUISliderControl slider = null; - [SkinControl(20)] protected GUIImage camImage = null; - - - DeviceGeneric myDev = null; - + [SkinControl(15)] protected GUISliderControl slider = null; + [SkinControl(20)] protected GUIImage camImage = null; + + [SkinControl(30)] protected GUIImage cmtImage = null; + [SkinControlAttribute(31)] protected GUILabelControl comment=null; + + VeraHelper helper = new VeraHelper(); + private DeviceGeneric myDev = null; + private long m_iLastUpdate = 0; + public DialogDeviceControl() { GetID = (int)1973; } - public void InitDialog(string strLine, DeviceGeneric dev) - { - //LoadSkin(); - AllocResources(); - InitControls(); + public override bool Init() + { + bool bResult = Load(GUIGraphicsContext.Skin + @"\VeraDialogDeviceControl.xml"); + return bResult; + } - lblHeading.Label = strLine; - + + public void InitDialog(string strLine, DeviceGeneric dev) + { + //LoadSkin(); + AllocResources(); + InitControls(); + + lblHeading.Label = strLine; myDev = dev; + + if (!myDev.isControllable) + { + btnClose.SetNavigation(2,2,2,2); + } + + updateStatus(); } - - public override bool Init() - { - bool bResult = Load(GUIGraphicsContext.Skin + @"\VeraDialogDeviceControl.xml"); - return bResult; - } + public void updateStatus() + { + SetImage("Vera\\"+myDev.getIconName()+".png"); + + setComment(helper.getStateImage(myDev.commstate), myDev.comment); + + if (myDev.isControllable) + { + if (myDev.GetType() == typeof(DeviceSprinkler)) + { + SetText(myDev.name, myDev.getStatusText() + " - " + myDev.mode, myDev.getExtraText() ); + SetActiveBut((myDev.status ? 1 : 0), (myDev.mode == "Auto" ? 0 : (myDev.mode == "Block" ? 2 : 1) )); + } + else if (myDev.GetType() == typeof(DeviceThermostat)) + { + SetText(myDev.name, myDev.getStatusText(), myDev.getExtraText() ); + SetActiveBut((myDev.status ? 1 : 0), (myDev.mode == "Auto" ? 0 : + (myDev.mode == "CoolOn" || myDev.mode == "Cool" ? 1 : + (myDev.mode == "HeatOn" || myDev.mode == "Heat" ? 2 : 3) ))); + } + else + { + SetText(myDev.name, "", ""); + SetActiveBut(myDev.status ? 1 : 0, -1); + } + SetButtons(myDev.getCommands()); + SetSlider(myDev.level, myDev.maxLevel); + } + else + { + if (myDev.GetType() == typeof(DeviceCam)) + { + DeviceCam cam = (DeviceCam) myDev; + SetCamImage(cam.imgUrl); + } + SetText(myDev.name, myDev.getStatusText(), myDev.getExtraText()); + } + // save last update ticks + m_iLastUpdate = DateTime.Now.Ticks; + } + + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { if (control == btnLeft) @@ -134,7 +187,7 @@ { btnLeft.NavigateUp = 12; btnRight.NavigateUp = 14; - + if (butTxt.Length < 5) { // if only 2 buttons required, use right iso middle button @@ -176,10 +229,10 @@ { btnMode1.TextColor = (iModeNr == 0 ? 0xFFFFFF00 : 0xFFFFFFFF ); btnMode1.TextColorNoFocus = (iModeNr == 0 ? 0x60FFFF00 : 0x60ffffff); - + btnMode2.TextColor = (iModeNr == 1 ? 0xFFFFFF00 : 0xFFFFFFFF ); btnMode2.TextColorNoFocus = (iModeNr == 1 ? 0x60FFFF00 : 0x60ffffff); - + btnMode3.TextColor = (iModeNr == 2 ? 0xFFFFFF00 : 0xFFFFFFFF ); btnMode3.TextColorNoFocus = (iModeNr == 2 ? 0x60FFFF00 : 0x60ffffff); } @@ -203,5 +256,29 @@ imgLogo.AllocResources(); imgLogo.KeepAspectRatio = true; } + + public void setComment(string img, string txt) + { + if (img != "") { + cmtImage.Dispose(); + cmtImage.SetFileName(img); + cmtImage.KeepAspectRatio = true; + cmtImage.Visibility = System.Windows.Visibility.Visible; + cmtImage.AllocResources(); + } else{ + cmtImage.Visibility = System.Windows.Visibility.Hidden; + } + comment.Label = txt; + } + + public override void Render(float timePassed) + { + if (myDev.newUpdateSince(m_iLastUpdate)) + { + updateStatus(); + } + + base.Render(timePassed); + } } } Added: trunk/plugins/VeraControl/DialogSceneControl.cs =================================================================== --- trunk/plugins/VeraControl/DialogSceneControl.cs (rev 0) +++ trunk/plugins/VeraControl/DialogSceneControl.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -0,0 +1,120 @@ +/* + * Created by SharpDevelop. + * User: Bart + * Date: 24-12-2011 + * Time: 14:17 + * + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller + * E-mail: ba...@ev... + */ +using System; +using System.Collections; +using MediaPortal; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +using Alignment = MediaPortal.GUI.Library.GUIControl.Alignment; +using VAlignment = MediaPortal.GUI.Library.GUIControl.VAlignment; +using Action = MediaPortal.GUI.Library.Action; +using VeraControl.Properties; + +namespace VeraControl +{ + /// <summary> + /// Description of DialogDeviceControl. + /// </summar`y> + public class DialogSceneControl : GUIDialogWindow + { + [SkinControl(2)] protected GUIButtonControl btnClose = null; + [SkinControl(4)] protected GUILabelControl lblHeading = null; + [SkinControl(5)] protected GUIImage imgLogo = null; + + [SkinControlAttribute(6)] protected GUILabelControl label1=null; + + [SkinControl(11)] protected GUIButtonControl btnRight = null; + + [SkinControl(30)] protected GUIImage cmtImage = null; + [SkinControlAttribute(31)] protected GUILabelControl comment=null; + + VeraHelper helper = new VeraHelper(); + private Scene myScene = null; + private long m_iLastUpdate = 0; + + public DialogSceneControl() + { + GetID = (int)1975; + } + + public override bool Init() + { + bool bResult = Load(GUIGraphicsContext.Skin + @"\VeraDialogSceneControl.xml"); + return bResult; + } + + + public void InitDialog(string strLine, Scene scene) + { + //LoadSkin(); + AllocResources(); + InitControls(); + + lblHeading.Label = strLine; + myScene = scene; + + updateStatus(); + } + + public void updateStatus() + { + setComment(helper.getStateImage(myScene.commstate), myScene.comment); + + label1.Label = myScene.name; + + // save last update ticks + m_iLastUpdate = DateTime.Now.Ticks; + } + + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + if (control == btnRight) + { + if (myScene.id != 0) { + comment.Label = "Running..."; + myScene.run(); + + } + } + + // Back to the text button to switch from image view + if (control == btnClose) + { + PageDestroy(); + } + base.OnClicked(controlId, control, actionType); + } + + public void setComment(string img, string txt) + { + if (img != "") { + cmtImage.Dispose(); + cmtImage.SetFileName(img); + cmtImage.KeepAspectRatio = true; + cmtImage.Visibility = System.Windows.Visibility.Visible; + cmtImage.AllocResources(); + } else{ + cmtImage.Visibility = System.Windows.Visibility.Hidden; + } + comment.Label = txt; + } + + public override void Render(float timePassed) + { + if (myScene.newUpdateSince(m_iLastUpdate)) + { + updateStatus(); + } + base.Render(timePassed); + } + } +} Modified: trunk/plugins/VeraControl/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/VeraControl/Properties/AssemblyInfo.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/Properties/AssemblyInfo.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -28,4 +28,4 @@ // // You can specify all the values or you can use the default the Revision and // Build Numbers by using the '*' as shown below: -[assembly: AssemblyVersion("0.5.0.1")] +[assembly: AssemblyVersion("0.5.1.0")] Modified: trunk/plugins/VeraControl/Scene.cs =================================================================== --- trunk/plugins/VeraControl/Scene.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/Scene.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -4,8 +4,8 @@ * Date: 22-12-2011 * Time: 13:50 * - * Copyright: 2012 GPL - Bart Eversdijk - * MediaPort plugin - MicasaVerde (TM) Vera Controller + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller * E-mail: ba...@ev... */ using System; @@ -28,11 +28,14 @@ } public VeraHelper helper = VeraHelper.Instance; + private bool m_bScreenUpdateRequired = false; private string m_sName = "unknown scene"; private int m_iId = 0; private bool m_bActive = false; private int m_iRoom = 0; + private long m_lLastUpdate = 0; + // not connected (-2), none (-1), pending (0,1,5,6), success(4), error (2,3) private string m_sComment = ""; // red(error), green(success) or blue(pending) - icon/text private DevState m_dsState = DevState.NONE; @@ -47,6 +50,9 @@ m_sComment = helper.getAttrAsString(xn, "comment", m_sComment ); m_dsState = helper.toDevState(helper.getAttrAsInt(xn, "state", -1)); + // Set update reqired flag + m_lLastUpdate = DateTime.Now.Ticks; + m_bScreenUpdateRequired = true; return true; } @@ -55,7 +61,7 @@ get { return m_iId; } set { } } - + public string name { get { return m_sName; } @@ -72,7 +78,7 @@ get { return (commstate != DevState.NONE ? m_sComment : ""); } set { } } - + public bool isActive() { return m_bActive; @@ -102,7 +108,25 @@ } VeraCommunication vera = VeraCommunication.Instance; string cmd = "?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="+id; - return vera.doVeraRequest(cmd, true); + return vera.doVeraRequest(cmd); } + + public bool newScreenUpdateWaitingAndClearFlag( ) + { + // Invoking this method will clear the update ready flag -> so caller need to handle the update + bool b = m_bScreenUpdateRequired; + m_bScreenUpdateRequired = false; + if (m_dsState != DevState.NONE && (m_lLastUpdate < (DateTime.Now.Ticks - (10 * 10000000)))) + { + m_dsState = DevState.NONE; + return true; + } + return b; + } + + public virtual bool newUpdateSince(long lTimePreviousCheck) + { + return (lTimePreviousCheck <= m_lLastUpdate); + } } } Modified: trunk/plugins/VeraControl/VeraCommunication.cs =================================================================== --- trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -4,13 +4,14 @@ * Date: 21-12-2011 * Time: 22:26 * - * Copyright: 2012 GPL - Bart Eversdijk - * MediaPort plugin - MicasaVerde (TM) Vera Controller + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller * E-mail: ba...@ev... */ using System; using System.Net; using System.IO; +using System.Threading; using System.Collections.Generic; using System.Xml; @@ -22,6 +23,7 @@ public class VeraStatus { + public DeviceSystem system = new DeviceSystem(); public List<DeviceGeneric> devices = new List<DeviceGeneric>(); public List<Scene> scenes = new List<Scene>(); public List<Room> rooms = new List<Room>(); @@ -164,22 +166,29 @@ public sealed class VeraCommunication { private static volatile VeraCommunication instance; - private static object syncRoot = new Object(); + private static object syncRoot = new Object(); + private VeraHelper helper = VeraHelper.Instance; - private string m_sVeraIPAddress; - private string m_sVeraTCPIPPort; - private string m_sDataVersion = ""; - private bool m_bMetric = true; - private DevState m_dsVeraState = DevState.NONE; - private string m_sComment = ""; + // Config data + private string m_sVeraIPAddress; + private string m_sVeraTCPIPPort; + private int m_iMaxRefreshDelay; + + // Actual device information private VeraStatus m_status = new VeraStatus(); - private long m_lLastUpdate = 0; - private bool m_bUpdatePending = false; + // Communication status/control + private long m_lLastUpdate = 0; + private bool m_bUpdatePending = false; + private bool m_bScreenUpdateRequired = false; // Only true when a new update was received AND at least one device(staus) or scene was changed + private bool m_bLastUpdateFailed = false; + private string m_strLastUpdateError = ""; + private WebClient m_webClient = new WebClient(); + + // Action control table public int[] actionTriggerTable = new int[(int)Actiontrigger.LAST_ACTIONTRIGGER]; - private VeraHelper helper = VeraHelper.Instance; - + public static VeraCommunication Instance { get @@ -208,39 +217,132 @@ //m_sVeraIPAddress = "192.10.1.240"; // m_sVeraIPAddress = "demo.mios.com"; // m_sVeraTCPIPPort = "3480"; - + // Fill action table (config settings) for (Actiontrigger i = 0; i < Actiontrigger.LAST_ACTIONTRIGGER; i++) { actionTriggerTable[(int)i] = xmlreader.GetValueAsInt("veracontroller", i.ToString(), 0); } + m_iMaxRefreshDelay = int.Parse(xmlreader.GetValueAsString("veracontroller", "maxrefreshdelay", "60")); + + // Set DownloadStringCompleted handler + m_webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnAsyncCompletedEventArgs); } } - public bool updateCurrentStatus() + public void updateCurrentStatus(long lNow) { - if (m_bUpdatePending) + /* when to update in case connection gets lost --> keep updating with webClient timeout 180 sec....*/ + /* TODO: watch-dog !!! last time > 4 * maxDelay force an update - to recover from hibernate */ + if (m_bUpdatePending /* && m_lLastUpdate < ((lNow / 10000000) - (4 * m_iMaxRefreshDelay)) */) { - return false; + return; } + m_bUpdatePending = true; - string verastatus = doVeraRequest("?id=lu_sdata&output_format=xml"); - m_lLastUpdate = getSecondsSince1970(); + string url = "?id=lu_sdata&loadtime=" + m_status.system.loadtime + "&dataversion=" + m_status.system.dataversion + "&minimumdelay=2000&timeout=" + m_iMaxRefreshDelay + "&output_format=xml"; + doVeraRequest(url, OnAsyncCompletedEventArgs); + m_lLastUpdate = helper.getSecondsSince1970(); + } + + public bool isVeraAlive(string ip, string port) + { + string response = retrieveURL("http://" + ip + ":" + port + "/data_request?id=lu_alive&time="+DateTime.Now.Ticks); + return (response == "OK"); + } + + public string doVeraRequest(string param) + { + return retrieveURL("http://" + vera_Address + "/data_request" + param + "&time="+DateTime.Now.Ticks); + } + + public void doVeraRequest(string param, Action<object, DownloadStringCompletedEventArgs> onCallBack) + { + retrieveURLAsync("http://" + vera_Address + "/data_request" + param + "&time="+DateTime.Now.Ticks); + } + + private string retrieveURL(string url) + { + // No callback thus Synchronised call (wait for response) + try { + m_webClient.CancelAsync(); // Cancel any current pending Async calls... + return m_webClient.DownloadString(url); + } catch( Exception e ) + { + m_bLastUpdateFailed = true; + m_strLastUpdateError = e.Message; + return "ERROR"; + } + + } + + private void retrieveURLAsync(string url) + { + // Callback thus ASynchronised call (do NOT wait for response) + try { + m_webClient.CancelAsync(); // Cancel any current pending Async calls... + m_webClient.DownloadStringAsync(new Uri(url)); + } catch( Exception e ) + { + m_bLastUpdateFailed = true; + m_strLastUpdateError = e.Message; + } + } + + public void OnAsyncCompletedEventArgs(object sender, DownloadStringCompletedEventArgs e) + { + if (!e.Cancelled) + { + // Communication cancel for some reason, no valid data to be expected + if (e.Error != null) + { + // Handle error here + m_bLastUpdateFailed = true; + m_strLastUpdateError = e.Error.Message; + m_bScreenUpdateRequired = true; + } + else + { + ParseUpdateInfo(e.Result); + // ParseUpdateInfo(m_webClient.DownloadString(@"C:\Users\Bart\Documents\SharpDevelop Projects\VeraControl\testdata\text.xml")); + } + } + + // update timer again (took some time to get the data) + m_lLastUpdate = helper.getSecondsSince1970(); + m_bUpdatePending = false; + } + + public void ParseUpdateInfo(string veraresponse) + { var xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(verastatus); - + xmlDoc.LoadXml(veraresponse); + // Parse header XmlNode rootnode = xmlDoc.SelectSingleNode("/root"); - m_bMetric = (helper.getAttrAsString(rootnode, "temperature", "C") == "C"); - bool bFullRefresh = helper.getAttrAsBool (rootnode, "full", true); - m_sDataVersion = helper.getAttrAsString (rootnode, "dataversion", "0"); - m_sComment = helper.getAttrAsString (rootnode, "comment", ""); - m_dsVeraState = helper.toDevState(helper.getAttrAsInt(rootnode, "state", -1)); + if (rootnode == null) + { + // not a status update, just return (might have been an Asynchrone sent command or start scene request) + return; + } - if (bFullRefresh) + if (!m_bScreenUpdateRequired) { - // We have a full refresh -> Clear all lists + // Clear flag, only when previous update was already handled + m_status.system.clearFullReloadFlag(); + } + if (m_bLastUpdateFailed) + { + m_bLastUpdateFailed = false; + m_bScreenUpdateRequired = true; + m_status.system.clearConnectionError(); + } + // Process system status first + m_status.system.update(rootnode); + if (m_status.system.fullReload) + { + // We have a full refresh -> Clear all lists (to get clear of removed devices) TODO: check/handle selected index when an item was deleted... m_status.clearAllLists(); } @@ -278,6 +380,9 @@ } else { m_status.scenes.Add(new Scene(xn)); } + + // At least one scene was found and thus changed + m_bScreenUpdateRequired = true; } @@ -292,20 +397,24 @@ m_status.categories.Add(new DevCategories(xn)); } } - + // Process Devices xnList = xmlDoc.SelectNodes("/root/devices/device"); foreach (XmlNode xn in xnList) { DeviceGeneric dev = m_status.getDeviceById( int.Parse(xn.Attributes["id"].Value) ); if (dev.id != 0) { + // update existing device dev.update(xn); } else { + m_status.system.setFullReloadFlag(); + + // catids: http://wiki.micasaverde.com/index.php/Luup_UPNP_Files switch (xn.Attributes["category"].Value) { - //case "1": - // m_status.devices.Add(new DeviceInterface(xn)); - // break; + //case "1": // TODO: Implement interface device ? + // m_status.devices.Add(new DeviceInterface(xn)); + // break; case "2": m_status.devices.Add(new DeviceDimmer(xn)); @@ -321,13 +430,13 @@ m_status.devices.Add(new DeviceSecurity(xn)); break; - case "5": - m_status.devices.Add(new DeviceThermostat(xn, m_bMetric)); - break; + case "5": + m_status.devices.Add(new DeviceThermostat(xn, m_status.system.isMetric())); + break; case "6": m_status.devices.Add(new DeviceCam(xn)); - break; + break; case "7": m_status.devices.Add(new DeviceDoorlock(xn)); @@ -336,31 +445,50 @@ case "8": m_status.devices.Add(new DeviceWindowCovering(xn)); break; - - case "14": + + //case "9": + // m_status.devices.Add(new DeviceRemoteControl(xn)); + // break; + + //case "10": + // m_status.devices.Add(new DeviceIrTx(xn)); + // break; + + //case "13": + // m_status.devices.Add(new DeviceSerialPort(xn)); + // break + + case "14": m_status.devices.Add(new DeviceSceneController(xn)); - break; - - // case "15": // TODO: Implement AV device ? - // m_status.devices.Add(new DeviceSensor(xn)); - // break; - + break; + + // case "15": + // m_status.devices.Add(new DeviceAV(xn)); + // break; + case "16": m_status.devices.Add(new DeviceHumidity(xn)); break; case "17": - m_status.devices.Add(new DeviceTemperature(xn, m_bMetric)); + m_status.devices.Add(new DeviceTemperature(xn, m_status.system.isMetric())); break; - - case "18": + + case "18": m_status.devices.Add(new DeviceLightSensor(xn)); - break; - - case "21": + break; + + //case "19": + // m_status.devices.Add(new DeviceZwaveInt(xn)); + // break + //case "20": + // m_status.devices.Add(new DeviceInsteonInt(xn)); + // break + + case "21": m_status.devices.Add(new DevicePowerMeter(xn)); - break; - + break; + case "0": default: // Check for Google Weather Device @@ -380,80 +508,30 @@ break; } } + // At least one device was found and thus changes + m_bScreenUpdateRequired = true; } - // update timer again (took some time to get the data) - m_lLastUpdate = getSecondsSince1970(); - m_bUpdatePending = false; - return bFullRefresh; } - public string doVeraRequest( string param, bool pParseResult ) - { - string response = doVeraRequest( param ); - if (pParseResult) - { - response = parseVeraRespones(response); - } - return response; - } - - public bool isVeraAlive(string ip, string port) - { - string response = retrieveURL("http://" + ip + ":" + port + "/data_request?id=lu_alive&time="+DateTime.Now.Ticks); - - return (response == "OK"); - } - - public string doVeraRequest( string param ) - { - return retrieveURL("http://" + vera_Address + "/data_request" + param + "&time="+DateTime.Now.Ticks); - } - - private string retrieveURL( string url ) - { - using (var webClient = new System.Net.WebClient()) { - return webClient.DownloadString(url); - } - } - - - private string parseVeraRespones(string response) - { - if (response.StartsWith("ERROR:")) - { - return response; - } - if (response.Contains("<OK>OK</OK>")) - { - return "Ok"; - } - - return response; - } - - public long getSecondsSince1970() - { - return (DateTime.Now.Ticks / 10000000); - } - public long secondsSinceLastUpdate { - get { return (getSecondsSince1970() - m_lLastUpdate); } + get { return (helper.getSecondsSince1970() - m_lLastUpdate); } set { } } + /* public bool metric { get { return m_bMetric; } set { } } - + */ public List<Scene> scenes { get { return m_status.scenes; } set { } } - + public List<DeviceGeneric> devices { get { return m_status.devices; } @@ -478,6 +556,32 @@ set { } } + public bool lastUpdateFailed + { + get { return m_bLastUpdateFailed; } + set { m_bLastUpdateFailed = value; } + } + + public string lastUpdateError + { + get { return m_strLastUpdateError; } + set { } + } + + public bool newScreenUpdateWaitingAndClearFlag() + { + // Invoking this method will clear the update ready flag -> so caller need to handle the update + bool b = m_bScreenUpdateRequired; + m_bScreenUpdateRequired = false; + return b; + } + + public bool updatePending + { + get { return m_bUpdatePending; } + set { } + } + public VeraStatus status { get { return m_status; } @@ -490,6 +594,6 @@ set { } } } - - + + } Modified: trunk/plugins/VeraControl/VeraControl.cs =================================================================== --- trunk/plugins/VeraControl/VeraControl.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/VeraControl.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -4,8 +4,8 @@ * Date: 21-12-2011 * Time: 21:20 * - * Copyright: 2012 GPL - Bart Eversdijk - * MediaPort plugin - MicasaVerde (TM) Vera Controller + * Copyright: 2012 GPL - Bart Eversdijk + * MediaPort plugin - MicasaVerde (TM) Vera Controller * E-mail: ba...@ev... */ using System; @@ -31,9 +31,7 @@ [assembly: UsesSubsystem("MP.SkinEngine")] [assembly: UsesSubsystem("MP.Config")] -// TODO: support multiple Vera Box -// TODO: get all boxes for a specific user (http://sta1.mios.com/locator_json.php?username=<user>) -// TODO: support remote vera Boxes (http://fwd1.mios.com/<name>/<pass>/<serial>/data_request?...) +// TODO: support multiple Vera Box AND get all boxes for a specific user (http://sta1.mios.com/locator_json.php?username=<user>) AND support remote vera Boxes (http://fwd1.mios.com/<name>/<pass>/<serial>/data_request?...) namespace VeraControl { @@ -88,17 +86,19 @@ [SkinControl(60)] protected GUIButtonControl ActionButton = null; [SkinControl(70)] protected GUIToggleButtonControl ActionTriggerButton = null; - int PluginID = 1972; - VeraCommunication vera = VeraCommunication.Instance; - int iSelectedRoom = Int16.MaxValue; - int iSelectedCategory = Int16.MaxValue; - int iRefreshDelay = 5; - public Actiontrigger iLastAction = Actiontrigger.LAST_ACTIONTRIGGER; + [SkinControl(30)] protected GUIImage cmtImage = null; + [SkinControlAttribute(31)] protected GUILabelControl comment=null; - public bool enableSceneTrigger = false; - bool bLastUpdateFailed = false; + private int PluginID = 1972; + private VeraCommunication vera = VeraCommunication.Instance; + private int m_iSelectedRoom = Int16.MaxValue; + private int m_iSelectedCategory = Int16.MaxValue; + public Actiontrigger iLastAction = Actiontrigger.LAST_ACTIONTRIGGER; + private VeraHelper helper = new VeraHelper(); - private string titleTxt = "Micasa Verde - Vera control"; + public bool enableSceneTrigger = false; + private bool bLastUpdateFailed = false; + private string titleTxt = "Micasa Verde - Vera control"; public VeraControl() { @@ -191,26 +191,33 @@ public override bool Init() { - iSelectedRoom = Int16.MaxValue; - iSelectedCategory = Int16.MaxValue; + m_iSelectedRoom = Int16.MaxValue; + m_iSelectedCategory = Int16.MaxValue; using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) { - iRefreshDelay = int.Parse(xmlreader.GetValueAsString("veracontroller", "refreshdelay", "5")); enableSceneTrigger = xmlreader.GetValueAsBool("veracontroller", "enableSceneTrigger", false); } GUIWindowManager.OnNewAction += new OnActionHandler(OnNewAction); - + Player.PlayBackEnded += new Player.EndedHandler(g_Player_PlayBackEnded); Player.PlayBackStarted += new Player.StartedHandler(g_Player_PlayBackStarted); Player.PlayBackStopped += new Player.StoppedHandler(g_Player_PlayBackStopped); - // Handle MP start-up trigger - InitClass initClass = new InitClass(this); - Thread oThread = new Thread(new ThreadStart(initClass.runFirstUpdate)); - oThread.Start(); - + // Handle MP start-up trigger - do this is a different Thread to not block MP-start up + new Thread( () => { + vera.updateCurrentStatus(DateTime.Now.Ticks); + // Run startup trigger after first update + if (enableSceneTrigger) + { + while (vera.updatePending) + { + Thread.Sleep(1000); + } + handleActionTriggers(Actiontrigger.MP_START_UP); + } + }).Start(); return Load(GUIGraphicsContext.Skin+@"\VeraControl.xml"); } @@ -269,6 +276,13 @@ } break; + case Action.ActionType.ACTION_CONTEXT_MENU: + if (GUIWindowManager.ActiveWindow == GetWindowId()) + { + showInfoDialog(); + } + break; + case Action.ActionType.ACTION_EXIT: handleActionTriggers(Actiontrigger.MP_EXIT); break; @@ -458,84 +472,150 @@ } } - public override void Render(float timePassed) { - if (vera.secondsSinceLastUpdate > iRefreshDelay) + // Give a message to the user a update failed + if (vera.lastUpdateFailed) { - refreshNow(); + // Show message only once! + if (!bLastUpdateFailed) + { + if (vera.status.system.dataversion == "0") + { // Give message on never connected... + new Thread (() => { NoConnection(vera.lastUpdateError);}).Start(); + } else { + vera.status.system.reportConnectionError(vera.lastUpdateError); + } + } + bLastUpdateFailed = true; } + else + { // Reset failed flag again + bLastUpdateFailed = false; + } + + // vera will only update when realy required + vera.updateCurrentStatus((long)timePassed); + refreshNow(); + base.Render(timePassed); - } public void refreshNow() { - if (updateNow()) + if (vera.newScreenUpdateWaitingAndClearFlag()) { + // update system status + if (vera.status.system.newScreenUpdateWaitingAndClearFlag()) + { + setSystemStatus(); + } + // update device status - if (iSelectedRoom != Int16.MaxValue) + if (m_iSelectedRoom != Int16.MaxValue) { foreach (GUIListItem item in RightList.ListItems) { DeviceGeneric dev = vera.status.getDeviceById( item.ItemId ); - item.Label2 = dev.getStatusText(); - - //Adjust color of item when option is turned off - item.IsPlayed = !dev.isControllable; - - item.IconImage = "Vera\\"+dev.getIconName()+".png"; - item.IconImageBig = "Vera\\"+dev.getIconName()+".png"; - item.ThumbnailImage = "Vera\\"+dev.getIconName()+".png"; - - Utils.SetDefaultIcons(item); + if (dev.newScreenUpdateWaitingAndClearFlag()) + { + item.Label2 = dev.getStatusText(); + item.PinImage = helper.getStateImage(dev.commstate); + + //Adjust color of item when option is turned off + item.IsPlayed = !dev.isControllable; + + item.IconImage = "Vera\\"+dev.getIconName()+".png"; + item.IconImageBig = "Vera\\"+dev.getIconName()+".png"; + item.ThumbnailImage = "Vera\\"+dev.getIconName()+".png"; + + Utils.SetDefaultIcons(item); + } } } + else + { + foreach(GUIListItem item in RightList.ListItems) + { + Scene scene = vera.status.getSceneById( item.ItemId ); + if (scene.newScreenUpdateWaitingAndClearFlag()) + { + item.Label2 = (scene.room == 0 ? "" : vera.status.getRoomById(scene.room).name); + item.PinImage = helper.getStateImage(scene.commstate); + item.IsPlayed = scene.isActive(); + Utils.SetDefaultIcons(item); + } + } + } } } protected override void OnPageLoad() { - updateNow(); + if (m_iSelectedCategory == 0) { m_iSelectedCategory = Int16.MaxValue; } - if (iSelectedCategory == 0) { iSelectedCategory = Int16.MaxValue; } - listCategories(); - listRooms(iSelectedCategory); - listScenes(); - - // Set Current Selected Item - LeftList.SelectedListItemIndex = 0; + listRooms(m_iSelectedCategory, m_iSelectedRoom); + if (m_iSelectedRoom == Int16.MaxValue) { + listScenes(); + } else { + listDevices(m_iSelectedRoom); + } + // Disable Page control (for left list) + LeftList.SetPageControlVisible( false ); + + setSystemStatus(); + refreshNow(); updateSceneTrigger(); base.OnPageLoad(); } + + private void setSystemStatus() + { + if (vera.status.system.state != DevState.NONE) { + cmtImage.Dispose(); + cmtImage.SetFileName(helper.getStateImage(vera.status.system.state)); + cmtImage.KeepAspectRatio = true; + cmtImage.Visibility = System.Windows.Visibility.Visible; + cmtImage.AllocResources(); + } else{ + cmtImage.Visibility = System.Windows.Visibility.Hidden; + } + comment.Label = vera.status.system.comment; + + } private void listCategories() { + int iCnt = 1; + int iSelected = 0; GUIControl.ClearControl(GetID, catList.GetID); catList.AddSpinLabel("All", Int16.MaxValue); - // Fill in scene for default foreach( Section sec in vera.sections ) { catList.AddSpinLabel(sec.name, sec.id); - + iCnt++; + if (m_iSelectedCategory == sec.id) + { + iSelected = iCnt; + } } - catList.SelectedItem = iSelectedCategory; + catList.SelectedItem = iSelected; } private void listScenes() { GUIControl.ClearControl(GetID, RightList.GetID); - // Fill in scene for default foreach( Scene scene in vera.scenes ) { GUIListItem item = new GUIListItem(scene.name); - item.Label2 = vera.status.getRoomById(scene.room).name; + item.Label2 = (scene.room == 0 ? "" : vera.status.getRoomById(scene.room).name); + item.PinImage = helper.getStateImage(scene.commstate); item.IsPlayed = scene.isActive(); item.ItemId = scene.id; @@ -545,7 +625,6 @@ Utils.SetDefaultIcons(item); RightList.Add(item); - } GUIControl.FocusControl(GetID, LeftList.GetID); @@ -555,8 +634,10 @@ title.Label = titleTxt + " - Scenes"; } - private void listRooms(int iShowSection) + private void listRooms(int iShowSection, int iSelectedRoom) { + int iCnt = 0; + int iSelected = 0; // --- fill in left lisft with rooms and scene item GUIControl.ClearControl(GetID, LeftList.GetID); GUIListItem sceneitem = new GUIListItem("Scenes"); @@ -583,9 +664,16 @@ Utils.SetDefaultIcons(item); LeftList.Add(item); + + iCnt++; + if (iSelectedRoom == room.id) + { + iSelected = iCnt; + } } } - + // Set Current Selected Item + LeftList.SelectedListItemIndex = iSelected; } private void listDevices(int iShowRoom) @@ -599,6 +687,7 @@ { GUIListItem item = new GUIListItem(dev.name); item.Label2 = dev.getStatusText(); + item.PinImage = helper.getStateImage(dev.commstate); //Adjust color of item when option is turned off item.IsPlayed = !dev.isControllable; @@ -624,11 +713,11 @@ private void OnLeftlistCrtl(GUIListControl control) { - iSelectedRoom = control.SelectedListItem.ItemId; + m_iSelectedRoom = control.SelectedListItem.ItemId; GUIAnimation.HideControl(GetID, RightList.GetID); - if (iSelectedRoom == Int16.MaxValue) + if (m_iSelectedRoom == Int16.MaxValue) { // Selected room is Int16.MaxValue which mean we need to have scenes in our list listScenes(); @@ -636,7 +725,7 @@ else { // Selected room != Int16.MaxValue which mean we need to have devices of a certain room in our list - listDevices(iSelectedRoom); + listDevices(m_iSelectedRoom); } GUIAnimation.ShowControl(GetID, RightList.GetID); @@ -645,33 +734,24 @@ private void OnCategoryList(GUISpinButton control) { if (control.SpinValue > 0) { - iSelectedCategory = vera.sections[control.SpinValue-1].id; + m_iSelectedCategory = vera.sections[control.SpinValue-1].id; } else { - iSelectedCategory = Int16.MaxValue; + m_iSelectedCategory = Int16.MaxValue; } - if (iSelectedCategory == 0 ) { iSelectedCategory = Int16.MaxValue; } - listRooms( iSelectedCategory ); - iSelectedRoom = Int16.MaxValue; + if (m_iSelectedCategory == 0 ) { m_iSelectedCategory = Int16.MaxValue; } + m_iSelectedRoom = Int16.MaxValue; + listRooms( m_iSelectedCategory, m_iSelectedRoom ); listScenes(); } private void OnRightlistCrtl(GUIListControl control) { - if (iSelectedRoom == Int16.MaxValue) + if (m_iSelectedRoom == Int16.MaxValue) { // Selected room is 0 which mean we have scenes in our list Scene scene = vera.status.getSceneById(control.SelectedListItem.ItemId); - - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading("Scene has been pressed"); - - if (scene.id != 0) { - scene.run(); - dlg.SetLine(1, "Scene '" + scene.name + "' executed"); - } else { - dlg.SetLine(1, "Scene id not found: " + control.SelectedListItem.ItemId.ToString()); - } - dlg.SetLine(2, String.Empty); - dlg.SetLine(3, String.Empty); + + DialogSceneControl dlg = (DialogSceneControl)GUIWindowManager.GetWindow((int)1975); + dlg.InitDialog("Scene control", scene); dlg.DoModal(GUIWindowManager.ActiveWindow); } else @@ -680,39 +760,6 @@ DeviceGeneric dev = vera.status.getDeviceById(control.SelectedListItem.ItemId); DialogDeviceControl dlg = (DialogDeviceControl)GUIWindowManager.GetWindow((int)1973); dlg.InitDialog(vera.status.getRoomById(dev.room).name, dev); - dlg.SetImage("Vera\\"+dev.getIconName()+".png"); - - if (dev.isControllable) - { - if (dev.GetType() == typeof(DeviceSprinkler)) - { - dlg.SetText(dev.name, dev.getStatusText() + " - " + dev.mode, dev.getExtraText() ); - dlg.SetActiveBut((dev.status ? 1 : 0), (dev.mode == "Auto" ? 0 : (dev.mode == "Block" ? 2 : 1) )); - } - else if (dev.GetType() == typeof(DeviceThermostat)) - { - dlg.SetText(dev.name, dev.getStatusText(), dev.getExtraText() ); - dlg.SetActiveBut((dev.status ? 1 : 0), (dev.mode == "Auto" ? 0 : - (dev.mode == "CoolOn" || dev.mode == "Cool" ? 1 : - (dev.mode == "HeatOn" || dev.mode == "Heat" ? 2 : 3) ))); - } - else - { - dlg.SetText(dev.name, "", ""); - dlg.SetActiveBut(dev.status ? 1 : 0, -1); - } - dlg.SetButtons(dev.getCommands()); - dlg.SetSlider(dev.level, dev.maxLevel); - } - else - { - if (dev.GetType() == typeof(DeviceCam)) - { - DeviceCam cam = (DeviceCam) dev; - dlg.SetCamImage(cam.imgUrl); - } - dlg.SetText(dev.name, dev.getStatusText(), dev.getExtraText()); - } dlg.DoModal(GUIWindowManager.ActiveWindow); // Update list after closure @@ -744,34 +791,37 @@ { ActionButton.IsVisible = enableSceneTrigger; ActionTriggerButton.Selected = enableSceneTrigger; - if (enableSceneTrigger) + if (enableSceneTrigger) { - LeftList.NavigateLeft = 60; - RightList.NavigateRight = 60; + LeftList.NavigateLeft = 60; + RightList.NavigateRight = 60; } else { - LeftList.NavigateLeft = 50; - RightList.NavigateRight = 40; + LeftList.NavigateLeft = 50; + RightList.NavigateRight = 40; } } - public bool updateNow() + private void showInfoDialog() { - try { - bool result = vera.updateCurrentStatus(); - bLastUpdateFailed = false; - return result; - } catch(Exception e) + GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); + if (dlg != null) { - if (!bLastUpdateFailed) - { - NoConnection(e.ToString()); - } - bLastUpdateFailed = false; - return false; + dlg.Reset(); + dlg.SetHeading("VeraBox - " + vera.status.system.serialno); + dlg.SetText ("version : " + vera.status.system.versionInfo +"\n" + + "addres : " + vera.vera_Address +"\n" + + "healed : " + (vera.status.system.bZWaveHeal ? "yes" : "no") +"\n" + + "units : " + (vera.status.system.isMetric() ? "metric" : "imperial") +"\n" + + "fwd1 : " + vera.status.system.fwd +"\n" + + "fwd2 : " + vera.status.system.fwdBackup + "\n" + "\n" + + "comment : " + (vera.status.system.comment == "" ? "-": vera.status.system.comment)); + + dlg.DoModal(GUIWindowManager.ActiveWindow); } } + private void NoConnection(string err) { GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); @@ -779,28 +829,11 @@ { dlg.Reset(); dlg.SetHeading("Error !!!"); - dlg.SetText ("Micasa Verde Vera 2 Box not found @ " + vera.vera_Address +"\n" + - "Check the plug-in cofiguration. \n\n Error message: \n" + err); + dlg.SetText ("MicasaVerde Vera 2 Box not found @ " + vera.vera_Address +"\n" + + "Check the plug-in configuration.\n\nError message: \n" + err); dlg.DoModal(GUIWindowManager.ActiveWindow); } } } - - public class InitClass - { - VeraControl _vc = null; - public InitClass(VeraControl vc) - { - _vc = vc; - } - public void runFirstUpdate() - { - _vc.updateNow(); - // Handle MP start-up trigger - _vc.handleActionTriggers(Actiontrigger.MP_START_UP); - } - } - - } \ No newline at end of file Modified: trunk/plugins/VeraControl/VeraControl.csproj =================================================================== --- trunk/plugins/VeraControl/VeraControl.csproj 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/VeraControl.csproj 2012-01-15 23:50:18 UTC (rev 4405) @@ -96,11 +96,13 @@ <Compile Include="DeviceSecurity.cs" /> <Compile Include="DeviceSprinkler.cs" /> <Compile Include="DeviceSwitch.cs" /> + <Compile Include="DeviceSystem.cs" /> <Compile Include="DeviceTemperature.cs" /> <Compile Include="DeviceThermostat.cs" /> <Compile Include="DeviceWindowCovering.cs" /> <Compile Include="DialogActionTrigger.cs" /> <Compile Include="DialogDeviceControl.cs" /> + <Compile Include="DialogSceneControl.cs" /> <Compile Include="VeraControl.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Room.cs" /> Modified: trunk/plugins/VeraControl/VeraHelper.cs =================================================================== --- trunk/plugins/VeraControl/VeraHelper.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/VeraHelper.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -19,7 +19,9 @@ NONE = 0, PENDING, SUCCESS, - ERROR + ERROR, + + CONNECTION_ERROR // not a Vera state } /// <summary> @@ -73,6 +75,29 @@ } } + public string getStateImage( DevState state ) + { + switch(state) + { + case DevState.PENDING: + return "remote_blue.png"; + + case DevState.SUCCESS: + return "remote_green.png"; + + case DevState.ERROR: + return "tvguide_recordconflict_button.png"; + + case DevState.CONNECTION_ERROR: + return "warning-icon.png"; + + default: + case DevState.NONE: + return ""; + + } + } + public int getAttrAsInt(XmlNode xn, string key, int iDefault) { if (xn == null || xn.Attributes[key] == null) @@ -100,5 +125,10 @@ } return xn.Attributes[key].Value; } + + public long getSecondsSince1970() + { + return (DateTime.Now.Ticks / 10000000); + } } } Modified: trunk/plugins/VeraControl/VeraSetupForm.Designer.cs =================================================================== --- trunk/plugins/VeraControl/VeraSetupForm.Designer.cs 2012-01-14 17:51:27 UTC (rev 4404) +++ trunk/plugins/VeraControl/VeraSetupForm.Designer.cs 2012-01-15 23:50:18 UTC (rev 4405) @@ -37,10 +37,10 @@ this.CheckConnection = new System.Windows.Forms.Button(); this.labelPortNumber = new System.Windows.Forms.Label(); this.portnumber = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); this.refreshdelay = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.enableSceneTrigger = new System.Windows.Forms.CheckBox(); + this.label1 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); @@ -141,26 +141,17 @@ this.portnumber.TabIndex = 2; this.portnumber.Text = "3480"; // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(17, 24); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(117, 13); - this.label1.TabIndex = 7; - this.label1.Text = "Refresh status delay (s)"; - // // refreshdelay // this.refreshdelay.AcceptsTab = true; this.refreshdelay.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Win... [truncated message content] |