mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
Merge pull request #1279 from PepperDash/device-status-console
This commit is contained in:
@@ -11,35 +11,35 @@ namespace PepperDash.Core
|
|||||||
public class Device : IKeyName
|
public class Device : IKeyName
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique Key
|
/// Unique Key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Key { get; protected set; }
|
public string Key { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the devie
|
/// Name of the devie
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; protected set; }
|
public string Name { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Enabled { get; protected set; }
|
public bool Enabled { get; protected set; }
|
||||||
|
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// A place to store reference to the original config object, if any. These values should
|
///// A place to store reference to the original config object, if any. These values should
|
||||||
///// NOT be used as properties on the device as they are all publicly-settable values.
|
///// NOT be used as properties on the device as they are all publicly-settable values.
|
||||||
///// </summary>
|
///// </summary>
|
||||||
//public DeviceConfig Config { get; private set; }
|
//public DeviceConfig Config { get; private set; }
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// Helper method to check if Config exists
|
///// Helper method to check if Config exists
|
||||||
///// </summary>
|
///// </summary>
|
||||||
//public bool HasConfig { get { return Config != null; } }
|
//public bool HasConfig { get { return Config != null; } }
|
||||||
|
|
||||||
List<Action> _PreActivationActions;
|
List<Action> _PreActivationActions;
|
||||||
List<Action> _PostActivationActions;
|
List<Action> _PostActivationActions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Device DefaultDevice { get { return _DefaultDevice; } }
|
public static Device DefaultDevice { get { return _DefaultDevice; } }
|
||||||
static Device _DefaultDevice = new Device("Default", "Default");
|
static Device _DefaultDevice = new Device("Default", "Default");
|
||||||
|
|
||||||
@@ -54,27 +54,27 @@ namespace PepperDash.Core
|
|||||||
Name = "";
|
Name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor with key and name
|
/// Constructor with key and name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
public Device(string key, string name) : this(key)
|
public Device(string key, string name) : this(key)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public Device(DeviceConfig config)
|
//public Device(DeviceConfig config)
|
||||||
// : this(config.Key, config.Name)
|
// : this(config.Key, config.Name)
|
||||||
//{
|
//{
|
||||||
// Config = config;
|
// Config = config;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a pre activation action
|
/// Adds a pre activation action
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="act"></param>
|
/// <param name="act"></param>
|
||||||
public void AddPreActivationAction(Action act)
|
public void AddPreActivationAction(Action act)
|
||||||
{
|
{
|
||||||
if (_PreActivationActions == null)
|
if (_PreActivationActions == null)
|
||||||
@@ -82,10 +82,10 @@ namespace PepperDash.Core
|
|||||||
_PreActivationActions.Add(act);
|
_PreActivationActions.Add(act);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a post activation action
|
/// Adds a post activation action
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="act"></param>
|
/// <param name="act"></param>
|
||||||
public void AddPostActivationAction(Action act)
|
public void AddPostActivationAction(Action act)
|
||||||
{
|
{
|
||||||
if (_PostActivationActions == null)
|
if (_PostActivationActions == null)
|
||||||
@@ -93,55 +93,58 @@ namespace PepperDash.Core
|
|||||||
_PostActivationActions.Add(act);
|
_PostActivationActions.Add(act);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the preactivation actions
|
/// Executes the preactivation actions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PreActivate()
|
public void PreActivate()
|
||||||
{
|
{
|
||||||
if (_PreActivationActions != null)
|
if (_PreActivationActions != null)
|
||||||
_PreActivationActions.ForEach(a => {
|
_PreActivationActions.ForEach(a =>
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
a.Invoke();
|
a.Invoke();
|
||||||
} catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
|
{
|
||||||
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
|
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets this device ready to be used in the system. Runs any added pre-activation items, and
|
/// Gets this device ready to be used in the system. Runs any added pre-activation items, and
|
||||||
/// all post-activation at end. Classes needing additional logic to
|
/// all post-activation at end. Classes needing additional logic to
|
||||||
/// run should override CustomActivate()
|
/// run should override CustomActivate()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Activate()
|
public bool Activate()
|
||||||
{
|
{
|
||||||
//if (_PreActivationActions != null)
|
//if (_PreActivationActions != null)
|
||||||
// _PreActivationActions.ForEach(a => a.Invoke());
|
// _PreActivationActions.ForEach(a => a.Invoke());
|
||||||
var result = CustomActivate();
|
var result = CustomActivate();
|
||||||
//if(result && _PostActivationActions != null)
|
//if(result && _PostActivationActions != null)
|
||||||
// _PostActivationActions.ForEach(a => a.Invoke());
|
// _PostActivationActions.ForEach(a => a.Invoke());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the postactivation actions
|
/// Executes the postactivation actions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PostActivate()
|
public void PostActivate()
|
||||||
{
|
{
|
||||||
if (_PostActivationActions != null)
|
if (_PostActivationActions != null)
|
||||||
_PostActivationActions.ForEach(a => {
|
_PostActivationActions.ForEach(a =>
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
a.Invoke();
|
{
|
||||||
}
|
a.Invoke();
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
|
{
|
||||||
}
|
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called in between Pre and PostActivationActions when Activate() is called.
|
/// Called in between Pre and PostActivationActions when Activate() is called.
|
||||||
@@ -158,14 +161,14 @@ namespace PepperDash.Core
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual bool Deactivate() { return true; }
|
public virtual bool Deactivate() { return true; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this method to start communications with a device. Overriding classes do not need to call base.Initialize()
|
/// Call this method to start communications with a device. Overriding classes do not need to call base.Initialize()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper method to check object for bool value false and fire an Action method
|
/// Helper method to check object for bool value false and fire an Action method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="o">Should be of type bool, others will be ignored</param>
|
/// <param name="o">Should be of type bool, others will be ignored</param>
|
||||||
@@ -175,5 +178,15 @@ namespace PepperDash.Core
|
|||||||
if (o is bool && !(bool)o) a();
|
if (o is bool && !(bool)o) a();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a string representation of the object, including its key and name.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>The returned string is formatted as "{Key} - {Name}". If the <c>Name</c> property is
|
||||||
|
/// null or empty, "---" is used in place of the name.</remarks>
|
||||||
|
/// <returns>A string that represents the object, containing the key and name in the format "{Key} - {Name}".</returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>())
|
foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>())
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse($"{dev}: {dev.CommunicationMonitor.Status}{Environment.NewLine}");
|
CrestronConsole.ConsoleCommandResponse($"{dev}: {dev.CommunicationMonitor.Status}\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,19 +20,20 @@ namespace PepperDash.Essentials.Core
|
|||||||
public event EventHandler Initialized;
|
public event EventHandler Initialized;
|
||||||
|
|
||||||
private bool _isInitialized;
|
private bool _isInitialized;
|
||||||
public bool IsInitialized {
|
public bool IsInitialized
|
||||||
|
{
|
||||||
get { return _isInitialized; }
|
get { return _isInitialized; }
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
if (_isInitialized == value) return;
|
if (_isInitialized == value) return;
|
||||||
|
|
||||||
_isInitialized = value;
|
_isInitialized = value;
|
||||||
|
|
||||||
if (_isInitialized)
|
if (_isInitialized)
|
||||||
{
|
{
|
||||||
Initialized?.Invoke(this, new EventArgs());
|
Initialized?.Invoke(this, new EventArgs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EssentialsDevice(string key)
|
protected EssentialsDevice(string key)
|
||||||
@@ -80,8 +81,9 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Override this method to build and create custom Mobile Control Messengers during the Activation phase
|
/// Override this method to build and create custom Mobile Control Messengers during the Activation phase
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void CreateMobileControlMessengers() {
|
protected virtual void CreateMobileControlMessengers()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user