using System.Collections.Generic;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace EssentialsPluginTemplate
{
///
/// Plugin device factory
///
///
/// Rename the class to match the device plugin being developed
///
///
/// "EssentialsPluginFactoryTemplate" renamed to "SamsungMdcFactory"
///
public class EssentialsPluginFactoryTemplate : EssentialsPluginDeviceFactory
{
///
/// Plugin device factory constructor
///
///
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
///
///
///
/// // Set the minimum Essentials Framework Version
/// MinimumEssentialsFrameworkVersion = "1.5.5";
/// // In the constructor we initialize the list with the typenames that will build an instance of this device
#pragma warning disable 1570
/// TypeNames = new List() { "SamsungMdc", "SamsungMdcDisplay" };
#pragma warning restore 1570
///
///
public EssentialsPluginFactoryTemplate()
{
// Set the minimum Essentials Framework Version
// TODO [ ] Update the Essentials minimum framework version which this plugin has been tested against
MinimumEssentialsFrameworkVersion = "1.6.4";
// In the constructor we initialize the list with the typenames that will build an instance of this device
// TODO [ ] Update the TypeNames for the plugin being developed
TypeNames = new List() { "examplePluginDevice" };
}
///
/// Builds and returns an instance of EssentialsPluginDeviceTemplate
///
/// device configuration
/// plugin device or null
///
/// The example provided below takes the device key, name, properties config and the comms device created.
/// Modify the EssetnialsPlugingDeviceTemplate constructor as needed to meet the requirements of the plugin device.
///
///
public override EssentialsDevice BuildDevice(PepperDash.Essentials.Core.Config.DeviceConfig dc)
{
Debug.Console(1, "[{0}] Factory Attempting to create new device from type: {1}", dc.Key, dc.Type);
// get the plugin device properties configuration object & check for null
var propertiesConfig = dc.Properties.ToObject();
if (propertiesConfig == null)
{
Debug.Console(0, "[{0}] Factory: failed to read properties config for {1}", dc.Key, dc.Name);
return null;
}
// TODO [ ] Discuss with Andrew/Neil on recommended best practice
// Method 1
//var username = dc.Properties["control"].Value("tcpSshProperties").Username;
//var password = dc.Properties["control"].Value("tcpSshProperties").Password;
//var method = dc.Properties["control"].Value("method");
// Method 2 - Returns a JValue, has to be casted to string
var username = (string)dc.Properties["control"]["tcpSshProperties"]["username"];
var password = (string)dc.Properties["control"]["tcpSshProperties"]["password"];
var method = (string)dc.Properties["control"]["method"];
// build the plugin device comms & check for null
// TODO { ] As of PepperDash Core 1.0.41, HTTP and HTTPS are not valid eControlMethods and will throw an exception.
var comms = CommFactory.CreateCommForDevice(dc);
if (comms == null)
{
Debug.Console(0, "[{0}] Factory: failed to create comm for {1}", dc.Key, dc.Name);
return null;
}
return new EssentialsPluginDeviceTemplate(dc.Key, dc.Name, propertiesConfig, comms);
}
}
}