mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 19:08:29 +00:00
feat: implement DeviceActionMessenger for executing device actions via JSON API
This commit is contained in:
parent
4403e91b79
commit
fb0afc8c41
3 changed files with 43 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue