Compare commits

..

3 Commits

Author SHA1 Message Date
Andrew Welker
9a18bfd816 Merge branch 'main' into mc-connect-logging 2025-09-17 11:41:23 -05:00
Andrew Welker
557e39f2f2 fix: CS LAN fixes 2025-09-17 11:38:20 -05:00
Andrew Welker
7c6aa1c0ff fix: set file log level for debugging 2025-09-15 11:02:06 -05:00
6 changed files with 71 additions and 125 deletions

View File

@@ -103,12 +103,6 @@ namespace PepperDash.Essentials.Core
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to hide this scenario in the UI.
/// </summary>
[JsonProperty("hideInUi", NullValueHandling = NullValueHandling.Ignore)]
public bool HideInUi { get; set; }
/// <summary>
/// Gets or sets the collection of partition states.
/// </summary>

View File

@@ -109,12 +109,6 @@ namespace PepperDash.Essentials.Core
[JsonProperty("isActive")]
bool IsActive { get; }
/// <summary>
/// Gets a value indicating whether this scenario should be hidden in the UI.
/// </summary>
[JsonProperty("hideInUi")]
bool HideInUi { get; }
/// <summary>
/// Activates this room combination scenario
/// </summary>

View File

@@ -14,40 +14,18 @@ namespace PepperDash.Essentials.Core
{
private RoomCombinationScenarioConfig _config;
/// <summary>
/// Gets or sets the key associated with the object.
/// </summary>
[JsonProperty("key")]
public string Key { get; set; }
/// <summary>
/// Gets or sets the name associated with the object.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets a value indicating whether to hide this scenario in the UI.
/// </summary>
///
[JsonProperty("hideInUi")]
public bool HideInUi
{
get { return _config.HideInUi; }
}
[JsonProperty("partitionStates")]
/// <summary>
/// Gets or sets the PartitionStates
/// </summary>
///
[JsonProperty("partitionStates")]
public List<PartitionState> PartitionStates { get; private set; }
/// <summary>
/// Determines which UI devices get mapped to which room in this scenario. The Key should be the key of the UI device and the Value should be the key of the room to map to
/// </summary>
[JsonProperty("uiMap")]
public Dictionary<string, string> UiMap { get; set; }

View File

@@ -1,10 +1,9 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Core.Logging;
using PepperDash.Essentials.Core;
using System;
namespace PepperDash.Essentials.AppServer.Messengers
{
@@ -13,46 +12,35 @@ namespace PepperDash.Essentials.AppServer.Messengers
/// </summary>
public class DeviceVolumeMessenger : MessengerBase
{
private readonly IBasicVolumeControls device;
private readonly IBasicVolumeWithFeedback _localDevice;
/// <summary>
/// Initializes a new instance of the <see cref="DeviceVolumeMessenger"/> class.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="messagePath">The message path.</param>
/// <param name="device">The device.</param>
public DeviceVolumeMessenger(string key, string messagePath, IBasicVolumeControls device)
public DeviceVolumeMessenger(string key, string messagePath, IBasicVolumeWithFeedback device)
: base(key, messagePath, device as IKeyName)
{
this.device = device;
_localDevice = device;
}
private void SendStatus(string id = null)
private void SendStatus()
{
try
{
if (!(device is IBasicVolumeWithFeedback feedbackDevice))
{
return;
}
var messageObj = new VolumeStateMessage
{
Volume = new Volume
{
Level = feedbackDevice?.VolumeLevelFeedback.IntValue ?? -1,
Muted = feedbackDevice?.MuteFeedback.BoolValue ?? false,
Level = _localDevice?.VolumeLevelFeedback.IntValue ?? -1,
Muted = _localDevice?.MuteFeedback.BoolValue ?? false,
HasMute = true, // assume all devices have mute for now
}
};
if (device is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
if (_localDevice is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
{
messageObj.Volume.RawValue = volumeAdvanced.RawVolumeLevel.ToString();
messageObj.Volume.Units = volumeAdvanced.Units;
}
PostStatusMessage(messageObj, id);
PostStatusMessage(messageObj);
}
catch (Exception ex)
{
@@ -65,23 +53,44 @@ namespace PepperDash.Essentials.AppServer.Messengers
protected override void RegisterActions()
{
AddAction("/volumeUp", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Calling {localDevice} volume up with {value}", DeviceKey, b);
try
{
device.VolumeUp(b);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Got exception during volume up: {Exception}", null, ex);
}
}));
AddAction("/fullStatus", (id, content) => SendStatus());
AddAction("/level", (id, content) =>
{
var volume = content.ToObject<MobileControlSimpleContent<ushort>>();
_localDevice.SetVolume(volume.Value);
});
AddAction("/muteToggle", (id, content) =>
{
device.MuteToggle();
});
{
_localDevice.MuteToggle();
});
AddAction("/muteOn", (id, content) =>
{
_localDevice.MuteOn();
});
AddAction("/muteOff", (id, content) =>
{
_localDevice.MuteOff();
});
AddAction("/volumeUp", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, "Calling {localDevice} volume up with {value}", DeviceKey, b);
try
{
_localDevice.VolumeUp(b);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Got exception during volume up: {Exception}", null, ex);
}
}));
AddAction("/volumeDown", (id, content) => PressAndHoldHandler.HandlePressAndHold(DeviceKey, content, (b) =>
{
@@ -89,7 +98,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
try
{
device.VolumeDown(b);
_localDevice.VolumeDown(b);
}
catch (Exception ex)
{
@@ -97,38 +106,7 @@ namespace PepperDash.Essentials.AppServer.Messengers
}
}));
if (!(device is IBasicVolumeWithFeedback feedback))
{
this.LogDebug("Skipping feedback methods for {deviceKey}", (device as IKeyName)?.Key);
return;
}
AddAction("/fullStatus", (id, content) => SendStatus(id));
AddAction("/volumeStatus", (id, content) => SendStatus(id));
AddAction("/level", (id, content) =>
{
var volume = content.ToObject<MobileControlSimpleContent<ushort>>();
feedback.SetVolume(volume.Value);
});
AddAction("/muteOn", (id, content) =>
{
feedback.MuteOn();
});
AddAction("/muteOff", (id, content) =>
{
feedback.MuteOff();
});
feedback.MuteFeedback.OutputChange += (sender, args) =>
_localDevice.MuteFeedback.OutputChange += (sender, args) =>
{
PostStatusMessage(JToken.FromObject(
new
@@ -141,10 +119,10 @@ namespace PepperDash.Essentials.AppServer.Messengers
);
};
feedback.VolumeLevelFeedback.OutputChange += (sender, args) =>
_localDevice.VolumeLevelFeedback.OutputChange += (sender, args) =>
{
var rawValue = "";
if (feedback is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
if (_localDevice is IBasicVolumeWithFeedbackAdvanced volumeAdvanced)
{
rawValue = volumeAdvanced.RawVolumeLevel.ToString();
}
@@ -160,6 +138,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
PostStatusMessage(JToken.FromObject(message));
};
}
#endregion

View File

@@ -244,13 +244,15 @@ namespace PepperDash.Essentials
CrestronEnvironment.ProgramStatusEventHandler +=
CrestronEnvironment_ProgramStatusEventHandler;
ApiOnlineAndAuthorized = new BoolFeedback(() =>
ApiOnlineAndAuthorized = new BoolFeedback("apiOnlineAndAuthorized", () =>
{
if (_wsClient2 == null)
return false;
return _wsClient2.IsAlive && IsAuthorized;
});
Debug.SetFileMinimumDebugLevel(Serilog.Events.LogEventLevel.Debug);
}
private void SetupDefaultRoomMessengers()
@@ -486,15 +488,15 @@ namespace PepperDash.Essentials
messengerAdded = true;
}
if (device is IBasicVolumeControls)
if (device is IBasicVolumeWithFeedback)
{
var deviceKey = device.Key;
this.LogVerbose(
"Adding IBasicVolumeControls for {deviceKey}",
"Adding IBasicVolumeControlWithFeedback for {deviceKey}",
deviceKey
);
var volControlDevice = device as IBasicVolumeControls;
var volControlDevice = device as IBasicVolumeWithFeedback;
var messenger = new DeviceVolumeMessenger(
$"{device.Key}-volume-{Key}",
string.Format("/device/{0}", deviceKey),
@@ -1917,7 +1919,8 @@ namespace PepperDash.Essentials
/// <param name="e"></param>
private void HandleError(object sender, ErrorEventArgs e)
{
this.LogError("Websocket error {0}", e.Message);
this.LogError("Websocket error {message}", e.Message);
this.LogError(e.Exception, "Websocket error");
IsAuthorized = false;
StartServerReconnectTimer();
@@ -1930,7 +1933,7 @@ namespace PepperDash.Essentials
/// <param name="e"></param>
private void HandleClose(object sender, CloseEventArgs e)
{
this.LogDebug(
this.LogInformation(
"Websocket close {code} {reason}, clean={wasClean}",
e.Code,
e.Reason,

View File

@@ -16,7 +16,6 @@ using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.DeviceInfo;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.UI;
using Serilog.Events;
using Feedback = PepperDash.Essentials.Core.Feedback;
namespace PepperDash.Essentials.Touchpanel
@@ -191,6 +190,12 @@ namespace PepperDash.Essentials.Touchpanel
RegisterForExtenders();
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Appliance)
{
this.LogInformation("Not running on processor. Skipping CS LAN Configuration");
return;
}
try
{
var csAdapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetCSAdapter);
@@ -202,15 +207,7 @@ namespace PepperDash.Essentials.Touchpanel
}
catch (ArgumentException)
{
Debug.LogInformation("This processor does not have a CS LAN", this);
}
catch (InvalidOperationException)
{
Debug.LogInformation("This processor does not have a CS LAN", this);
}
catch (Exception ex)
{
Debug.LogError($"Unexpected exception when checking CS LAN: {ex}", this);
this.LogInformation("This processor does not have a CS LAN");
}
}
@@ -452,7 +449,7 @@ namespace PepperDash.Essentials.Touchpanel
var processorIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, lanAdapterId);
if(csIpAddress == null || csSubnetMask == null || url == null)
if (csIpAddress == null || csSubnetMask == null || url == null)
{
this.LogWarning("CS IP Address Subnet Mask or url is null, cannot determine correct IP for URL");
return url;
@@ -518,7 +515,7 @@ namespace PepperDash.Essentials.Touchpanel
_bridge.UserCodeChanged += UpdateFeedbacks;
_bridge.AppUrlChanged += (s, a) =>
{
this.LogInformation("AppURL changed: {appURL}", _bridge.AppUrl);
this.LogInformation("AppURL changed");
SetAppUrl(_bridge.AppUrl);
UpdateFeedbacks(s, a);
};