diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceInfoMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceInfoMessenger.cs
index ffd58948..c588195e 100644
--- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceInfoMessenger.cs
+++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceInfoMessenger.cs
@@ -2,27 +2,69 @@
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core.DeviceInfo;
+using System.Timers;
namespace PepperDash.Essentials.AppServer.Messengers
{
+ ///
+ /// Facilitates communication of device information by providing mechanisms for status updates and device
+ /// information reporting.
+ ///
+ /// The class integrates with an to manage device-specific information. It uses a debounce timer to limit the
+ /// frequency of updates, ensuring efficient communication. The timer is initialized with a 1-second interval and
+ /// is disabled by default. This class also subscribes to device information change events and provides actions for
+ /// reporting full device status and triggering updates.
public class DeviceInfoMessenger : MessengerBase
{
private readonly IDeviceInfoProvider _deviceInfoProvider;
+
+ private readonly Timer debounceTimer;
+
+ ///
+ /// Initializes a new instance of the class, which facilitates communication
+ /// of device information.
+ ///
+ /// The messenger uses a debounce timer to limit the frequency of certain operations. The
+ /// timer is initialized with a 1-second interval and is disabled by default.
+ /// A unique identifier for the messenger instance.
+ /// The path used for sending and receiving messages.
+ /// An implementation of that provides device-specific information.
public DeviceInfoMessenger(string key, string messagePath, IDeviceInfoProvider device) : base(key, messagePath, device as Device)
{
_deviceInfoProvider = device;
- }
+ debounceTimer = new Timer(1000)
+ {
+ Enabled = false,
+ AutoReset = false
+ };
+
+ debounceTimer.Elapsed += DebounceTimer_Elapsed;
+ }
+
+ private void DebounceTimer_Elapsed(object sender, ElapsedEventArgs e)
+ {
+ PostStatusMessage(JToken.FromObject(new
+ {
+ deviceInfo = _deviceInfoProvider.DeviceInfo
+ }));
+ }
+
+ ///
+ /// Registers actions and event handlers for device information updates and status reporting.
+ ///
+ /// This method sets up actions for handling device status updates and reporting full
+ /// device status. It also subscribes to the event to
+ /// trigger debounced updates when the device information changes.
protected override void RegisterActions()
{
base.RegisterActions();
_deviceInfoProvider.DeviceInfoChanged += (o, a) =>
{
- PostStatusMessage(JToken.FromObject(new
- {
- deviceInfo = a.DeviceInfo
- }));
+ debounceTimer.Stop();
+ debounceTimer.Start();
};
AddAction("/fullStatus", (id, context) => PostStatusMessage(new DeviceInfoStateMessage
@@ -34,6 +76,12 @@ namespace PepperDash.Essentials.AppServer.Messengers
}
}
+ ///
+ /// Represents a message containing the state information of a device, including detailed device information.
+ ///
+ /// This class is used to encapsulate the state of a device along with its associated
+ /// information. It extends to provide additional details about the
+ /// device.
public class DeviceInfoStateMessage : DeviceStateMessageBase
{
[JsonProperty("deviceInfo")]