Merge pull request #1203 from PepperDash/feature-2.0.0/bridge-issues

fix: joins in join maps get added correctly to a bridge
This commit is contained in:
Andrew Welker
2024-10-30 13:27:25 -05:00
committed by GitHub
6 changed files with 139 additions and 143 deletions

View File

@@ -18,81 +18,6 @@ using Serilog.Events;
namespace PepperDash.Essentials.Core.Bridges namespace PepperDash.Essentials.Core.Bridges
{ {
/// <summary>
/// Helper methods for bridges
/// </summary>
public static class BridgeHelper
{
public static void PrintJoinMap(string command)
{
var targets = command.Split(' ');
var bridgeKey = targets[0].Trim();
var bridge = DeviceManager.GetDeviceForKey(bridgeKey) as EiscApiAdvanced;
if (bridge == null)
{
Debug.LogMessage(LogEventLevel.Information, "Unable to find advanced bridge with key: '{0}'", bridgeKey);
return;
}
if (targets.Length > 1)
{
var deviceKey = targets[1].Trim();
if (string.IsNullOrEmpty(deviceKey)) return;
bridge.PrintJoinMapForDevice(deviceKey);
}
else
{
bridge.PrintJoinMaps();
}
}
public static void JoinmapMarkdown(string command)
{
var targets = command.Split(' ');
var bridgeKey = targets[0].Trim();
var bridge = DeviceManager.GetDeviceForKey(bridgeKey) as EiscApiAdvanced;
if (bridge == null)
{
Debug.LogMessage(LogEventLevel.Information, "Unable to find advanced bridge with key: '{0}'", bridgeKey);
return;
}
if (targets.Length > 1)
{
var deviceKey = targets[1].Trim();
if (string.IsNullOrEmpty(deviceKey)) return;
bridge.MarkdownJoinMapForDevice(deviceKey, bridgeKey);
}
else
{
bridge.MarkdownForBridge(bridgeKey);
}
}
}
/// <summary>
/// Base class for all bridge class variants
/// </summary>
public class BridgeBase : EssentialsDevice
{
public BridgeApi Api { get; protected set; }
public BridgeBase(string key) :
base(key)
{
}
}
/// <summary> /// <summary>
/// Base class for bridge API variants /// Base class for bridge API variants
/// </summary> /// </summary>
@@ -168,19 +93,15 @@ namespace PepperDash.Essentials.Core.Bridges
Debug.LogMessage(LogEventLevel.Debug, this, "Linking Device: '{0}'", device.Key); Debug.LogMessage(LogEventLevel.Debug, this, "Linking Device: '{0}'", device.Key);
if (!typeof(IBridgeAdvanced).IsAssignableFrom(device.GetType().GetType())) if (device is IBridgeAdvanced bridge)
{ {
Debug.LogMessage(LogEventLevel.Information, this, bridge.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this);
"{0} is not compatible with this bridge type. Please use 'eiscapi' instead, or updae the device.",
device.Key);
continue; continue;
} }
var bridge = device as IBridgeAdvanced; Debug.LogMessage(LogEventLevel.Information, this,
if (bridge != null) "{0} is not compatible with this bridge type. Please use 'eiscapi' instead, or updae the device.",
{ device.Key);
bridge.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this);
}
} }
} }
@@ -249,11 +170,11 @@ namespace PepperDash.Essentials.Core.Bridges
/// </summary> /// </summary>
public virtual void PrintJoinMaps() public virtual void PrintJoinMaps()
{ {
Debug.LogMessage(LogEventLevel.Information, this, "Join Maps for EISC IPID: {0}", Eisc.ID.ToString("X")); CrestronConsole.ConsoleCommandResponse("Join Maps for EISC IPID: {0}\r\n", Eisc.ID.ToString("X"));
foreach (var joinMap in JoinMaps) foreach (var joinMap in JoinMaps)
{ {
Debug.LogMessage(LogEventLevel.Information, "Join map for device '{0}':", joinMap.Key); CrestronConsole.ConsoleCommandResponse("Join map for device '{0}':", joinMap.Key);
joinMap.Value.PrintJoinMapInfo(); joinMap.Value.PrintJoinMapInfo();
} }
} }

