diff --git a/src/Abstractions/IApDeviceBuilder.cs b/src/Abstractions/IApDeviceBuilder.cs index 57d796a..388fe54 100644 --- a/src/Abstractions/IApDeviceBuilder.cs +++ b/src/Abstractions/IApDeviceBuilder.cs @@ -17,5 +17,6 @@ public interface IApDeviceBuilder : IKeyName ReadOnlyDictionary Outlets { get; } EssentialsDevice Build(); bool UseEssentialsJoinMap { get; } + bool EnableAsOnline { get; } } } \ No newline at end of file diff --git a/src/Builders/Ap89XxBuilder.cs b/src/Builders/Ap89XxBuilder.cs index 57ab5ca..ce34974 100644 --- a/src/Builders/Ap89XxBuilder.cs +++ b/src/Builders/Ap89XxBuilder.cs @@ -18,8 +18,10 @@ private Ap89XxBuilder(string key, string name, IBasicCommunication coms, ApDevic Coms = coms; Name = name; Key = key; + UseEssentialsJoinMap = config.UseEssentialsJoinmap; Outlets = BuildOutletsFromConfig(key, config, coms); + EnableAsOnline = config.EnableOutletsOverride; foreach (var outlet in Outlets) { @@ -32,6 +34,7 @@ private Ap89XxBuilder(string key, string name, IBasicCommunication coms, ApDevic public string Name { get; private set; } public IBasicCommunication Coms { get; private set; } public bool UseEssentialsJoinMap { get; private set; } + public bool EnableAsOnline { get; private set; } public ReadOnlyDictionary Outlets { get; private set; } @@ -40,6 +43,7 @@ public static ReadOnlyDictionary BuildOutletsFromConfig( ApDeviceConfig config, IBasicCommunication coms) { + var outlets = config .Outlets .Select(x => new ApOutlet(x.Key, x.Value.Name, x.Value.OutletIndex, parentKey, coms, config.PowerCycleTimeMs)) diff --git a/src/Config/ApDeviceConfig.cs b/src/Config/ApDeviceConfig.cs index 51c9047..7b82855 100644 --- a/src/Config/ApDeviceConfig.cs +++ b/src/Config/ApDeviceConfig.cs @@ -4,6 +4,7 @@ using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; +using Newtonsoft.Json; using PepperDash.Core; namespace ApcEpi.Config @@ -14,6 +15,8 @@ public class ApDeviceConfig public int PowerCycleTimeMs { get; set; } public Dictionary Outlets { get; set; } public bool UseEssentialsJoinmap { get; set; } + [JsonProperty("enableOutletsOverride")] + public bool EnableOutletsOverride { get; set; } } public class ApOutletConfig diff --git a/src/Devices/ApDevice.cs b/src/Devices/ApDevice.cs index 6b44b5d..1bf193d 100644 --- a/src/Devices/ApDevice.cs +++ b/src/Devices/ApDevice.cs @@ -20,7 +20,8 @@ public class ApDevice : EssentialsBridgeableDevice, IOutletName, IOutletPower, I { private readonly StatusMonitorBase _monitor; public ReadOnlyDictionary PduOutlets { get; private set; } - private readonly bool _useEssentialsConfig; + bool _useEssentialsJoinmap; + private readonly bool _enableAsOnline; public ApDevice(IApDeviceBuilder builder) : base(builder.Key, builder.Name) @@ -39,8 +40,8 @@ public ApDevice(IApDeviceBuilder builder) NameFeedback = new StringFeedback("DeviceNameFeedback", () => Name); Feedbacks.Add(IsOnline); Feedbacks.Add(NameFeedback); - - _useEssentialsConfig = builder.UseEssentialsJoinMap; + _enableAsOnline = builder.EnableAsOnline; + _useEssentialsJoinmap = builder.UseEssentialsJoinMap; var gather = new CommunicationGather(builder.Coms, "\n"); gather.LineReceived += @@ -171,7 +172,7 @@ public override bool CustomActivate() public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { - if (!_useEssentialsConfig) + if (!_useEssentialsJoinmap) { var joinMap = new ApDeviceJoinMap(joinStart); @@ -406,7 +407,12 @@ public bool TryGetOutletOnlineFeedback(uint outletIndex, out BoolFeedback result if (!PduOutlets.TryGetValue((int)outletIndex, out outlet)) return false; var apOutlet = outlet as IApOutlet; - result = apOutlet != null ? apOutlet.IsOnline : new BoolFeedback(() => false); + if (!_enableAsOnline) + { + result = apOutlet != null ? apOutlet.IsOnline : new BoolFeedback(() => false); + return true; + } + result = apOutlet != null ? new BoolFeedback(() => true) : new BoolFeedback(() => false); return true; }