From: <Ba...@us...> - 2012-01-23 23:04:54
|
Revision: 4424 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4424&view=rev Author: BartEv Date: 2012-01-23 23:04:46 +0000 (Mon, 23 Jan 2012) Log Message: ----------- Scene and device update improved Modified Paths: -------------- trunk/plugins/VeraControl/BaseDevice.cs trunk/plugins/VeraControl/DeviceCam.cs trunk/plugins/VeraControl/DeviceGeneric.cs trunk/plugins/VeraControl/Scene.cs trunk/plugins/VeraControl/VeraCommunication.cs trunk/plugins/VeraControl/VeraControl.cs Modified: trunk/plugins/VeraControl/BaseDevice.cs =================================================================== --- trunk/plugins/VeraControl/BaseDevice.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/BaseDevice.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -13,142 +13,170 @@ namespace VeraControl.Properties { - /// <summary> - /// Description of BaseDevice. - /// </summary> - public class BaseDevice - { - public long _lastUpdate = 0; - public long _lastPendingUpdate = 0; - public bool _screenUpdateRequired = false; - private string _name = "unknown device"; - private int _id = 0; - private int _room = 0; - - // not connected (-2), none (-1), pending (0,1,5,6), success(4), error (2,3) - private DevState _dsState = DevState.NONE; - private string _comment = ""; // red(error), green(success) or blue(pending) - icon/text - - public VeraHelper _helper = VeraHelper.Instance; - public VeraCommunication _vera = VeraCommunication.Instance; - - public BaseDevice(XmlNode xn) - { - if (xn != null) - { - Update(xn); - } - } - - /// <summary> - /// Process Vera update information - /// </summary> - public virtual bool Update(XmlNode xn) - { - _name = _helper.GetAttrAsString(xn, "name", _name); - _id = _helper.GetAttrAsInt (xn, "id", _id); - _room = _helper.GetAttrAsInt (xn, "room", _room); - - string tempComment = _helper.GetAttrAsString(xn, "comment", _comment ); - DevState tempDsState = _helper.ToDevState(_helper.GetAttrAsInt(xn, "state", -1)); - if (_dsState != DevState.PENDING || tempDsState != DevState.NONE || (tempDsState == DevState.NONE && ((_lastPendingUpdate / TimeSpan.TicksPerSecond ) < (DateTime.Now.Ticks / TimeSpan.TicksPerSecond)))) - { // If state was set to pending next update should contain a new state or still pending - so do not clear pending flag for at least 10 seconds - _comment = tempComment; - _dsState = tempDsState; - } - if (_id == 0) - { - // void device no further processing needed - return false; - } - - // Set update flag - _screenUpdateRequired = true; - _lastUpdate = DateTime.Now.Ticks; - return true; - } - - public int id - { - get { return _id; } - set { } - } - - public string name - { - get { return _name; } - set { } - } + /// <summary> + /// Description of BaseDevice. + /// </summary> + public class BaseDevice + { + private long _lastUpdate = 0; + private long _lastPendingUpdate = 0; + private bool _screenUpdateRequired = false; + private string _name = "unknown device"; + private int _id = 0; + private int _room = 0; + + // not connected (-2), none (-1), pending (0,1,5,6), success(4), error (2,3) + private DevState _dsState = DevState.NONE; + private string _comment = ""; // red(error), green(success) or blue(pending) - icon/text + + public VeraHelper _helper = VeraHelper.Instance; + public VeraCommunication _vera = VeraCommunication.Instance; + + public BaseDevice(XmlNode xn) + { + if (xn != null) + { + Update(xn); + } + } + + /// <summary> + /// Process Vera update information + /// </summary> + public virtual bool Update(XmlNode xn) + { + _name = _helper.GetAttrAsString(xn, "name", _name); + _id = _helper.GetAttrAsInt (xn, "id", _id); + _room = _helper.GetAttrAsInt (xn, "room", _room); + _comment = _helper.GetAttrAsString(xn, "comment", _comment ); + _dsState = _helper.ToDevState(_helper.GetAttrAsInt(xn, "state", -1)); + + if (_id == 0) + { + // void device no further processing needed + return false; + } + + // Set update flag + screenUpdateRequired = true; + lastUpdate = DateTime.Now.Ticks; + return true; + } + + public virtual string GetIconName() + { + return ""; + } + + public virtual string GetStatusText() + { + return ""; + } + + public int id + { + get { return _id; } + set { } + } + + public string name + { + get { return _name; } + set { } + } - public bool InRoom(int id) - { - return (_room == id); - } - - public int room - { - get { return _room; } - set { _room = value; } - } - - public DevState commstate - { - get { return _dsState; } - set { } - } - - public string comment - { - get { return (commstate != DevState.NONE ? _comment : ""); } - set { } - } - - public void ReportPendingRequest() - { - _dsState = DevState.PENDING; - _comment = "Sending command..."; - _screenUpdateRequired = true; - _lastUpdate = DateTime.Now.Ticks; - _lastPendingUpdate = _lastUpdate; - } - - /// <summary> - /// Callback function for Ansync Web Client call on to report errors... - /// </summary> - public void ReportRequestError(string message) - { - _dsState = DevState.COMMAND_ERROR; - _comment = message; - _screenUpdateRequired = true; - _lastUpdate = DateTime.Now.Ticks; - } - - public void ClearCommState() - { - _dsState = DevState.NONE; - } - - /// <summary> - /// True when an update was processed after the give time stamp - /// </summary> - public virtual bool NewUpdateSince(long timePreviousCheck) - { - return (timePreviousCheck <= _lastUpdate); - } - - /// <summary> - /// Invoking this method will clear the update ready flag -> so caller need to handle the screen update - /// </summary> - public virtual bool NewScreenUpdateWaitingAndClearFlag() - { - bool b = _screenUpdateRequired; - _screenUpdateRequired = false; - return b; - } - - public override string ToString() - { - return name; - } - } + public bool InRoom(int id) + { + return (_room == id); + } + + public int room + { + get { return _room; } + set { _room = value; } + } + + public DevState commstate + { + get { return _dsState; } + set { } + } + + public string comment + { + get { return (commstate != DevState.NONE ? _comment : ""); } + set { } + } + + public bool screenUpdateRequired + { + get { return _screenUpdateRequired; } + set { + if (value) + { // If at least one device report screen update required, Vera should take over this report + _vera.setScreenUpdateRequired(); + } + _screenUpdateRequired = value; + } + } + + public long lastUpdate + { + get { return _lastUpdate; } + set { _lastUpdate = value; } + } + + public void ReportPendingRequest() + { + _dsState = DevState.PENDING; + _comment = "Sending command..."; + screenUpdateRequired = true; + lastUpdate = DateTime.Now.Ticks; + _lastPendingUpdate = lastUpdate; + } + + /// <summary> + /// Callback function for Ansync Web Client call on to report errors... + /// </summary> + public void ReportRequestError(string message) + { + _dsState = DevState.COMMAND_ERROR; + _comment = message; + screenUpdateRequired = true; + lastUpdate = DateTime.Now.Ticks; + } + + public void ClearCommState() + { + if (_dsState != DevState.NONE) + { + _dsState = DevState.NONE; + screenUpdateRequired = true; + lastUpdate = DateTime.Now.Ticks; + } + } + + /// <summary> + /// True when an update was processed after the give time stamp + /// </summary> + public virtual bool NewUpdateSince(long timePreviousCheck) + { + return (timePreviousCheck <= lastUpdate); + } + + /// <summary> + /// Invoking this method will clear the update ready flag -> so caller need to handle the screen update + /// </summary> + public virtual bool NewScreenUpdateWaitingAndClearFlag() + { + bool b = screenUpdateRequired; + screenUpdateRequired = false; + return b; + } + + public override string ToString() + { + return name; + } + } } Modified: trunk/plugins/VeraControl/DeviceCam.cs =================================================================== --- trunk/plugins/VeraControl/DeviceCam.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/DeviceCam.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -90,21 +90,21 @@ { // 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 = _screenUpdateRequired || HasRefreshDelayPassed(DateTime.Now.Ticks); - _screenUpdateRequired = false; + bool b = screenUpdateRequired || HasRefreshDelayPassed(DateTime.Now.Ticks); + screenUpdateRequired = false; if (b) { - _lastUpdate = DateTime.Now.Ticks; + lastUpdate = DateTime.Now.Ticks; } return b; } public override bool NewUpdateSince(long lTimePreviousCheck) { - bool b = (lTimePreviousCheck <= _lastUpdate) || HasRefreshDelayPassed(_lastUpdate); + bool b = (lTimePreviousCheck <= lastUpdate) || HasRefreshDelayPassed(lastUpdate); if (b) { - _lastUpdate = DateTime.Now.Ticks; + lastUpdate = DateTime.Now.Ticks; } return b; } @@ -114,7 +114,7 @@ if (id == 0) { _vera.status.system.ReportCommandError("Unknown device"); - _screenUpdateRequired = true; + screenUpdateRequired = true; return; } string cmd = "?id=lu_action&DeviceNum=" + id + "&serviceId=urn:micasaverde-com:serviceId:PanTiltZoom1&action=" + direction; Modified: trunk/plugins/VeraControl/DeviceGeneric.cs =================================================================== --- trunk/plugins/VeraControl/DeviceGeneric.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/DeviceGeneric.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -96,12 +96,12 @@ set { } } - public virtual string GetIconName() + public override string GetIconName() { return "generic_sensor"; } - public virtual string GetStatusText() + public override string GetStatusText() { return ""; } Modified: trunk/plugins/VeraControl/Scene.cs =================================================================== --- trunk/plugins/VeraControl/Scene.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/Scene.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -14,62 +14,60 @@ namespace VeraControl.Properties { - /// <summary> - /// Description of Scene. - /// </summary> - public class Scene : BaseDevice - { - public Scene(XmlNode xn) : base (xn) - { - if (xn != null) - { - Update(xn); - } - } - - private bool _active = false; - - public override bool Update(XmlNode xn) - { - _active = _helper.GetAttrAsBool(xn, "active", _active); - bool b = base.Update(xn); - - // Make sure the room exists or else make it 0 - if (room != 0 && !_vera.status.IsRoomFound(room)) - { - room = 0; - } - return b; - } - - public bool IsActive() - { - return _active; - } + /// <summary> + /// Description of Scene. + /// </summary> + public class Scene : BaseDevice + { + public Scene(XmlNode xn) : base (xn) + { + if (xn != null) + { + Update(xn); + } + } + + private bool _active = false; + + public override bool Update(XmlNode xn) + { + _active = _helper.GetAttrAsBool(xn, "active", _active); + bool b = base.Update(xn); + + // Make sure the room exists or else make it 0 + if (room != 0 && !_vera.status.IsRoomFound(room)) + { + room = 0; + } + return b; + } + + public override string GetIconName() + { + return "Scenes"; + } + + public override string GetStatusText() + { + return (room == 0 ? "" : _vera.status.GetRoomById(room).name); + } + + public bool IsActive() + { + return _active; + } - public void Run() - { - if (id == 0) - { - _vera.status.system.ReportCommandError("Unknown scene"); - _screenUpdateRequired = true; - return; - } - ReportPendingRequest(); - string cmd = "?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="+id; - _vera.DoVeraCommandRequest(cmd, ReportRequestError); - } - - public override bool NewScreenUpdateWaitingAndClearFlag( ) - { - // Scenes are not reported Done by Vera so the will time out... - bool b = base.NewScreenUpdateWaitingAndClearFlag(); - if (commstate != DevState.NONE && (_lastUpdate < (DateTime.Now.Ticks - (10 * 10000000)))) - { - ClearCommState(); - return true; - } - return b; - } - } + public void Run() + { + if (id == 0) + { + _vera.status.system.ReportCommandError("Unknown scene"); + screenUpdateRequired = true; + return; + } + ReportPendingRequest(); + string cmd = "?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="+id; + _vera.DoVeraCommandRequest(cmd, ReportRequestError); + } + } } Modified: trunk/plugins/VeraControl/VeraCommunication.cs =================================================================== --- trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/VeraCommunication.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -23,12 +23,12 @@ 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>(); - public List<DevCategories> categories = new List<DevCategories>(); - public List<Section> sections = new List<Section>(); + 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>(); + public List<DevCategories> categories = new List<DevCategories>(); + public List<Section> sections = new List<Section>(); #region Vers get by id support functions @@ -165,14 +165,14 @@ public sealed class VeraCommunication { - private static volatile VeraCommunication _instance; + private static volatile VeraCommunication _instance; private static object _syncRoot = new Object(); private VeraHelper _helper = VeraHelper.Instance; // Config data private string _veraIPAddress; private string _veraTCPIPPort; - private int _maxRefreshDelay; // Maximun delay between 2 status updates in seconds + private int _maxRefreshDelay; // Maximun delay between 2 status updates in seconds private int _minRefreshDelay = 1000; // Minimun delay between 2 status updates in miliseconds // Actual device information @@ -266,7 +266,7 @@ { _webCommandClientErrorReporter = null; status.system.ReportCommandError(e.Message); - _screenUpdateRequired = true; + setScreenUpdateRequired(); } } @@ -285,7 +285,7 @@ // Show eror in MediaPortal Vera-main window status.system.ReportCommandError("Request was canceled"); } - _screenUpdateRequired = true; + setScreenUpdateRequired(); } else if (e.Error != null) { @@ -300,7 +300,7 @@ // Show eror in MediaPortal Vera-main window status.system.ReportCommandError(e.Error.Message); } - _screenUpdateRequired = true; + setScreenUpdateRequired(); } else { @@ -317,7 +317,7 @@ // Show eror in MediaPortal Vera-main window status.system.ReportCommandError(e.Result); } - _screenUpdateRequired = true; + setScreenUpdateRequired(); } } // Communication done clear error report handler @@ -358,9 +358,9 @@ if (e.Error != null) { // Handle error here - _lastUpdateFailed = true; + _lastUpdateFailed = true; _lastUpdateErrorMessage = e.Error.Message; - _screenUpdateRequired = true; + setScreenUpdateRequired(); } else { @@ -399,7 +399,7 @@ if (_lastUpdateFailed) { _lastUpdateFailed = false; - _screenUpdateRequired = true; + setScreenUpdateRequired(); _status.system.ClearConnectionError(); } // Process system status first @@ -436,6 +436,12 @@ // Process Scenes xnList = xmlDoc.SelectNodes("/root/scenes/scene"); + // State update of Scenes are not reported done, so they have to be cleaned manualy + // if a message is still valid and/or new message will be reported below + foreach (Scene scene in _status.scenes) + { + scene.ClearCommState(); + } foreach (XmlNode xn in xnList) { Scene sc = _status.GetSceneById( int.Parse(xn.Attributes["id"].Value) ); @@ -444,9 +450,6 @@ } else { _status.scenes.Add(new Scene(xn)); } - - // At least one scene was found and thus screen update required - _screenUpdateRequired = true; } // Process Categories @@ -571,8 +574,6 @@ break; } } - // At least one device update/new was found and thus screen update required - _screenUpdateRequired = true; } } @@ -635,6 +636,10 @@ return b; } + public void setScreenUpdateRequired() + { + _screenUpdateRequired = true; + } /// <summary> /// A request is currently being handled by Vera, this request takes at least _minRefreshDelay msecs, at most _maxRefreshDelay seconds and will be finished the moment Vera detects a change. /// As soon as this function returns false a new update request should be invoked (with UpdateCurrentStatus()), Vera will take care of the Refresh delays (by keeping open the http-connection) Modified: trunk/plugins/VeraControl/VeraControl.cs =================================================================== --- trunk/plugins/VeraControl/VeraControl.cs 2012-01-21 23:46:35 UTC (rev 4423) +++ trunk/plugins/VeraControl/VeraControl.cs 2012-01-23 23:04:46 UTC (rev 4424) @@ -35,212 +35,216 @@ namespace VeraControl { - public enum Actiontrigger - { - MUSIC_START_PLAYING = 0, - MUSIC_PAUSED, - MUSIC_PAUSE_RESUMED, - MUSIC_STOPPED, - - VIDEO_START_PLAYING, - VIDEO_PAUSED, - VIDEO_PAUSE_RESUMED, - VIDEO_STOPPED, - - TV_START_PLAYING, - TV_PAUSED, - TV_PAUSE_RESUMED, - TV_STOPPED, - - RECORDING_START_PLAYING, - RECORDING_PAUSED, - RECORDING_PAUSE_RESUMED, - RECORDING_STOPPED, - - RADIO_START_PLAYING, - RADIO_PAUSED, - RADIO_PAUSE_RESUMED, - RADIO_STOPPED, - - UNKNOWN_START_PLAYING, - UNKNOWN_PAUSED, - UNKNOWN_PAUSE_RESUMED, - UNKNOWN_STOPPED, - - MP_START_UP, - MP_SHUTDOWN, - MP_EXIT, - - LAST_ACTIONTRIGGER - }; - - /// <summary> - /// Description of VeraControl. - /// </summary> - public class VeraControl : GUIInternalWindow, ISetupForm - { - [SkinControlAttribute(10)] protected GUILabelControl _title = null; - [SkinControl(20)] protected GUISpinButton _catList = null; - [SkinControl(40)] protected GUIListControl _leftList = null; - [SkinControl(50)] protected GUIListControl _rightList = null; - [SkinControl(60)] protected GUIButtonControl _actionButton = null; - [SkinControl(70)] protected GUIToggleButtonControl _actionTriggerButton = null; - - [SkinControl(30)] protected GUIImage _cmtImage = null; - [SkinControlAttribute(31)] protected GUILabelControl _comment = null; - - private int _pluginID = 1972; - private VeraCommunication _vera = VeraCommunication.Instance; - private int _selectedRoom = Int16.MaxValue; - private int _selectedCategory = Int16.MaxValue; - public Actiontrigger _lastAction = Actiontrigger.LAST_ACTIONTRIGGER; - private VeraHelper _helper = new VeraHelper(); - - public bool _enableSceneTrigger = false; - private bool _lastUpdateFailed = false; - private string _titleTxt = "Micasa Verde - Vera control"; - - public VeraControl() - { - } + public enum Actiontrigger + { + MUSIC_START_PLAYING = 0, + MUSIC_PAUSED, + MUSIC_PAUSE_RESUMED, + MUSIC_STOPPED, + + VIDEO_START_PLAYING, + VIDEO_PAUSED, + VIDEO_PAUSE_RESUMED, + VIDEO_STOPPED, + + TV_START_PLAYING, + TV_PAUSED, + TV_PAUSE_RESUMED, + TV_STOPPED, + + RECORDING_START_PLAYING, + RECORDING_PAUSED, + RECORDING_PAUSE_RESUMED, + RECORDING_STOPPED, + + RADIO_START_PLAYING, + RADIO_PAUSED, + RADIO_PAUSE_RESUMED, + RADIO_STOPPED, + + UNKNOWN_START_PLAYING, + UNKNOWN_PAUSED, + UNKNOWN_PAUSE_RESUMED, + UNKNOWN_STOPPED, + + MP_START_UP, + MP_SHUTDOWN, + MP_EXIT, + + LAST_ACTIONTRIGGER + }; + + /// <summary> + /// Description of VeraControl. + /// </summary> + public class VeraControl : GUIInternalWindow, ISetupForm + { + [SkinControlAttribute(10)] protected GUILabelControl _title = null; + [SkinControl(20)] protected GUISpinButton _catList = null; + [SkinControl(40)] protected GUIListControl _leftList = null; + [SkinControl(50)] protected GUIListControl _rightList = null; + [SkinControl(60)] protected GUIButtonControl _actionButton = null; + [SkinControl(70)] protected GUIToggleButtonControl _actionTriggerButton = null; + + [SkinControl(30)] protected GUIImage _cmtImage = null; + [SkinControlAttribute(31)] protected GUILabelControl _comment = null; + + const int ALL = Int16.MaxValue; + const int NO_SCENE_SELECTED = Int16.MaxValue; + + + private int _pluginID = 1972; + private VeraCommunication _vera = VeraCommunication.Instance; + private int _selectedRoom = ALL; + private int _selectedCategory = ALL; + public Actiontrigger _lastAction = Actiontrigger.LAST_ACTIONTRIGGER; + private VeraHelper _helper = new VeraHelper(); + + public bool _enableSceneTrigger = false; + private bool _lastUpdateFailed = false; + private string _titleTxt = "Micasa Verde - Vera control"; + + public VeraControl() + { + } - #region ISetupForm Members + #region ISetupForm Members - // Returns the name of the plugin which is shown in the plugin menu - public string PluginName() - { - return "Vera Controller"; - } + // Returns the name of the plugin which is shown in the plugin menu + public string PluginName() + { + return "Vera Controller"; + } - // Returns the description of the plugin is shown in the plugin menu - public string Description() - { - return "Micasa Verde Vera 2 controller, let Media Portal control your Z-wave devices"; - } + // Returns the description of the plugin is shown in the plugin menu + public string Description() + { + return "Micasa Verde Vera 2 controller, let Media Portal control your Z-wave devices"; + } - // Returns the author of the plugin which is shown in the plugin menu - public string Author() - { - return "Bart Eversdijk"; - } + // Returns the author of the plugin which is shown in the plugin menu + public string Author() + { + return "Bart Eversdijk"; + } - // show the setup dialog - public void ShowPlugin() - { - VeraSetupForm verasetup = new VeraSetupForm(); - verasetup.ShowDialog(); - } + // show the setup dialog + public void ShowPlugin() + { + VeraSetupForm verasetup = new VeraSetupForm(); + verasetup.ShowDialog(); + } - // Indicates whether plugin can be enabled/disabled - public bool CanEnable() - { - return true; - } + // Indicates whether plugin can be enabled/disabled + public bool CanEnable() + { + return true; + } - // Get Windows-ID - public int GetWindowId() - { - // WindowID of windowplugin belonging to this setup - // enter your own unique code - return _pluginID; - } + // Get Windows-ID + public int GetWindowId() + { + // WindowID of windowplugin belonging to this setup + // enter your own unique code + return _pluginID; + } - // Indicates if plugin is enabled by default; - public bool DefaultEnabled() - { - return true; - } + // Indicates if plugin is enabled by default; + public bool DefaultEnabled() + { + return true; + } - // indicates if a plugin has it's own setup screen - public bool HasSetup() - { - return true; - } + // indicates if a plugin has it's own setup screen + public bool HasSetup() + { + return true; + } - /// <summary> - /// If the plugin should have it's own button on the main menu of Mediaportal then it - /// should return true to this method, otherwise if it should not be on home - /// it should return false - /// </summary> - /// <param name="strButtonText">text the button should have</param> - /// <param name="strButtonImage">image for the button, or empty for default</param> - /// <param name="strButtonImageFocus">image for the button, or empty for default</param> - /// <param name="strPictureImage">subpicture for the button or empty for none</param> - /// <returns>true : plugin needs it's own button on home - /// false : plugin does not need it's own button on home</returns> + /// <summary> + /// If the plugin should have it's own button on the main menu of Mediaportal then it + /// should return true to this method, otherwise if it should not be on home + /// it should return false + /// </summary> + /// <param name="strButtonText">text the button should have</param> + /// <param name="strButtonImage">image for the button, or empty for default</param> + /// <param name="strButtonImageFocus">image for the button, or empty for default</param> + /// <param name="strPictureImage">subpicture for the button or empty for none</param> + /// <returns>true : plugin needs it's own button on home + /// false : plugin does not need it's own button on home</returns> - public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) - { - strButtonText = PluginName(); - strButtonImage = "hover_remote.png"; - strButtonImageFocus = "hover_remote.png"; - strPictureImage = "hover_remote.png"; - return true; - } + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = PluginName(); + strButtonImage = "hover_remote.png"; + strButtonImageFocus = "hover_remote.png"; + strPictureImage = "hover_remote.png"; + return true; + } - // With GetID it will be an window-plugin / otherwise a process-plugin - // Enter the id number here again - public override int GetID - { - get { return _pluginID; } - set { } - } + // With GetID it will be an window-plugin / otherwise a process-plugin + // Enter the id number here again + public override int GetID + { + get { return _pluginID; } + set { } + } - #endregion + #endregion - public override bool Init() - { - _selectedRoom = Int16.MaxValue; - _selectedCategory = Int16.MaxValue; + public override bool Init() + { + _selectedRoom = ALL; + _selectedCategory = ALL; - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) - { - _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); + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) + { + _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 - do this is a different Thread to not block MP-start up - new Thread( () => { - _vera.UpdateCurrentStatus(); - // 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"); - } + // Handle MP start-up trigger - do this is a different Thread to not block MP-start up + new Thread( () => { + _vera.UpdateCurrentStatus(); + // 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"); + } - protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) - { - if (control==_rightList) - OnRightlistCrtl((GUIListControl)control); - - if (control==_leftList) - OnLeftlistCrtl((GUIListControl)control); - - if (control==_catList) - OnCategoryList((GUISpinButton)control); - - if (control==_actionButton) - OnActionButton((GUIButtonControl)control); - - if (control==_actionTriggerButton) - OnActionTrigger((GUIToggleButtonControl)control); - - base.OnClicked (controlId, control, actionType); - } + protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) + { + if (control==_rightList) + OnRightlistCrtl((GUIListControl)control); + + if (control==_leftList) + OnLeftlistCrtl((GUIListControl)control); + + if (control==_catList) + OnCategoryList((GUISpinButton)control); + + if (control==_actionButton) + OnActionButton((GUIButtonControl)control); + + if (control==_actionTriggerButton) + OnActionTrigger((GUIToggleButtonControl)control); + + base.OnClicked (controlId, control, actionType); + } - /* Not valid until MP version 1.3 + /* Not valid until MP version 1.3 protected override void OnFocus(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { if (control==RightList) @@ -251,601 +255,586 @@ base.OnClicked (controlId, control, actionType); } - */ - - private void OnNewAction(Action action) - { - switch(action.wID) - { - case Action.ActionType.ACTION_PAUSE: - if (Player.Paused || Player.Playing) { - if (Player.IsMusic) { - handleActionTriggers(Player.Paused ? Actiontrigger.MUSIC_PAUSED : Actiontrigger.MUSIC_PAUSE_RESUMED); - } else if (Player.IsRadio) { - handleActionTriggers(Player.Paused ? Actiontrigger.RADIO_PAUSED : Actiontrigger.RADIO_PAUSE_RESUMED); - } else if (Player.IsTVRecording) { - handleActionTriggers(Player.Paused ? Actiontrigger.RECORDING_PAUSED : Actiontrigger.RECORDING_PAUSE_RESUMED); - } else if (Player.IsTV || Player.IsTimeShifting) { - handleActionTriggers(Player.Paused ? Actiontrigger.TV_PAUSED : Actiontrigger.TV_PAUSE_RESUMED); - } else if (Player.IsVideo ) { - handleActionTriggers(Player.Paused ? Actiontrigger.VIDEO_PAUSED : Actiontrigger.VIDEO_PAUSE_RESUMED); - } else { - handleActionTriggers(Player.Paused ? Actiontrigger.UNKNOWN_PAUSED : Actiontrigger.UNKNOWN_PAUSE_RESUMED); - } - } - break; + */ + + private void OnNewAction(Action action) + { + switch(action.wID) + { + case Action.ActionType.ACTION_PAUSE: + if (Player.Paused || Player.Playing) { + if (Player.IsMusic) { + handleActionTriggers(Player.Paused ? Actiontrigger.MUSIC_PAUSED : Actiontrigger.MUSIC_PAUSE_RESUMED); + } else if (Player.IsRadio) { + handleActionTriggers(Player.Paused ? Actiontrigger.RADIO_PAUSED : Actiontrigger.RADIO_PAUSE_RESUMED); + } else if (Player.IsTVRecording) { + handleActionTriggers(Player.Paused ? Actiontrigger.RECORDING_PAUSED : Actiontrigger.RECORDING_PAUSE_RESUMED); + } else if (Player.IsTV || Player.IsTimeShifting) { + handleActionTriggers(Player.Paused ? Actiontrigger.TV_PAUSED : Actiontrigger.TV_PAUSE_RESUMED); + } else if (Player.IsVideo ) { + handleActionTriggers(Player.Paused ? Actiontrigger.VIDEO_PAUSED : Actiontrigger.VIDEO_PAUSE_RESUMED); + } else { + handleActionTriggers(Player.Paused ? Actiontrigger.UNKNOWN_PAUSED : Actiontrigger.UNKNOWN_PAUSE_RESUMED); + } + } + break; - case Action.ActionType.ACTION_CONTEXT_MENU: - if (GUIWindowManager.ActiveWindow == GetWindowId()) - { - showInfoDialog(); - } - break; - - case Action.ActionType.ACTION_EXIT: - handleActionTriggers(Actiontrigger.MP_EXIT); - break; + case Action.ActionType.ACTION_CONTEXT_MENU: + if (GUIWindowManager.ActiveWindow == GetWindowId()) + { + showInfoDialog(); + } + break; + + case Action.ActionType.ACTION_EXIT: + handleActionTriggers(Actiontrigger.MP_EXIT); + break; - case Action.ActionType.ACTION_HIBERNATE: - case Action.ActionType.ACTION_POWER_OFF: - case Action.ActionType.ACTION_REBOOT: - case Action.ActionType.ACTION_SHUTDOWN: - case Action.ActionType.ACTION_SUSPEND: - handleActionTriggers(Actiontrigger.MP_SHUTDOWN); - break; - - // Resume ? how to determine (Plug in init?) - default: - break; - - } - } - - private void g_Player_PlayBackEnded(Player.MediaType media, string filename) - { - g_Player_PlayBackStopped(media, 0, filename); - } - - private void g_Player_PlayBackStopped(Player.MediaType media, int stoptime, string filename) - { - switch(media) - { - case Player.MediaType.Music: - handleActionTriggers(Actiontrigger.MUSIC_STOPPED); - break; - case Player.MediaType.Radio: - handleActionTriggers(Actiontrigger.RADIO_STOPPED); - break; - case Player.MediaType.Recording: - handleActionTriggers(Actiontrigger.RECORDING_STOPPED); - break; - case Player.MediaType.TV: - handleActionTriggers(Actiontrigger.TV_STOPPED); - break; - case Player.MediaType.Video: - handleActionTriggers(Actiontrigger.VIDEO_STOPPED); - break; - case Player.MediaType.Unknown: - default: - handleActionTriggers(Actiontrigger.UNKNOWN_STOPPED); - break; - } - } - - private void g_Player_PlayBackStarted(Player.MediaType media, string filename) - { - switch(media) - { - case Player.MediaType.Music: - if (_lastAction == Actiontrigger.MUSIC_PAUSED) { - handleActionTriggers(Actiontrigger.MUSIC_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.MUSIC_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.MUSIC_START_PLAYING); - handleActionTriggers(Actiontrigger.MUSIC_START_PLAYING); - } - break; - case Player.MediaType.Radio: - if (_lastAction == Actiontrigger.RADIO_PAUSED) { - handleActionTriggers(Actiontrigger.RADIO_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.RADIO_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.RADIO_START_PLAYING); - handleActionTriggers(Actiontrigger.RADIO_START_PLAYING); - } - break; - case Player.MediaType.Recording: - if (_lastAction == Actiontrigger.RECORDING_PAUSED) { - handleActionTriggers(Actiontrigger.RECORDING_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.RECORDING_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.RECORDING_START_PLAYING); - handleActionTriggers(Actiontrigger.RECORDING_START_PLAYING); - } - break; - case Player.MediaType.TV: - if (_lastAction == Actiontrigger.TV_PAUSED) { - handleActionTriggers(Actiontrigger.TV_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.TV_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.TV_START_PLAYING); - handleActionTriggers(Actiontrigger.TV_START_PLAYING); - } - break; - case Player.MediaType.Video: - if (_lastAction == Actiontrigger.VIDEO_PAUSED) { - handleActionTriggers(Actiontrigger.VIDEO_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.VIDEO_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.TV_START_PLAYING); - handleActionTriggers(Actiontrigger.VIDEO_START_PLAYING); - } - break; - case Player.MediaType.Unknown: - default: - if (_lastAction == Actiontrigger.UNKNOWN_PAUSED) { - handleActionTriggers(Actiontrigger.UNKNOWN_PAUSE_RESUMED); - } else if (_lastAction != Actiontrigger.UNKNOWN_PAUSE_RESUMED) { - triggerStopPlayingMedia(Actiontrigger.UNKNOWN_START_PLAYING); - handleActionTriggers(Actiontrigger.UNKNOWN_START_PLAYING); - } - break; - } - } - - private void triggerStopPlayingMedia(Actiontrigger newAction) - { - switch(_lastAction) - { - case Actiontrigger.MUSIC_START_PLAYING: - case Actiontrigger.MUSIC_PAUSED: - case Actiontrigger.MUSIC_PAUSE_RESUMED: - if (newAction != Actiontrigger.MUSIC_START_PLAYING) { - handleActionTriggers(Actiontrigger.MUSIC_STOPPED); - } - break; - case Actiontrigger.RADIO_START_PLAYING: - case Actiontrigger.RADIO_PAUSED: - case Actiontrigger.RADIO_PAUSE_RESUMED: - if (newAction != Actiontrigger.RADIO_START_PLAYING) { - handleActionTriggers(Actiontrigger.RADIO_STOPPED); - } - break; - case Actiontrigger.RECORDING_START_PLAYING: - case Actiontrigger.RECORDING_PAUSED: - case Actiontrigger.RECORDING_PAUSE_RESUMED: - if (newAction != Actiontrigger.RECORDING_START_PLAYING) { - handleActionTriggers(Actiontrigger.RECORDING_STOPPED); - } - break; - case Actiontrigger.TV_START_PLAYING: - case Actiontrigger.TV_PAUSED: - case Actiontrigger.TV_PAUSE_RESUMED: - if (newAction != Actiontrigger.TV_START_PLAYING) { - handleActionTriggers(Actiontrigger.TV_STOPPED); - } - break; - case Actiontrigger.VIDEO_START_PLAYING: - case Actiontrigger.VIDEO_PAUSED: - case Actiontrigger.VIDEO_PAUSE_RESUMED: - if (newAction != Actiontrigger.VIDEO_START_PLAYING) { - handleActionTriggers(Actiontrigger.VIDEO_STOPPED); - } - break; - case Actiontrigger.UNKNOWN_START_PLAYING: - case Actiontrigger.UNKNOWN_PAUSED: - case Actiontrigger.UNKNOWN_PAUSE_RESUMED: - if (newAction != Actiontrigger.UNKNOWN_START_PLAYING) { - handleActionTriggers(Actiontrigger.UNKNOWN_STOPPED); - } - break; - } - } - - - public void handleActionTriggers(Actiontrigger action) - { - /* - * Action handler: - * - start up --> plugin init - * - shut down/hibernate --> Action: ACTION_SHUTDOWN - * - resume from hibernate ??? - * - quit --> Action: ACTION_EXIT - * - * Music + Video + Radio + Recording + TV + Unknown - * - play --> PLayer_started && media - * - pause --> Action == Action.ActionType.ACTION_PAUSE && g_Player.Paused - * - stop --> PLayer_started && media - */ - - if (_lastAction == action || !_enableSceneTrigger) - { - // Never send the same action twice... || check if scene trigger is enabled - return; - } - //Store last action - never send the same action twice... - _lastAction = action; + case Action.ActionType.ACTION_HIBERNATE: + case Action.ActionType.ACTION_POWER_OFF: + case Action.ActionType.ACTION_REBOOT: + case Action.ActionType.ACTION_SHUTDOWN: + case Action.ActionType.ACTION_SUSPEND: + handleActionTriggers(Actiontrigger.MP_SHUTDOWN); + break; + + // Resume ? how to determine (Plug in init?) + default: + break; + + } + } + + private void g_Player_PlayBackEnded(Player.MediaType media, string filename) + { + g_Player_PlayBackStopped(media, 0, filename); + } + + private void g_Player_PlayBackStopped(Player.MediaType media, int stoptime, string filename) + { + switch(media) + { + case Player.MediaType.Music: + handleActionTriggers(Actiontrigger.MUSIC_STOPPED); + break; + case Player.MediaType.Radio: + handleActionTriggers(Actiontrigger.RADIO_STOPPED); + break; + case Player.MediaType.Recording: + handleActionTriggers(Actiontrigger.RECORDING_STOPPED); + break; + case Player.MediaType.TV: + handleActionTriggers(Actiontrigger.TV_STOPPED); + break; + case Player.MediaType.Video: + handleActionTriggers(Actiontrigger.VIDEO_STOPPED); + break; + case Player.MediaType.Unknown: + default: + handleActionTriggers(Actiontrigger.UNKNOWN_STOPPED); + break; + } + } + + private void g_Player_PlayBackStarted(Player.MediaType media, string filename) + { + switch(media) + { + case Player.MediaType.Music: + if (_lastAction == Actiontrigger.MUSIC_PAUSED) { + handleActionTriggers(Actiontrigger.MUSIC_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.MUSIC_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.MUSIC_START_PLAYING); + handleActionTriggers(Actiontrigger.MUSIC_START_PLAYING); + } + break; + case Player.MediaType.Radio: + if (_lastAction == Actiontrigger.RADIO_PAUSED) { + handleActionTriggers(Actiontrigger.RADIO_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.RADIO_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.RADIO_START_PLAYING); + handleActionTriggers(Actiontrigger.RADIO_START_PLAYING); + } + break; + case Player.MediaType.Recording: + if (_lastAction == Actiontrigger.RECORDING_PAUSED) { + handleActionTriggers(Actiontrigger.RECORDING_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.RECORDING_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.RECORDING_START_PLAYING); + handleActionTriggers(Actiontrigger.RECORDING_START_PLAYING); + } + break; + case Player.MediaType.TV: + if (_lastAction == Actiontrigger.TV_PAUSED) { + handleActionTriggers(Actiontrigger.TV_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.TV_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.TV_START_PLAYING); + handleActionTriggers(Actiontrigger.TV_START_PLAYING); + } + break; + case Player.MediaType.Video: + if (_lastAction == Actiontrigger.VIDEO_PAUSED) { + handleActionTriggers(Actiontrigger.VIDEO_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.VIDEO_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.TV_START_PLAYING); + handleActionTriggers(Actiontrigger.VIDEO_START_PLAYING); + } + break; + case Player.MediaType.Unknown: + default: + if (_lastAction == Actiontrigger.UNKNOWN_PAUSED) { + handleActionTriggers(Actiontrigger.UNKNOWN_PAUSE_RESUMED); + } else if (_lastAction != Actiontrigger.UNKNOWN_PAUSE_RESUMED) { + triggerStopPlayingMedia(Actiontrigger.UNKNOWN_START_PLAYING); + handleActionTriggers(Actiontrigger.UNKNOWN_START_PLAYING); + } + break; + } + } + + private void triggerStopPlayingMedia(Actiontrigger newAction) + { + switch(_lastAction) + { + case Actiontrigger.MUSIC_START_PLAYING: + case Actiontrigger.MUSIC_PAUSED: + case Actiontrigger.MUSIC_PAUSE_RESUMED: + if (newAction != Actiontrigger.MUSIC_START_PLAYING) { + handleActionTriggers(Actiontrigger.MUSIC_STOPPED); + } + break; + case Actiontrigger.RADIO_START_PLAYING: + case Actiontrigger.RADIO_PAUSED: + case Actiontrigger.RADIO_PAUSE_RESUMED: + if (newAction != Actiontrigger.RADIO_START_PLAYING) { + handleActionTriggers(Actiontrigger.RADIO_STOPPED); + } + break; + case Actiontrigger.RECORDING_START_PLAYING: + case Actiontrigger.RECORDING_PAUSED: + case Actiontrigger.RECORDING_PAUSE_RESUMED: + if (newAction != Actiontrigger.RECORDING_START_PLAYING) { + handleActionTriggers(Actiontrigger.RECORDING_STOPPED); + } + break; + case Actiontrigger.TV_START_PLAYING: + case Actiontrigger.TV_PAUSED: + case Actiontrigger.TV_PAUSE_RESUMED: + if (newAction != Actiontrigger.TV_START_PLAYING) { + handleActionTriggers(Actiontrigger.TV_STOPPED); + } + break; + case Actiontrigger.VIDEO_START_PLAYING: + case Actiontrigger.VIDEO_PAUSED: + case Actiontrigger.VIDEO_PAUSE_RESUMED: + if (newAction != Actiontrigger.VIDEO_START_PLAYING) { + handleActionTriggers(Actiontrigger.VIDEO_STOPPED); + } + break; + case Actiontrigger.UNKNOWN_START_PLAYING: + case Actiontrigger.UNKNOWN_PAUSED: + case Actiontrigger.UNKNOWN_PAUSE_RESUMED: + if (newAction != Actiontrigger.UNKNOWN_START_PLAYING) { + handleActionTriggers(Actiontrigger.UNKNOWN_STOPPED); + } + break; + } + } + + + public void handleActionTriggers(Actiontrigger action) + { + /* + * Action handler: + * - start up --> plugin init + * - shut down/hibernate --> Action: ACTION_SHUTDOWN + * - resume from hibernate ??? + * - quit --> Action: ACTION_EXIT + * + * Music + Video + Radio + Recording + TV + Unknown + * - play --> PLayer_started && media + * - pause --> Action == Action.ActionType.ACTION_PAUSE && g_Player.Paused + * - stop --> PLayer_started && media + */ + + if (_lastAction == action || !_enableSceneTrigger) + { + // Never send the same action twice... || check if scene trigger is enabled + return; + } + //Store last action - never send the same action twice... + _lastAction = action; - if ((_vera.actionTriggerTable[(int)action] > 0) && (_vera.actionTriggerTable[(int)action] < Int16.MaxValue)) - { - Scene scene = _vera.status.GetSceneById(_vera.actionTriggerTable[(int)action]); - if (scene.id > 0) - { - scene.Run(); - } - } - } - - public override void Render(float timePassed) - { - // Give a message to the user a update failed - if (_vera.lastUpdateFailed) - { - // Show message only once! - if (!_lastUpdateFailed) - { - if (_vera.status.system.dataversion == "0") - { // Give message dialog on never connected... - new Thread (() => { NoConnection(_vera.lastUpdateError);}).Start(); - } else { - // Give an error message on screen - _vera.status.system.ReportConnectionError(_vera.lastUpdateError); - } - } - _lastUpdateFailed = true; - } - else - { // Reset failed flag again - _lastUpdateFailed = false; - } - - // vera will only update when realy required - _vera.UpdateCurrentStatus(); - refreshNow(); - - base.Render(timePassed); - } + if ((_vera.actionTriggerTable[(int)action] > 0) && (_vera.actionTriggerTable[(int)action] < NO_SCENE_SELECTED)) + { + Scene scene = _vera.status.GetSceneById(_vera.actionTriggerTable[(int)action]); + if (scene.id > 0) + { + scene.Run(); + } + } + } + + public override void Render(float timePassed) + { + // Give a message to the user a update failed + if (_vera.lastUpdateFailed) + { + // Show message only once! + if (!_lastUpdateFailed) + { + if (_vera.status.system.dataversion == "0") + { // Give message dialog on never connected... + new Thread (() => { NoConnection(_vera.lastUpdateError);}).Start(); + } else { + // Give an error message on screen + _vera.status.system.ReportConnectionError(_vera.lastUpdateError); + } + } + _lastUpdateFailed = true; + } + else + { // Reset failed flag again + _lastUpdateFailed = false; + } + + // vera will only update when realy required + _vera.UpdateCurrentStatus(); + refreshNow(); + + base.Render(timePassed); + } - public void refreshNow() - { - if (_vera.NewScreenUpdateWaitingAndClearFlag()) - { - // update system status - if (_vera.status.system.NewScreenUpdateWaitingAndClearFlag()) - { - setSystemStatus(); - } - - // if full reload has been found rebuild lists - if (_vera.status.system.fullReload ) { - listRooms(_selectedCategory, _selectedRoom); - if (_selectedRoom == Int16.MaxValue) { - listScenes(); - } else { - listDevices(_selectedRoom); - } - } - else - { - // update device status - if (_selectedRoom != Int16.MaxValue) - { - foreach (GUIListItem item in _rightList.ListItems) - { - DeviceGeneric dev = _vera.status.GetDeviceById( item.ItemId ); - 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() - { - if (_selectedCategory == 0) { _selectedCategory = Int16.MaxValue; } - - listCategories(); - listRooms(_selectedCategory, _selectedRoom); - if (_selectedRoom == Int16.MaxValue) { - listScenes(); - } else { - listDevices(_selectedRoom); - } - - // 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); - - foreach( Section sec in _vera.sections ) - { - _catList.AddSpinLabel(sec.name, sec.id); - iCnt++; - if (_selectedCategory == sec.id) - { - iSelected = iCnt; - } - } - _catList.SelectedItem = iSelected; - } - - private void listScenes() - { - GUIControl.ClearControl(GetID, _rightList.GetID); - - foreach( Scene scene in _vera.scenes ) - { - GUIListItem item = new GUIListItem(scene.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; - item.IconImage = "Vera\\Scenes.png"; - item.IconImageBig = "Vera\\Scenes.png"; - item.ThumbnailImage = "Vera\\Scenes.png"; - - Utils.SetDefaultIcons(item); - _rightList.Add(item); - } - GUIControl.FocusControl(GetID, _leftList.GetID); + public void refreshNow() + { + if (_vera.NewScreenUpdateWaitingAndClearFlag()) + { + // update system status + if (_vera.status.system.NewScreenUpdateWaitingAndClearFlag()) + { + setSystemStatus(); + } + + // if full reload has been found rebuild lists + if (_vera.status.system.fullReload ) { + listRooms(_selectedCategory, _selectedRoom); + if (_selectedRoom == ALL) { + listScenes(ALL); + } else { + listDevices(_selectedRoom); + } + } + else + { + // update device status + foreach (GUIListItem item in _rightList.ListItems) + { + if (item.ItemId > 0) + { // ItemId > 0 so we have a device + DeviceGeneric dev = _vera.status.GetDeviceById(item.ItemId); + if (dev.NewScreenUpdateWaitingAndClearFlag()) + { + fillinDeviceInfo(item, dev); + } + } + else + { // ItemId < 0 so we have a scene + Scene scene = _vera.status.GetSceneById((item.ItemId * -1)); + if (scene.NewScreenUpdateWaitingAndClearFlag()) + { + fillinSceneInfo(item, scene); + } + } + } + } + } + } + + protected override void OnPageLoad() + { + if (_selectedCategory == 0) { _selectedCategory = ALL; } + + listCategories(); + listRooms(_selectedCategory, _selectedRoom); + if (_selectedRoom == ALL) { + listScenes(ALL); + } else { + listDevices(_selectedRoom); + } + + // 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", ALL); + + foreach( Section sec in _vera.sections ) + { + _catList.AddSpinLabel(sec.name, sec.id); + iCnt++; + if (_selectedCategory == sec.id) + { + iSelected = iCnt; + } + } + _catList.SelectedItem = iSelected; + } + + private void listRooms(int showSection, int selectedRoom) + { + int cnt = 0; + int selected = 0; + // --- fill in left lisft with rooms and scene item + GUIControl.ClearControl(GetID, _leftList.GetID); + GUIListItem sceneitem = new GUIListItem("Scenes"); + sceneitem.ItemId = ALL; - // Set Current Selected Item - _rightList.SelectedListItemIndex = 0; + sceneitem.IconImage = "Vera\\Scenes.png"; + sceneitem.IconImageBig = "Vera\\Scenes.png"; + sceneitem.ThumbnailImage = "Vera\\Scenes.png"; + + Utils.SetDefaultIcons(sceneitem); + _leftList.Add(sceneitem); + + foreach(Room room in _vera.rooms) + { + if (showSection == ALL|| room.section == showSection) + { + GUIListItem item = new GUIListItem(room.name); + item.Label2 = _vera.status.GetSectionById(room.section).name; + + item.ItemId = room.id; + item.IconImage = "fastforward_enabled.png"; + item.IconImageBig = "fastforward_enabled.png"; + item.ThumbnailImage = "fastforward_enabled.png"; + + Utils.SetDefaultIcons(item); + _leftList.Add(item); - _title.Label = _titleTxt + " - Scenes"; - } - - 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"); - sceneitem.ItemId = Int16.MaxValue; + cnt++; + if (selectedRoom == room.id) + { + selected = cnt; + } + } + } + // Set Current Selected Item + _leftList.SelectedListItemIndex = selected; + } + + private void listScenes(int selectedRoom) + { + GUIControl.ClearControl(GetID, _rightList.GetID); + + foreach(Scene scene in _vera.scenes) + { + if (selectedRoom == ALL || scene.InRoom(selectedRoom)) + { + GUIListItem item = new GUIListItem(scene.name); + fillinSceneInfo(item, scene); + _rightList.Add(item); + } + } + GUIControl.FocusControl(GetID, _leftList.GetID); - sceneitem.IconImage = "Vera\\Scenes.png"; - sceneitem.IconImageBig = "Vera\\Scenes.png"; - sceneitem.ThumbnailImage = "Vera\\Scenes.png"; - - Utils.SetDefaultIcons(sceneitem); - _leftList.Add(scene... [truncated message content] |