diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 9f8022de..5977e3e9 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -290,33 +290,14 @@ namespace PepperDash.Essentials DeviceManager.ActivateAll(); - var mobileControl = DeviceManager.GetDeviceForKey("appServer") as IMobileControl; + var mobileControl = GetMobileControlDevice(); if (mobileControl == null) return; mobileControl.LinkSystemMonitorToAppServer(); - //LinkSystemMonitorToAppServer(); + } - //void LinkSystemMonitorToAppServer() - //{ - // var sysMon = DeviceManager.GetDeviceForKey("systemMonitor") as PepperDash.Essentials.Core.Monitoring.SystemMonitorController; - - // var appServer = DeviceManager.GetDeviceForKey("appServer") as MobileControlSystemController; - - - // if (sysMon != null && appServer != null) - // { - // var key = sysMon.Key + "-" + appServer.Key; - // var messenger = new PepperDash.Essentials.AppServer.Messengers.SystemMonitorMessenger - // (key, sysMon, "/device/systemMonitor"); - - // messenger.RegisterWithAppServer(appServer); - - // DeviceManager.AddDevice(messenger); - // } - //} - /// /// Reads all devices from config and adds them to DeviceManager /// @@ -504,7 +485,7 @@ namespace PepperDash.Essentials private static void CreateMobileControlBridge(EssentialsRoomBase room) { - var mobileControl = DeviceManager.GetDeviceForKey("appServer") as IMobileControl; + var mobileControl = GetMobileControlDevice(); if (mobileControl == null) return; @@ -513,6 +494,26 @@ namespace PepperDash.Essentials Debug.Console(0, Debug.ErrorLogLevel.Notice, "Mobile Control Bridge Added..."); } + private static IMobileControl GetMobileControlDevice() + { + var mobileControlList = DeviceManager.AllDevices.OfType().ToList(); + + if (mobileControlList.Count > 0) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, + "Multiple instances of Mobile Control Server found. Using instance with key {0}", + mobileControlList[0].Key); + } + + if (mobileControlList.Count != 0) + { + return mobileControlList[0]; + } + + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Mobile Control not enabled for this system"); + return null; + } + /// /// Helps add the post activation steps that link bridges to main controller ///