diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs index 256b2496..29847144 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorController.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.GeneralIO; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash_Essentials_Core.Bridges.JoinMaps; @@ -18,15 +12,12 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor [Description("Wrapper class for GLS Cresnet Partition Sensor")] public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice { - public GlsPartCn PartitionSensor { get; private set; } + private readonly GlsPartCn _partitionSensor; public StringFeedback NameFeedback { get; private set; } - public BoolFeedback EnableFeedback { get; private set; } - public BoolFeedback PartitionSensedFeedback { get; private set; } public BoolFeedback PartitionNotSensedFeedback { get; private set; } - public IntFeedback SensitivityFeedback { get; private set; } public bool InTestMode { get; private set; } @@ -34,31 +25,6 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public bool TestPartitionSensedFeedback { get; private set; } public int TestSensitivityFeedback { get; private set; } - public Func NameFeedbackFunc - { - get { return () => Name; } - } - - public Func EnableFeedbackFunc - { - get { return () => InTestMode ? TestEnableFeedback : PartitionSensor.EnableFeedback.BoolValue; } - } - - public Func PartitionSensedFeedbackFunc - { - get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionSensedFeedback.BoolValue; } - } - - public Func PartitionNotSensedFeedbackFunc - { - get { return () => InTestMode ? TestPartitionSensedFeedback : PartitionSensor.PartitionNotSensedFeedback.BoolValue; } - } - - public Func SensitivityFeedbackFunc - { - get { return () => InTestMode ? TestSensitivityFeedback : PartitionSensor.SensitivityFeedback.UShortValue; } - } - /// /// Constructor /// @@ -68,15 +34,15 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public GlsPartitionSensorController(string key, string name, GlsPartCn hardware) : base(key, name, hardware) { - PartitionSensor = hardware; + _partitionSensor = hardware; - NameFeedback = new StringFeedback(NameFeedbackFunc); - EnableFeedback = new BoolFeedback(EnableFeedbackFunc); - PartitionSensedFeedback = new BoolFeedback(PartitionSensedFeedbackFunc); - PartitionNotSensedFeedback = new BoolFeedback(PartitionNotSensedFeedbackFunc); - SensitivityFeedback = new IntFeedback(SensitivityFeedbackFunc); + NameFeedback = new StringFeedback(() => Name); + EnableFeedback = new BoolFeedback(() => _partitionSensor.EnableFeedback.BoolValue); + PartitionSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionSensedFeedback.BoolValue); + PartitionNotSensedFeedback = new BoolFeedback(() => _partitionSensor.PartitionNotSensedFeedback.BoolValue); + SensitivityFeedback = new IntFeedback(() => _partitionSensor.SensitivityFeedback.UShortValue); - if (PartitionSensor != null) PartitionSensor.BaseEvent += PartitionSensor_BaseEvent; + if (_partitionSensor != null) _partitionSensor.BaseEvent += PartitionSensor_BaseEvent; } @@ -108,7 +74,7 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor } default: { - Debug.Console(2, this, "args.EventId: {0}", args.EventId); + Debug.Console(2, this, "Unhandled args.EventId: {0}", args.EventId); break; } } @@ -158,37 +124,36 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public void SetEnableState(bool state) { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.Enable.BoolValue = state; + _partitionSensor.Enable.BoolValue = state; } public void IncreaseSensitivity() { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.IncreaseSensitivity(); + _partitionSensor.IncreaseSensitivity(); } public void DecreaseSensitivity() { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.DecreaseSensitivity(); + _partitionSensor.DecreaseSensitivity(); } public void SetSensitivity(ushort value) { - if (PartitionSensor == null) + if (_partitionSensor == null) return; - PartitionSensor.Sensitivity.UShortValue = (ushort)value; + _partitionSensor.Sensitivity.UShortValue = value; } - public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { var joinMap = new GlsPartitionSensorJoinMap(joinStart); @@ -220,13 +185,13 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]); EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]); PartitionSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]); - PartitionNotSensedFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]); + PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]); SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]); FeedbacksFireUpdates(); // update when device is online - PartitionSensor.OnlineStatusChange += (o, a) => + _partitionSensor.OnlineStatusChange += (o, a) => { if (a.DeviceOnLine) { diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs index 543fc799..a60637f7 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/PartitionSensor/GlsPartitionSensorControllerFactory.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; +using System.Collections.Generic; using Crestron.SimplSharpPro.GeneralIO; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; -using PepperDash.Essentials.Devices.Common.Occupancy; namespace PepperDash.Essentials.Devices.Common.PartitionSensor { @@ -21,14 +16,11 @@ namespace PepperDash.Essentials.Devices.Common.PartitionSensor public override EssentialsDevice BuildDevice(DeviceConfig dc) { Debug.Console(2, "Factory Attempting to create new GLS-PART-CN Device"); - - var typeName = dc.Type.ToLower(); - var key = dc.Key; - var name = dc.Name; + var comm = CommFactory.GetControlPropertiesConfig(dc); if (comm == null) { - Debug.Console(0, "ERROR: Control Properties Config are null"); + Debug.Console(0, "ERROR: Control Properties Config for {0} is null", dc.Key); return null; }