mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +00:00
34 lines
904 B
C#
34 lines
904 B
C#
using Newtonsoft.Json.Linq;
|
|
using PepperDash.Core;
|
|
using PepperDash.Core.Logging;
|
|
using PepperDash.Essentials.Core;
|
|
|
|
namespace PepperDash.Essentials.AppServer.Messengers;
|
|
|
|
/// <summary>
|
|
/// Messenger that accepts generic device actions at /action/executeAction
|
|
/// and executes them using DeviceJsonApi.DoDeviceAction
|
|
/// </summary>
|
|
public class DeviceActionMessenger : MessengerBase
|
|
{
|
|
public DeviceActionMessenger(string key, string messagePath)
|
|
: base(key, messagePath)
|
|
{
|
|
}
|
|
|
|
protected override void RegisterActions()
|
|
{
|
|
AddAction("/executeAction", (id, content) =>
|
|
{
|
|
var action = content.ToObject<DeviceActionWrapper>();
|
|
|
|
if (action == null)
|
|
{
|
|
this.LogWarning("Received null DeviceActionWrapper");
|
|
return;
|
|
}
|
|
|
|
DeviceJsonApi.DoDeviceAction(action);
|
|
});
|
|
}
|
|
}
|