From fb0afc8c412b0724c34d9309ec80cc54b9ca2d61 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 16 Jun 2026 08:57:31 -0600 Subject: [PATCH] feat: implement DeviceActionMessenger for executing device actions via JSON API --- .../Devices/DeviceJsonApi.cs | 3 ++ .../Messengers/DeviceActionMessenger.cs | 34 +++++++++++++++++++ .../MobileControlSystemController.cs | 6 ++++ 3 files changed, 43 insertions(+) create mode 100644 src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceActionMessenger.cs diff --git a/src/PepperDash.Essentials.Core/Devices/DeviceJsonApi.cs b/src/PepperDash.Essentials.Core/Devices/DeviceJsonApi.cs index 6ba640d4..f4de34e4 100644 --- a/src/PepperDash.Essentials.Core/Devices/DeviceJsonApi.cs +++ b/src/PepperDash.Essentials.Core/Devices/DeviceJsonApi.cs @@ -393,16 +393,19 @@ public class DeviceActionWrapper /// /// The key of the device to call the method on /// + [JsonProperty("deviceKey")] public string DeviceKey { get; set; } /// /// The name of the method to call /// + [JsonProperty("methodName")] public string MethodName { get; set; } /// /// 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. /// + [JsonProperty("params")] public object[] Params { get; set; } } diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceActionMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceActionMessenger.cs new file mode 100644 index 00000000..42f95138 --- /dev/null +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DeviceActionMessenger.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json.Linq; +using PepperDash.Core; +using PepperDash.Core.Logging; +using PepperDash.Essentials.Core; + +namespace PepperDash.Essentials.AppServer.Messengers; + +/// +/// Messenger that accepts generic device actions at /action/executeAction +/// and executes them using DeviceJsonApi.DoDeviceAction +/// +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(); + + if (action == null) + { + this.LogWarning("Received null DeviceActionWrapper"); + return; + } + + DeviceJsonApi.DoDeviceAction(action); + }); + } +} diff --git a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs index 5e3314aa..683877fd 100644 --- a/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs +++ b/src/PepperDash.Essentials.MobileControl/MobileControlSystemController.cs @@ -242,6 +242,12 @@ namespace PepperDash.Essentials AddPreActivationAction(() => LinkSystemMonitorToAppServer()); + AddPreActivationAction(() => + { + var actionMessenger = new DeviceActionMessenger("deviceActionMessenger-" + Key, "/action"); + AddDeviceMessenger(actionMessenger); + }); + AddPreActivationAction(() => AddWebApiPaths()); AddPreActivationAction(() =>