fix: add messenger and event to ICurrentSources

This commit is contained in:
Andrew Welker
2025-07-29 22:26:07 -05:00
parent 2efab4f196
commit e03874a7a9
5 changed files with 157 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Routing namespace PepperDash.Essentials.Core.Routing
{ {
@@ -25,5 +25,19 @@ namespace PepperDash.Essentials.Core.Routing
/// </summary> /// </summary>
Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; } Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; }
/// <summary>
/// Event raised when the current sources change.
/// </summary>
event EventHandler CurrentSourcesChanged;
/// <summary>
/// Sets the current source for a specific signal type.
/// This method updates the current source for the specified signal type and notifies any subscribers of the change.
/// </summary>
/// <param name="signalType">The signal type to update.</param>
/// <param name="sourceListKey">The key for the source list.</param>
/// <param name="sourceListItem">The source list item to set as the current source.</param>
void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem);
} }
} }

View File

@@ -52,9 +52,9 @@ namespace PepperDash.Essentials.Devices.Common.Displays
/// </summary> /// </summary>
public event SourceInfoChangeHandler CurrentSourceChange; public event SourceInfoChangeHandler CurrentSourceChange;
/// <summary> /// <summary>
/// Gets or sets the CurrentSourceInfoKey /// Gets or sets the CurrentSourceInfoKey
/// </summary> /// </summary>
public string CurrentSourceInfoKey { get; set; } public string CurrentSourceInfoKey { get; set; }
/// <summary> /// <summary>
@@ -89,29 +89,32 @@ namespace PepperDash.Essentials.Devices.Common.Displays
/// <inheritdoc/> /// <inheritdoc/>
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; } public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; private set; }
/// <inheritdoc />
public event EventHandler CurrentSourcesChanged;
/// <summary> /// <summary>
/// Gets feedback indicating whether the display is currently cooling down after being powered off. /// Gets feedback indicating whether the display is currently cooling down after being powered off.
/// </summary> /// </summary>
public BoolFeedback IsCoolingDownFeedback { get; protected set; } public BoolFeedback IsCoolingDownFeedback { get; protected set; }
/// <summary> /// <summary>
/// Gets or sets the IsWarmingUpFeedback /// Gets or sets the IsWarmingUpFeedback
/// </summary> /// </summary>
public BoolFeedback IsWarmingUpFeedback { get; private set; } public BoolFeedback IsWarmingUpFeedback { get; private set; }
/// <summary> /// <summary>
/// Gets or sets the UsageTracker /// Gets or sets the UsageTracker
/// </summary> /// </summary>
public UsageTracking UsageTracker { get; set; } public UsageTracking UsageTracker { get; set; }
/// <summary> /// <summary>
/// Gets or sets the WarmupTime /// Gets or sets the WarmupTime
/// </summary> /// </summary>
public uint WarmupTime { get; set; } public uint WarmupTime { get; set; }
/// <summary> /// <summary>
/// Gets or sets the CooldownTime /// Gets or sets the CooldownTime
/// </summary> /// </summary>
public uint CooldownTime { get; set; } public uint CooldownTime { get; set; }
/// <summary> /// <summary>
@@ -189,7 +192,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays
/// <summary> /// <summary>
/// Gets the collection of feedback objects for this display device. /// Gets the collection of feedback objects for this display device.
/// </summary> /// </summary>
/// <inheritdoc /> /// <inheritdoc />
public virtual FeedbackCollection<Feedback> Feedbacks public virtual FeedbackCollection<Feedback> Feedbacks
{ {
get get
@@ -378,6 +381,33 @@ namespace PepperDash.Essentials.Devices.Common.Displays
volumeDisplayWithFeedback.MuteFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.VolumeMuteOff.JoinNumber]); volumeDisplayWithFeedback.MuteFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.VolumeMuteOff.JoinNumber]);
} }
/// <inheritdoc />
public virtual void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem)
{
// Update the current source for the specified signal type
if (CurrentSources.ContainsKey(signalType))
{
CurrentSources[signalType] = sourceListItem;
}
else
{
CurrentSources.Add(signalType, sourceListItem);
}
// Update the current source key for the specified signal type
if (CurrentSourceKeys.ContainsKey(signalType))
{
CurrentSourceKeys[signalType] = sourceListKey;
}
else
{
CurrentSourceKeys.Add(signalType, sourceListKey);
}
// Raise the CurrentSourcesChanged event
CurrentSourcesChanged?.Invoke(this, EventArgs.Empty);
}
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,68 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.AppServer.Messengers
{
/// <summary>
/// Represents a IHasCurrentSourceInfoMessenger
/// </summary>
public class CurrentSourcesMessenger : MessengerBase
{
private readonly ICurrentSources sourceDevice;
public CurrentSourcesMessenger(string key, string messagePath, ICurrentSources device) : base(key, messagePath, device as IKeyName)
{
sourceDevice = device;
}
protected override void RegisterActions()
{
base.RegisterActions();
AddAction("/fullStatus", (id, content) =>
{
var message = new CurrentSourcesStateMessage
{
CurrentSourceKeys = sourceDevice.CurrentSourceKeys,
CurrentSources = sourceDevice.CurrentSources
};
PostStatusMessage(message);
});
sourceDevice.CurrentSourcesChanged += (sender, e) =>
{
PostStatusMessage(JToken.FromObject(new
{
currentSourceKeys = sourceDevice.CurrentSourceKeys,
currentSources = sourceDevice.CurrentSources
}));
};
}
}
/// <summary>
/// Represents a CurrentSourcesStateMessage
/// </summary>
public class CurrentSourcesStateMessage : DeviceStateMessageBase
{
/// <summary>
/// Gets or sets the CurrentSourceKey
/// </summary>
[JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
public Dictionary<eRoutingSignalType, string> CurrentSourceKeys { get; set; }
/// <summary>
/// Gets or sets the CurrentSource
/// </summary>
[JsonProperty("currentSource")]
public Dictionary<eRoutingSignalType, SourceListItem> CurrentSources { get; set; }
}
}

View File

@@ -54,16 +54,18 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// </summary> /// </summary>
public class CurrentSourceStateMessage : DeviceStateMessageBase public class CurrentSourceStateMessage : DeviceStateMessageBase
{ {
[JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)]
/// <summary> /// <summary>
/// Gets or sets the CurrentSourceKey /// Gets or sets the CurrentSourceKey
/// </summary> /// </summary>
[JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)]
public string CurrentSourceKey { get; set; } public string CurrentSourceKey { get; set; }
[JsonProperty("currentSource")]
/// <summary> /// <summary>
/// Gets or sets the CurrentSource /// Gets or sets the CurrentSource
/// </summary> /// </summary>
[JsonProperty("currentSource")]
public SourceListItem CurrentSource { get; set; } public SourceListItem CurrentSource { get; set; }
} }
} }

