fix: return --- if the device was created without a name

This commit is contained in:
Andrew Welker
2025-06-26 14:14:04 -04:00
parent 253b2cddaf
commit c9b3205736
3 changed files with 101 additions and 86 deletions

View File

@@ -99,11 +99,13 @@ namespace PepperDash.Core
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);
} }
@@ -131,7 +133,8 @@ namespace PepperDash.Core
public void PostActivate() public void PostActivate()
{ {
if (_PostActivationActions != null) if (_PostActivationActions != null)
_PostActivationActions.ForEach(a => { _PostActivationActions.ForEach(a =>
{
try try
{ {
a.Invoke(); a.Invoke();
@@ -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);
}
} }
} }

View File

@@ -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.Key}|{dev.Name}: {dev.CommunicationMonitor.Status}\r\n"); CrestronConsole.ConsoleCommandResponse($"{dev}: {dev.CommunicationMonitor.Status}\r\n");
} }
} }

View File

@@ -20,7 +20,8 @@ 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
{ {
@@ -80,7 +81,8 @@ 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()
{
} }
} }