View File

@@ -0,0 +1,66 @@
using PepperDash.Core;
using Serilog.Events;
//using PepperDash.Essentials.Devices.Common.Cameras;
namespace PepperDash.Essentials.Core.Bridges
{
/// <summary>
/// Helper methods for bridges
/// </summary>
public static class BridgeHelper
{
public static void PrintJoinMap(string command)
{
var targets = command.Split(' ');
var bridgeKey = targets[0].Trim();
if (!(DeviceManager.GetDeviceForKey(bridgeKey) is EiscApiAdvanced bridge))
{
Debug.LogMessage(LogEventLevel.Information, "Unable to find advanced bridge with key: '{0}'", bridgeKey);
return;
}
if (targets.Length > 1)
{
var deviceKey = targets[1].Trim();
if (string.IsNullOrEmpty(deviceKey)) return;
bridge.PrintJoinMapForDevice(deviceKey);
}
else
{
bridge.PrintJoinMaps();
}
}
public static void JoinmapMarkdown(string command)
{
var targets = command.Split(' ');
var bridgeKey = targets[0].Trim();
var bridge = DeviceManager.GetDeviceForKey(bridgeKey) as EiscApiAdvanced;
if (bridge == null)
{
Debug.LogMessage(LogEventLevel.Information, "Unable to find advanced bridge with key: '{0}'", bridgeKey);
return;
}
if (targets.Length > 1)
{
var deviceKey = targets[1].Trim();
if (string.IsNullOrEmpty(deviceKey)) return;
bridge.MarkdownJoinMapForDevice(deviceKey, bridgeKey);
}
else
{
bridge.MarkdownForBridge(bridgeKey);
}
}
}
}

View File

@@ -206,7 +206,7 @@ namespace PepperDash.Essentials.Core
if (dev == null) if (dev == null)
return "{ \"error\":\"No Device\"}"; return "{ \"error\":\"No Device\"}";
object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null); object prop = dev.GetType().GetProperty(propertyName).GetValue(dev, null);
// var prop = t.GetProperty(propertyName); // var prop = t.GetProperty(propertyName);
if (prop != null) if (prop != null)

View File

