diff --git a/src/PepperDash.Essentials.Core/Routing/ICurrentSources.cs b/src/PepperDash.Essentials.Core/Routing/ICurrentSources.cs index bef0fd95..a8940d08 100644 --- a/src/PepperDash.Essentials.Core/Routing/ICurrentSources.cs +++ b/src/PepperDash.Essentials.Core/Routing/ICurrentSources.cs @@ -1,5 +1,5 @@ +using System; using System.Collections.Generic; -using PepperDash.Essentials.Core; namespace PepperDash.Essentials.Core.Routing { @@ -25,5 +25,19 @@ namespace PepperDash.Essentials.Core.Routing /// Dictionary CurrentSourceKeys { get; } + /// + /// Event raised when the current sources change. + /// + event EventHandler CurrentSourcesChanged; + + /// + /// 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. + /// + /// The signal type to update. + /// The key for the source list. + /// The source list item to set as the current source. + void SetCurrentSource(eRoutingSignalType signalType, string sourceListKey, SourceListItem sourceListItem); + } } diff --git a/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs b/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs index 786fc00d..27a3e0e0 100644 --- a/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs +++ b/src/PepperDash.Essentials.Devices.Common/Displays/DisplayBase.cs @@ -52,9 +52,9 @@ namespace PepperDash.Essentials.Devices.Common.Displays /// public event SourceInfoChangeHandler CurrentSourceChange; - /// - /// Gets or sets the CurrentSourceInfoKey - /// + /// + /// Gets or sets the CurrentSourceInfoKey + /// public string CurrentSourceInfoKey { get; set; } /// @@ -89,29 +89,32 @@ namespace PepperDash.Essentials.Devices.Common.Displays /// public Dictionary CurrentSourceKeys { get; private set; } + /// + public event EventHandler CurrentSourcesChanged; + /// /// Gets feedback indicating whether the display is currently cooling down after being powered off. /// public BoolFeedback IsCoolingDownFeedback { get; protected set; } - /// - /// Gets or sets the IsWarmingUpFeedback - /// + /// + /// Gets or sets the IsWarmingUpFeedback + /// public BoolFeedback IsWarmingUpFeedback { get; private set; } - /// - /// Gets or sets the UsageTracker - /// + /// + /// Gets or sets the UsageTracker + /// public UsageTracking UsageTracker { get; set; } - /// - /// Gets or sets the WarmupTime - /// + /// + /// Gets or sets the WarmupTime + /// public uint WarmupTime { get; set; } - /// - /// Gets or sets the CooldownTime - /// + /// + /// Gets or sets the CooldownTime + /// public uint CooldownTime { get; set; } /// @@ -189,7 +192,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays /// /// Gets the collection of feedback objects for this display device. /// - /// + /// public virtual FeedbackCollection Feedbacks { get @@ -378,6 +381,33 @@ namespace PepperDash.Essentials.Devices.Common.Displays volumeDisplayWithFeedback.MuteFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.VolumeMuteOff.JoinNumber]); } + /// + 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); + } + } /// diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/CurrentSourcesMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/CurrentSourcesMessenger.cs new file mode 100644 index 00000000..01763b59 --- /dev/null +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/CurrentSourcesMessenger.cs @@ -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 +{ + /// + /// Represents a IHasCurrentSourceInfoMessenger + /// + 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 + })); + }; + } + } + + /// + /// Represents a CurrentSourcesStateMessage + /// + public class CurrentSourcesStateMessage : DeviceStateMessageBase + { + + /// + /// Gets or sets the CurrentSourceKey + /// + [JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)] + [JsonConverter(typeof(StringEnumConverter))] + public Dictionary CurrentSourceKeys { get; set; } + + + /// + /// Gets or sets the CurrentSource + /// + [JsonProperty("currentSource")] + public Dictionary CurrentSources { get; set; } + } +} diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasCurrentSourceInfoMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasCurrentSourceInfoMessenger.cs index 12a6bfec..04130776 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasCurrentSourceInfoMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasCurrentSourceInfoMessenger.cs @@ -54,16 +54,18 @@ namespace PepperDash.Essentials.AppServer.Messengers /// public class CurrentSourceStateMessage : DeviceStateMessageBase { - [JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)] + /// /// Gets or sets the CurrentSourceKey /// + [JsonProperty("currentSourceKey", NullValueHandling = NullValueHandling.Ignore)] public string CurrentSourceKey { get; set; } - [JsonProperty("currentSource")] + /// /// Gets or sets the CurrentSource /// + [JsonProperty("currentSource")] public SourceListItem CurrentSource { get; set; } } } diff --git a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs index fea28e01..3c853c01 100644 --- a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs +++ b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs @@ -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.Net.Http; using Crestron.SimplSharp.WebScripting; @@ -30,12 +36,6 @@ using PepperDash.Essentials.RoomBridges; using PepperDash.Essentials.Services; using PepperDash.Essentials.WebApiHandlers; 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; namespace PepperDash.Essentials @@ -582,7 +582,7 @@ namespace PepperDash.Essentials { this.LogVerbose( "Adding ISetTopBoxControlMessenger for {deviceKey}" - ); + ); var messenger = new ISetTopBoxControlsMessenger( $"{device.Key}-stb-{Key}", @@ -599,7 +599,7 @@ namespace PepperDash.Essentials { this.LogVerbose( "Adding IChannelMessenger for {deviceKey}", device.Key - ); + ); var messenger = new IChannelMessenger( $"{device.Key}-channel-{Key}", @@ -614,7 +614,7 @@ namespace PepperDash.Essentials if (device is IColor colorDevice) { - this.LogVerbose("Adding IColorMessenger for {deviceKey}", device.Key); + this.LogVerbose("Adding IColorMessenger for {deviceKey}", device.Key); var messenger = new IColorMessenger( $"{device.Key}-color-{Key}", @@ -629,7 +629,7 @@ namespace PepperDash.Essentials if (device is IDPad dPadDevice) { - this.LogVerbose("Adding IDPadMessenger for {deviceKey}", device.Key); + this.LogVerbose("Adding IDPadMessenger for {deviceKey}", device.Key); var messenger = new IDPadMessenger( $"{device.Key}-dPad-{Key}", @@ -644,7 +644,7 @@ namespace PepperDash.Essentials if (device is INumericKeypad nkDevice) { - this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key); + this.LogVerbose("Adding INumericKeyapdMessenger for {deviceKey}", device.Key); var messenger = new INumericKeypadMessenger( $"{device.Key}-numericKeypad-{Key}", @@ -659,7 +659,7 @@ namespace PepperDash.Essentials if (device is IHasPowerControl pcDevice) { - this.LogVerbose("Adding IHasPowerControlMessenger for {deviceKey}", device.Key); + this.LogVerbose("Adding IHasPowerControlMessenger for {deviceKey}", device.Key); var messenger = new IHasPowerMessenger( $"{device.Key}-powerControl-{Key}", @@ -693,7 +693,7 @@ namespace PepperDash.Essentials { this.LogVerbose( "Adding ITransportMessenger for {deviceKey}", device.Key - ); + ); var messenger = new ITransportMessenger( $"{device.Key}-transport-{Key}", @@ -721,6 +721,15 @@ namespace PepperDash.Essentials 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) { this.LogVerbose( @@ -2309,7 +2318,7 @@ Mobile Control Direct Server Infromation: { this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type); break; - } + } foreach (var handler in handlers) {