update to new plugin factory method

This commit is contained in:
Andrew Welker
2020-08-20 10:40:28 -06:00
parent d590987143
commit 07019ad6d8
3 changed files with 69 additions and 65 deletions

View File

@@ -1,52 +0,0 @@
using System;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharpPro; // For Basic SIMPL#Pro classes
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Essentials;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Core;
namespace EssentialsPluginTemplateEPI
{
/// <summary>
/// This class contains the necessary properties and static methods required to function as an Essentials Plugin
/// </summary>
public class EssentialsPluginFactory
{
/// <summary>
/// This string is used to define the minimum version of the
/// Essentials Framework required for this plugin
/// </summary>
public static string MinimumEssentialsFrameworkVersion = "1.4.31";
/// <summary>
/// This method will get called by Essentials when this plugin is loaded.
/// Use it to add factory methods for all new Device types defined in this plugin
/// </summary>
public static void LoadPlugin()
{
PepperDash.Essentials.Core.DeviceFactory.AddFactoryForType("EssentialsPluginTemplate", EssentialsPluginFactory.BuildDevice);
// Add additional factories for each type here
}
/// <summary>
/// Builds an instance of the device type. There should be method like this defined for each device type your plugin needs
/// to be able to build
/// </summary>
/// <param name="dc">The device configuration</param>
/// <returns>The device</returns>
public static EssentialsPluginTemplateDevice BuildDevice(DeviceConfig dc)
{
var config = JsonConvert.DeserializeObject<EssentialsPluginTemplatePropertiesConfig>(dc.Properties.ToString());
var newDevice = new EssentialsPluginTemplateDevice(dc.Key, dc.Name, config);
return newDevice;
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharpPro; // For Basic SIMPL#Pro classes
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Essentials;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Core;
namespace EssentialsPluginTemplateEPI
{
/// <summary>
/// This class contains the necessary properties and methods required to function as an Essentials Plugin
/// </summary>
public class EssentialsPluginFactory:EssentialsPluginDeviceFactory<EssentialsPluginTemplateDevice>
{
public EssentialsPluginFactory()
{
// This string is used to define the minimum version of the
// Essentials Framework required for this plugin
MinimumEssentialsFrameworkVersion = "1.6.1";
//The strings defined in this list will be used in the configuration file to build the device in this plugin.
TypeNames = new List<string> {"essentialsPluginTemplateDevice"};
}
#region Overrides of EssentialsDeviceFactory<EssentialsPluginTemplateDevice>
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
var config = dc.Properties.ToObject<EssentialsPluginTemplatePropertiesConfig>();
var newDevice = new EssentialsPluginTemplateDevice(dc.Key, dc.Name, config);
return newDevice;
}
#endregion
}
}

View File

@@ -1,22 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Essentials;
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PDT.EssentialsPluginTemplate.EPI;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Core;
using PepperDash.Essentials.Bridges;
namespace EssentialsPluginTemplateEPI
{
/// <summary>
/// Example of a plugin device
/// </summary>
public class EssentialsPluginTemplateDevice : Device, IBridge
public class EssentialsPluginTemplateDevice : EssentialsDevice, IBridgeAdvanced
{
/// <summary>
/// Device Constructor. Called by BuildDevice
@@ -46,9 +40,28 @@ namespace EssentialsPluginTemplateEPI
/// <param name="trilist"></param>
/// <param name="joinStart"></param>
/// <param name="joinMapKey"></param>
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey)
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
this.LinkToApi(trilist, joinStart, joinMapKey);
// Construct the default join map
var joinMap = new EssentialsPluginTemplateBridgeJoinMap(joinStart);
// Attempt to get a custom join map if specified in config
var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);
// If we find a custom join map, deserialize it
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<EssentialsPluginTemplateBridgeJoinMap>(joinMapSerialized);
//Checking if the bridge is null allows for backwards compatability with configurations that use EiscApi instead of EiscApiAdvanced
if (bridge != null)
{
bridge.AddJoinMap(Key, joinMap);
}
// Set all your join actions here
// Link all your feedbacks to joins here
}
}
}