View File

@@ -1,4 +1,10 @@
using Crestron.SimplSharp; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http; using Crestron.SimplSharp.Net.Http;
using Crestron.SimplSharp.WebScripting; using Crestron.SimplSharp.WebScripting;
@@ -30,12 +36,6 @@ using PepperDash.Essentials.RoomBridges;
using PepperDash.Essentials.Services; using PepperDash.Essentials.Services;
using PepperDash.Essentials.WebApiHandlers; using PepperDash.Essentials.WebApiHandlers;
using PepperDash.Essentials.WebSocketServer; using PepperDash.Essentials.WebSocketServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WebSocketSharp; using WebSocketSharp;
namespace PepperDash.Essentials namespace PepperDash.Essentials
@@ -721,6 +721,15 @@ namespace PepperDash.Essentials
messengerAdded = true; messengerAdded = true;
} }
if (device is ICurrentSources currentSources)
{
this.LogVerbose("Adding CurrentSourcesMessenger for {deviceKey}", device.Key);
var messenger = new CurrentSourcesMessenger($"{device.Key}-currentSources-{Key}", $"/device/{device.Key}", currentSources);
AddDefaultDeviceMessenger(messenger);
}
if (device is ISwitchedOutput switchedDevice) if (device is ISwitchedOutput switchedDevice)
{ {
this.LogVerbose( this.LogVerbose(