@@ -107,19 +107,20 @@ namespace PepperDash.Essentials.Core
} }
protected void AddJoins(Type type) protected void AddJoins(Type type)
{ {
var fields = var fields =
type.GetType() type.GetFields(BindingFlags.Public | BindingFlags.Instance)
.GetFields(BindingFlags.Public | BindingFlags.Instance) .Where(f => f.IsDefined(typeof (JoinNameAttribute), true)).ToList();
.Where(f => f.IsDefined(typeof (JoinNameAttribute), true));
Debug.LogMessage(LogEventLevel.Debug, "Got {fields} with JoinNameAttribute", fields.Count);
foreach (var field in fields) foreach (var field in fields)
{ {
var childClass = Convert.ChangeType(this, type, null); var childClass = Convert.ChangeType(this, type, null);
var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields. //this here is JoinMapBaseAdvanced, not the child class. JoinMapBaseAdvanced has no fields.
if (value == null) if (!(field.GetValue(childClass) is JoinDataComplete value))
{ {
Debug.LogMessage(LogEventLevel.Information, "Unable to cast base class to {0}", type.Name); Debug.LogMessage(LogEventLevel.Information, "Unable to cast base class to {0}", type.Name);
continue; continue;
@@ -129,7 +130,7 @@ namespace PepperDash.Essentials.Core
var joinName = value.GetNameAttribute(field); var joinName = value.GetNameAttribute(field);
if (String.IsNullOrEmpty(joinName)) continue; if (string.IsNullOrEmpty(joinName)) continue;
Joins.Add(joinName, value); Joins.Add(joinName, value);
} }
@@ -155,29 +156,37 @@ namespace PepperDash.Essentials.Core
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
// Get the joins of each type and print them var lineEnding = "\r\n";
sb.AppendLine(String.Format("# {0}", GetType().Name));
sb.AppendLine();
sb.AppendLine("## Digitals");
sb.AppendLine();
// Get the joins of each type and print them
var digitals =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital)
.ToDictionary(j => j.Key, j => j.Value);
var digitalSb = AppendJoinList(GetSortedJoins(digitals));
digitalSb.AppendLine("## Analogs");
digitalSb.AppendLine();
var analogs = var digitals =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog) Joins.Where(j => j.Value.Metadata.JoinType.HasFlag(eJoinType.Digital))
.ToDictionary(j => j.Key, j => j.Value);
var analogs = Joins.Where(j => j.Value.Metadata.JoinType.HasFlag(eJoinType.Analog))
.ToDictionary(j => j.Key, j => j.Value); .ToDictionary(j => j.Key, j => j.Value);
var analogSb = AppendJoinList(GetSortedJoins(analogs));
analogSb.AppendLine("## Serials");
analogSb.AppendLine();
var serials = var serials =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial) Joins.Where(j => j.Value.Metadata.JoinType.HasFlag(eJoinType.Serial))
.ToDictionary(j => j.Key, j => j.Value); .ToDictionary(j => j.Key, j => j.Value);
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, "Digital join count {digitalCount} Analog join count {analogCount} Serial join count {serialCount}", null, digitals.Count, analogs.Count, serials.Count);
// Get the joins of each type and print them
sb.Append($"# {GetType().Name}\r\n");
sb.Append(lineEnding);
sb.Append($"## Digitals{lineEnding}");
sb.Append(lineEnding);
// Get the joins of each type and print them
var digitalSb = AppendJoinList(GetSortedJoins(digitals));
digitalSb.Append($"## Analogs{lineEnding}");
digitalSb.Append(lineEnding);
var analogSb = AppendJoinList(GetSortedJoins(analogs));
analogSb.Append($"## Serials{lineEnding}");
analogSb.Append(lineEnding);
var serialSb = AppendJoinList(GetSortedJoins(serials)); var serialSb = AppendJoinList(GetSortedJoins(serials));
sb.EnsureCapacity(sb.Length + digitalSb.Length + analogSb.Length + serialSb.Length); sb.EnsureCapacity(sb.Length + digitalSb.Length + analogSb.Length + serialSb.Length);
@@ -202,7 +211,7 @@ namespace PepperDash.Essentials.Core
private static void WriteJoinmapMarkdown(StringBuilder stringBuilder, string pluginType, string bridgeKey, string deviceKey) private static void WriteJoinmapMarkdown(StringBuilder stringBuilder, string pluginType, string bridgeKey, string deviceKey)
{ {
var fileName = String.Format("{0}{1}{2}__{3}__{4}.md", Global.FilePathPrefix, "joinMaps/", pluginType, bridgeKey, deviceKey); var fileName = string.Format("{0}{1}{2}__{3}__{4}.md", Global.FilePathPrefix, "joinMaps/", pluginType, bridgeKey, deviceKey);
using (var sw = new StreamWriter(fileName)) using (var sw = new StreamWriter(fileName))
{ {
@@ -230,7 +239,7 @@ namespace PepperDash.Essentials.Core
static StringBuilder AppendJoinList(List<KeyValuePair<string, JoinDataComplete>> joins) static StringBuilder AppendJoinList(List<KeyValuePair<string, JoinDataComplete>> joins)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
const string stringFormatter = "| {0} | {1} | {2} | {3} | {4} |"; const string stringFormatter = "| {0} | {1} | {2} | {3} | {4} |\r\n";
const int joinNumberLen = 11; const int joinNumberLen = 11;
const int joinSpanLen = 9; const int joinSpanLen = 9;
const int typeLen = 19; const int typeLen = 19;
@@ -238,25 +247,25 @@ namespace PepperDash.Essentials.Core
var descriptionLen = (from @join in joins select @join.Value into j select j.Metadata.Description.Length).Concat(new[] {11}).Max(); var descriptionLen = (from @join in joins select @join.Value into j select j.Metadata.Description.Length).Concat(new[] {11}).Max();
//build header //build header
sb.AppendLine(String.Format(stringFormatter, sb.Append(string.Format(stringFormatter,
String.Format("Join Number").PadRight(joinNumberLen, ' '), string.Format("Join Number").PadRight(joinNumberLen, ' '),
String.Format("Join Span").PadRight(joinSpanLen, ' '), string.Format("Join Span").PadRight(joinSpanLen, ' '),
String.Format("Description").PadRight(descriptionLen, ' '), string.Format("Description").PadRight(descriptionLen, ' '),
String.Format("Type").PadRight(typeLen, ' '), string.Format("Type").PadRight(typeLen, ' '),
String.Format("Capabilities").PadRight(capabilitiesLen, ' '))); string.Format("Capabilities").PadRight(capabilitiesLen, ' ')));
//build table seperator //build table seperator
sb.AppendLine(String.Format(stringFormatter, sb.Append(string.Format(stringFormatter,
new String('-', joinNumberLen), new string('-', joinNumberLen),
new String('-', joinSpanLen), new string('-', joinSpanLen),
new String('-', descriptionLen), new string('-', descriptionLen),
new String('-', typeLen), new string('-', typeLen),
new String('-', capabilitiesLen))); new string('-', capabilitiesLen)));
foreach (var join in joins) foreach (var join in joins)
{ {
sb.AppendLine(join.Value.GetMarkdownFormattedData(stringFormatter, descriptionLen)); sb.Append(join.Value.GetMarkdownFormattedData(stringFormatter, descriptionLen));
} }
sb.AppendLine(); sb.Append("\r\n");
return sb; return sb;
} }
@@ -411,10 +420,10 @@ namespace PepperDash.Essentials.Core
{ {
//Fixed Width Headers //Fixed Width Headers
var joinNumberLen = String.Format("Join Number").Length; var joinNumberLen = string.Format("Join Number").Length;
var joinSpanLen = String.Format("Join Span").Length; var joinSpanLen = string.Format("Join Span").Length;
var typeLen = String.Format("AnalogDigitalSerial").Length; var typeLen = string.Format("AnalogDigitalSerial").Length;
var capabilitiesLen = String.Format("ToFromFusion").Length; var capabilitiesLen = string.Format("ToFromFusion").Length;
//Track which one failed, if it did //Track which one failed, if it did
const string placeholder = "unknown"; const string placeholder = "unknown";
@@ -430,13 +439,13 @@ namespace PepperDash.Essentials.Core
try try
{ {
dataArray["joinNumber"] = String.Format("{0}", JoinNumber.ToString(CultureInfo.InvariantCulture).ReplaceIfNullOrEmpty(placeholder)).PadRight(joinNumberLen, ' '); dataArray["joinNumber"] = string.Format("{0}", JoinNumber.ToString(CultureInfo.InvariantCulture).ReplaceIfNullOrEmpty(placeholder)).PadRight(joinNumberLen, ' ');
dataArray["joinSpan"] = String.Format("{0}", JoinSpan.ToString(CultureInfo.InvariantCulture).ReplaceIfNullOrEmpty(placeholder)).PadRight(joinSpanLen, ' '); dataArray["joinSpan"] = string.Format("{0}", JoinSpan.ToString(CultureInfo.InvariantCulture).ReplaceIfNullOrEmpty(placeholder)).PadRight(joinSpanLen, ' ');
dataArray["description"] = String.Format("{0}", Metadata.Description.ReplaceIfNullOrEmpty(placeholder)).PadRight(descriptionLen, ' '); dataArray["description"] = string.Format("{0}", Metadata.Description.ReplaceIfNullOrEmpty(placeholder)).PadRight(descriptionLen, ' ');
dataArray["joinType"] = String.Format("{0}", Metadata.JoinType.ToString().ReplaceIfNullOrEmpty(placeholder)).PadRight(typeLen, ' '); dataArray["joinType"] = string.Format("{0}", Metadata.JoinType.ToString().ReplaceIfNullOrEmpty(placeholder)).PadRight(typeLen, ' ');
dataArray["capabilities"] = String.Format("{0}", Metadata.JoinCapabilities.ToString().ReplaceIfNullOrEmpty(placeholder)).PadRight(capabilitiesLen, ' '); dataArray["capabilities"] = string.Format("{0}", Metadata.JoinCapabilities.ToString().ReplaceIfNullOrEmpty(placeholder)).PadRight(capabilitiesLen, ' ');
return String.Format(stringFormatter, return string.Format(stringFormatter,
dataArray["joinNumber"], dataArray["joinNumber"],
dataArray["joinSpan"], dataArray["joinSpan"],
dataArray["description"], dataArray["description"],
@@ -454,8 +463,8 @@ namespace PepperDash.Essentials.Core
errorKey = item.Key; errorKey = item.Key;
break; break;
} }
Debug.LogMessage(LogEventLevel.Information, "Unable to decode join metadata {1}- {0}", e.Message, !String.IsNullOrEmpty(errorKey) ? (' ' + errorKey) : String.Empty); Debug.LogMessage(LogEventLevel.Information, "Unable to decode join metadata {1}- {0}", e.Message, !string.IsNullOrEmpty(errorKey) ? (' ' + errorKey) : string.Empty);
return String.Format(stringFormatter, return string.Format(stringFormatter,
dataArray["joinNumber"], dataArray["joinNumber"],
dataArray["joinSpan"], dataArray["joinSpan"],
dataArray["description"], dataArray["description"],
@@ -520,7 +529,7 @@ namespace PepperDash.Essentials.Core
public JoinNameAttribute(string name) public JoinNameAttribute(string name)
{ {
Debug.LogMessage(LogEventLevel.Verbose, "Setting Attribute Name: {0}", name); Debug.LogMessage(LogEventLevel.Verbose, "Setting Attribute Name: {0}",null, name);
_Name = name; _Name = name;
} }

View File

@@ -42,7 +42,7 @@ namespace PepperDash.Essentials.Devices.Common
public void PrintExpectedIrCommands() public void PrintExpectedIrCommands()
{ {
var cmds = typeof (AppleTvIrCommands).GetType().GetFields(BindingFlags.Public | BindingFlags.Static); var cmds = typeof (AppleTvIrCommands).GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (var value in cmds.Select(cmd => cmd.GetValue(null)).OfType<string>()) foreach (var value in cmds.Select(cmd => cmd.GetValue(null)).OfType<string>())
{ {

View File

@@ -1214,7 +1214,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
var entryIndex = counterIndex; var entryIndex = counterIndex;
Debug.LogMessage(LogEventLevel.Verbose, this, "Entry{2:0000} Name: {0}, Folder ID: {1}, Type: {3}, ParentFolderId: {4}", Debug.LogMessage(LogEventLevel.Verbose, this, "Entry{2:0000} Name: {0}, Folder ID: {1}, Type: {3}, ParentFolderId: {4}",
entry.Name, entry.FolderId, entryIndex, entry.GetType().GetType().FullName, entry.ParentFolderId); entry.Name, entry.FolderId, entryIndex, entry.GetType().FullName, entry.ParentFolderId);
if (entry is DirectoryFolder) if (entry is DirectoryFolder)
{ {