mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +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
|
|
@ -393,16 +393,19 @@ public class DeviceActionWrapper
|
|||
/// <summary>
|
||||
/// The key of the device to call the method on
|
||||
/// </summary>
|
||||
[JsonProperty("deviceKey")]
|
||||
public string DeviceKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the method to call
|
||||
/// </summary>
|
||||
[JsonProperty("methodName")]
|
||||
public string MethodName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parameters to pass to the method. This should be an array of objects matching the parameters of the method being called. If the method has no parameters, this can be omitted or set to null.
|
||||
/// </summary>
|
||||
[JsonProperty("params")]
|
||||
public object[] Params { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -242,6 +242,12 @@ namespace PepperDash.Essentials
|
|||
|
||||
AddPreActivationAction(() => LinkSystemMonitorToAppServer());
|
||||
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
var actionMessenger = new DeviceActionMessenger("deviceActionMessenger-" + Key, "/action");
|
||||
AddDeviceMessenger(actionMessenger);
|
||||
});
|
||||
|
||||
AddPreActivationAction(() => AddWebApiPaths());
|
||||
|
||||
AddPreActivationAction(() =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue