mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: add messenger and event to ICurrentSources
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -582,7 +582,7 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
this.LogVerbose(
|
this.LogVerbose(
|
||||||
"Adding ISetTopBoxControlMessenger for {deviceKey}"
|
"Adding ISetTopBoxControlMessenger for {deviceKey}"
|
||||||
);
|
);
|
||||||
|
|
||||||
var messenger = new ISetTopBoxControlsMessenger(
|
var messenger = new ISetTopBoxControlsMessenger(
|
||||||
$"{device.Key}-stb-{Key}",
|
$"{device.Key}-stb-{Key}",
|
||||||
@@ -599,7 +599,7 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
this.LogVerbose(
|
this.LogVerbose(
|
||||||
"Adding IChannelMessenger for {deviceKey}", device.Key
|
"Adding IChannelMessenger for {deviceKey}", device.Key
|
||||||
);
|
);
|
||||||
|
|
||||||
var messenger = new IChannelMessenger(
|
var messenger = new IChannelMessenger(
|
||||||
$"{device.Key}-channel-{Key}",
|
$"{device.Key}-channel-{Key}",
|
||||||
@@ -614,7 +614,7 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
if (device is IColor colorDevice)
|
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(
|
var messenger = new IColorMessenger(
|
||||||
$"{device.Key}-color-{Key}",
|
$"{device.Key}-color-{Key}",
|
||||||
@@ -629,7 +629,7 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
if (device is IDPad dPadDevice)
|
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(
|
var messenger = new IDPadMessenger(
|
||||||
$"{device.Key}-dPad-{Key}",
|
$"{device.Key}-dPad-{Key}",
|
||||||
@@ -644,7 +644,7 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
if (device is INumericKeypad nkDevice)
|
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(
|
var messenger = new INumericKeypadMessenger(
|
||||||
$"{device.Key}-numericKeypad-{Key}",
|
$"{device.Key}-numericKeypad-{Key}",
|
||||||
@@ -659,7 +659,7 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
if (device is IHasPowerControl pcDevice)
|
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(
|
var messenger = new IHasPowerMessenger(
|
||||||
$"{device.Key}-powerControl-{Key}",
|
$"{device.Key}-powerControl-{Key}",
|
||||||
@@ -693,7 +693,7 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
this.LogVerbose(
|
this.LogVerbose(
|
||||||
"Adding ITransportMessenger for {deviceKey}", device.Key
|
"Adding ITransportMessenger for {deviceKey}", device.Key
|
||||||
);
|
);
|
||||||
|
|
||||||
var messenger = new ITransportMessenger(
|
var messenger = new ITransportMessenger(
|
||||||
$"{device.Key}-transport-{Key}",
|
$"{device.Key}-transport-{Key}",
|
||||||
@@ -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(
|
||||||
@@ -2309,7 +2318,7 @@ Mobile Control Direct Server Infromation:
|
|||||||
{
|
{
|
||||||
this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type);
|
this.LogInformation("-- Warning: Incoming message has no registered handler {type}", message.Type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var handler in handlers)
|
foreach (var handler in handlers)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user