feat: implement DeviceActionMessenger for executing device actions via JSON API

This commit is contained in:
Neil Dorin 2026-06-16 08:57:31 -06:00
parent 4403e91b79
commit fb0afc8c41
3 changed files with 43 additions and 0 deletions

View file

@ -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; }
}

View file

@ -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);
});
}
}

View file

@ -242,6 +242,12 @@ namespace PepperDash.Essentials
AddPreActivationAction(() => LinkSystemMonitorToAppServer());
AddPreActivationAction(() =>
{
var actionMessenger = new DeviceActionMessenger("deviceActionMessenger-" + Key, "/action");
AddDeviceMessenger(actionMessenger);
});
AddPreActivationAction(() => AddWebApiPaths());
AddPreActivationAction(() =>