mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-07 00:35:07 +00:00
Merge branch 'main' into feature/add-IHasCamerasMessenger
This commit is contained in:
@@ -2,27 +2,69 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.DeviceInfo;
|
||||
using System.Timers;
|
||||
|
||||
namespace PepperDash.Essentials.AppServer.Messengers
|
||||
{
|
||||
/// <summary>
|
||||
/// Facilitates communication of device information by providing mechanisms for status updates and device
|
||||
/// information reporting.
|
||||
/// </summary>
|
||||
/// <remarks>The <see cref="DeviceInfoMessenger"/> class integrates with an <see
|
||||
/// cref="IDeviceInfoProvider"/> 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.</remarks>
|
||||
public class DeviceInfoMessenger : MessengerBase
|
||||
{
|
||||
private readonly IDeviceInfoProvider _deviceInfoProvider;
|
||||
|
||||
private readonly Timer debounceTimer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeviceInfoMessenger"/> class, which facilitates communication
|
||||
/// of device information.
|
||||
/// </summary>
|
||||
/// <remarks>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.</remarks>
|
||||
/// <param name="key">A unique identifier for the messenger instance.</param>
|
||||
/// <param name="messagePath">The path used for sending and receiving messages.</param>
|
||||
/// <param name="device">An implementation of <see cref="IDeviceInfoProvider"/> that provides device-specific information.</param>
|
||||
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
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers actions and event handlers for device information updates and status reporting.
|
||||
/// </summary>
|
||||
/// <remarks>This method sets up actions for handling device status updates and reporting full
|
||||
/// device status. It also subscribes to the <see cref="IDeviceInfoProvider.DeviceInfoChanged"/> event to
|
||||
/// trigger debounced updates when the device information changes.</remarks>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a message containing the state information of a device, including detailed device information.
|
||||
/// </summary>
|
||||
/// <remarks>This class is used to encapsulate the state of a device along with its associated
|
||||
/// information. It extends <see cref="DeviceStateMessageBase"/> to provide additional details about the
|
||||
/// device.</remarks>
|
||||
public class DeviceInfoStateMessage : DeviceStateMessageBase
|
||||
{
|
||||
[JsonProperty("deviceInfo")]
|
||||
|
||||
@@ -8,16 +8,42 @@ using System.Collections.Generic;
|
||||
|
||||
namespace PepperDash.Essentials.AppServer.Messengers
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides messaging functionality for managing room combination scenarios and partition states in an <see
|
||||
/// cref="IEssentialsRoomCombiner"/> instance. Enables external systems to interact with the room combiner via
|
||||
/// predefined actions and status updates.
|
||||
/// </summary>
|
||||
/// <remarks>This class facilitates communication with an <see cref="IEssentialsRoomCombiner"/> by
|
||||
/// exposing actions for toggling modes, managing partitions, and setting room combination scenarios. It also
|
||||
/// listens for feedback changes and broadcasts status updates to connected systems. Typical usage involves
|
||||
/// registering actions for external commands and handling feedback events to synchronize state changes.</remarks>
|
||||
public class IEssentialsRoomCombinerMessenger : MessengerBase
|
||||
{
|
||||
private readonly IEssentialsRoomCombiner _roomCombiner;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IEssentialsRoomCombinerMessenger"/> class, which facilitates
|
||||
/// messaging for an <see cref="IEssentialsRoomCombiner"/> instance.
|
||||
/// </summary>
|
||||
/// <remarks>This class is designed to enable communication and interaction with an <see
|
||||
/// cref="IEssentialsRoomCombiner"/> through the specified messaging path. Ensure that the <paramref
|
||||
/// name="roomCombiner"/> parameter is not null when creating an instance.</remarks>
|
||||
/// <param name="key">The unique key identifying this messenger instance.</param>
|
||||
/// <param name="messagePath">The path used for messaging operations.</param>
|
||||
/// <param name="roomCombiner">The <see cref="IEssentialsRoomCombiner"/> instance associated with this messenger.</param>
|
||||
public IEssentialsRoomCombinerMessenger(string key, string messagePath, IEssentialsRoomCombiner roomCombiner)
|
||||
: base(key, messagePath, roomCombiner as IKeyName)
|
||||
{
|
||||
_roomCombiner = roomCombiner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers actions and event handlers for managing room combination scenarios and partition states.
|
||||
/// </summary>
|
||||
/// <remarks>This method sets up various actions that can be triggered via specific endpoints,
|
||||
/// such as toggling modes, setting room combination scenarios, and managing partition states. It also
|
||||
/// subscribes to feedback events to update the status when changes occur in room combination scenarios or
|
||||
/// partition states.</remarks>
|
||||
protected override void RegisterActions()
|
||||
{
|
||||
AddAction("/fullStatus", (id, content) => SendFullStatus());
|
||||
@@ -107,6 +133,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
|
||||
var message = new IEssentialsRoomCombinerStateMessage
|
||||
{
|
||||
DisableAutoMode = _roomCombiner.DisableAutoMode,
|
||||
IsInAutoMode = _roomCombiner.IsInAutoMode,
|
||||
CurrentScenario = _roomCombiner.CurrentScenario,
|
||||
Rooms = rooms,
|
||||
@@ -132,20 +159,48 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the state message for a room combiner system, providing information about the current configuration,
|
||||
/// operational mode, and associated rooms, partitions, and scenarios.
|
||||
/// </summary>
|
||||
/// <remarks>This class is used to encapsulate the state of a room combiner system, including its current
|
||||
/// mode of operation, active room combination scenario, and the list of rooms and partitions involved. It is
|
||||
/// typically serialized and transmitted to communicate the state of the system.</remarks>
|
||||
public class IEssentialsRoomCombinerStateMessage : DeviceStateMessageBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether automatic mode is disabled.
|
||||
/// </summary>
|
||||
[JsonProperty("disableAutoMode", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool DisableAutoMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the system is operating in automatic mode.
|
||||
/// </summary>
|
||||
[JsonProperty("isInAutoMode", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool IsInAutoMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current room combination scenario.
|
||||
/// </summary>
|
||||
[JsonProperty("currentScenario", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IRoomCombinationScenario CurrentScenario { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of rooms associated with the entity.
|
||||
/// </summary>
|
||||
[JsonProperty("rooms", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<IKeyName> Rooms { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of room combination scenarios.
|
||||
/// </summary>
|
||||
[JsonProperty("roomCombinationScenarios", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of partition controllers.
|
||||
/// </summary>
|
||||
[JsonProperty("partitions", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<IPartitionController> Partitions { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user