From b689c847fb1afe6653d5c0f6e2e68705325dbe0b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 11:14:54 -0600 Subject: [PATCH] fix: invert interface to be custom instead of default This way, existing rooms and devices will build messengers by default, while new plugins can implement their own messengers --- .../DeviceTypeInterfaces/IMobileControl.cs | 4 ++-- .../Devices/EssentialsDevice.cs | 14 ++++++++++++++ src/PepperDash.Essentials/ControlSystem.cs | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 80e9cc8c..5e46f17f 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -6,9 +6,9 @@ using PepperDash.Core; namespace PepperDash.Essentials.Core.DeviceTypeInterfaces { /// - /// Use this interface on a device or room if it should use default Mobile Control messengers + /// Use this interface on a device or room if it uses custom Mobile Control messengers /// - public interface IStandardMobileControl : IKeyed + public interface ICustomMobileControl : IKeyed { } diff --git a/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs b/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs index 1846a512..cd9e3923 100644 --- a/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs +++ b/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs @@ -48,6 +48,20 @@ namespace PepperDash.Essentials.Core } }); } + + public override bool CustomActivate() + { + CreateMobileControlMessengers(); + + return base.CustomActivate(); + } + + /// + /// Override this method to build and create custom Mobile Control Messengers during the Activation phase + /// + protected virtual void CreateMobileControlMessengers() { + + } } [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)] diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 7d4281bd..18cee177 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -476,23 +476,23 @@ namespace PepperDash.Essentials var room = Core.DeviceFactory.GetDevice(roomConfig); DeviceManager.AddDevice(room); - if (!(room is IStandardMobileControl)) + if (room is ICustomMobileControl) { continue; } - BuildMC(room as IStandardMobileControl); + BuildMC(room as IEssentialsRoom); } Debug.Console(0, Debug.ErrorLogLevel.Notice, "All Rooms Loaded."); } - private static void BuildMC(IStandardMobileControl room) + private static void BuildMC(IEssentialsRoom room) { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge for "); + Debug.Console(0, Debug.ErrorLogLevel.Notice, $"Attempting to build Mobile Control Bridge for {room?.Key}"); - CreateMobileControlBridge(room as IEssentialsRoom); + CreateMobileControlBridge(room); } private static void CreateMobileControlBridge(IEssentialsRoom room)