using System.Collections.Generic;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using Crestron.SimplSharpPro.UI;
namespace EssentialsPluginTemplate
{
///
/// Plugin device factory for devices that use IBasicCommunication
///
///
/// Rename the class to match the device plugin being developed
///
///
/// "EssentialsPluginFactoryTemplate" renamed to "MyDeviceFactory"
///
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.6.4;
///
/// In the constructor we initialize the list with the typenames that will build an instance of this device
///
/// TypeNames = new List() { "SamsungMdc", "SamsungMdcDisplay" };
///
///
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;
}
// attempt build the plugin device comms device & 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(1, "[{0}] Factory Notice: No control object present for device {1}", dc.Key, dc.Name);
return null;
}
else
{
return new EssentialsPluginTemplateDevice(dc.Key, dc.Name, propertiesConfig, comms);
}
}
}
///
/// Plugin device factory for logic devices that don't communicate
///
///
/// Rename the class to match the device plugin being developed
///
///
/// "EssentialsPluginFactoryTemplate" renamed to "MyLogicDeviceFactory"
///
public class EssentialsPluginFactoryLogicDeviceTemplate : EssentialsPluginDeviceFactory
{
///
/// Plugin device factory constructor
///
///
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
///
///
/// Set the minimum Essentials Framework Version
///
/// MinimumEssentialsFrameworkVersion = "1.6.4;
///
/// In the constructor we initialize the list with the typenames that will build an instance of this device
///
/// TypeNames = new List() { "SamsungMdc", "SamsungMdcDisplay" };
///
///
public EssentialsPluginFactoryLogicDeviceTemplate()
{
// 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() { "examplePluginLogicDevice" };
}
///
/// Builds and returns an instance of EssentialsPluginTemplateLogicDevice
///
/// 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;
}
var controlConfig = CommFactory.GetControlPropertiesConfig(dc);
if (controlConfig == null)
{
return new EssentialsPluginTemplateLogicDevice(dc.Key, dc.Name, propertiesConfig);
}
else
{
Debug.Console(0, "[{0}] Factory: Unable to get control properties from device config for {1}", dc.Key, dc.Name);
return null;
}
}
}
///
/// Plugin device factory for Crestron wrapper devices
///
///
/// Rename the class to match the device plugin being developed
///
///
/// "EssentialsPluginFactoryTemplate" renamed to "MyCrestronDeviceFactory"
///
public class EssentialsPluginFactoryCrestronDeviceTemplate : EssentialsPluginDeviceFactory
{
///
/// Plugin device factory constructor
///
///
/// Update the MinimumEssentialsFrameworkVersion & TypeNames as needed when creating a plugin
///
///
/// Set the minimum Essentials Framework Version
///
/// MinimumEssentialsFrameworkVersion = "1.6.4;
///
/// In the constructor we initialize the list with the typenames that will build an instance of this device
///
/// TypeNames = new List() { "SamsungMdc", "SamsungMdcDisplay" };
///
///
public EssentialsPluginFactoryCrestronDeviceTemplate()
{
// Set the minimum Essentials Framework Version
// TODO [ ] Update the Essentials minimum framework version which this plugin has been tested against
MinimumEssentialsFrameworkVersion = "1.7.5";
// 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() { "examplePluginCrestronDevice" };
}
///
/// Builds and returns an instance of EssentialsPluginTemplateCrestronDevice
///
/// 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;
}
var controlConfig = CommFactory.GetControlPropertiesConfig(dc);
if (controlConfig == null)
{
var myTouchpanel = new Tsw760(controlConfig.IpIdInt, Global.ControlSystem);
return new EssentialsPluginTemplateCrestronDevice(dc.Key, dc.Name, propertiesConfig, myTouchpanel);
}
else
{
Debug.Console(0, "[{0}] Factory: Unable to get control properties from device config for {1}", dc.Key, dc.Name);
return null;
}
}
}
}