From 3137796335de18e895b8b68c822fff5319bcc935 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 19 May 2026 14:43:02 -0600 Subject: [PATCH] fix: improve error logging for routing devices and ports; ensure API server initializes correctly --- src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs | 8 ++++---- src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs | 9 ++++++++- src/PepperDash.Essentials/ControlSystem.cs | 7 ++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs b/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs index 606cb603..8ddf7d2a 100644 --- a/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs +++ b/src/PepperDash.Essentials.Core/Routing/TieLineConfig.cs @@ -69,14 +69,14 @@ namespace PepperDash.Essentials.Core.Config // Get the source device if (!(DeviceManager.GetDeviceForKey(SourceKey) is IRoutingOutputs sourceDev)) { - LogError("Routable source not found"); + LogError($"Routable source not found for key '{SourceKey}'"); return null; } // Get the destination device if (!(DeviceManager.GetDeviceForKey(DestinationKey) is IRoutingInputs destDev)) { - LogError("Routable destination not found"); + LogError($"Routable destination not found for key '{DestinationKey}'"); return null; } @@ -85,7 +85,7 @@ namespace PepperDash.Essentials.Core.Config if (sourceOutputPort == null) { - LogError("Source does not contain port"); + LogError($"Source '{SourceKey}' does not contain port '{SourcePort}'"); return null; } @@ -94,7 +94,7 @@ namespace PepperDash.Essentials.Core.Config if (destinationInputPort == null) { - LogError("Destination does not contain port"); + LogError($"Destination '{DestinationKey}' does not contain port '{DestinationPort}'"); return null; } diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index 3cdb8433..0bca27d5 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -19,7 +19,7 @@ namespace PepperDash.Essentials.Core.Web private readonly WebApiServer _debugServer; - + private bool isInitialized; /// @@ -230,6 +230,11 @@ namespace PepperDash.Essentials.Core.Web /// public override void Initialize() { + if (isInitialized) + { + return; + } + AddRoute(new HttpCwsRoute("apiPaths") { Name = "GetPaths", @@ -264,6 +269,8 @@ namespace PepperDash.Essentials.Core.Web _debugServer.Start(); GetPaths(); + + isInitialized = true; } /// diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 47de4d3e..72072ce5 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -140,7 +140,9 @@ namespace PepperDash.Essentials CrestronConsole.AddNewConsoleCommand(DeviceManager.GetRoutingPorts, "getroutingports", "Reports all routing ports, if any. Requires a device key", ConsoleAccessLevelEnum.AccessOperator); - DeviceManager.AddDevice(new EssentialsWebApi("essentialsWebApi", "Essentials Web API")); + + var apiServer = new EssentialsWebApi("essentialsWebApi", "Essentials Web API"); + DeviceManager.AddDevice(apiServer); if (!Debug.DoNotLoadConfigOnNextBoot) { @@ -148,6 +150,9 @@ namespace PepperDash.Essentials return; } + // Init the API server even if we're not loading config to allow for dynamic loading via console command + apiServer.Initialize(); + if (!(bool)preventInitialization) { SystemMonitor.ProgramInitialization.ProgramInitializationComplete = true;