Skip to content

Commit

Permalink
Merge pull request #11 from PepperDash-Engineering/feature/enable-Out…
Browse files Browse the repository at this point in the history
…lets-Override

Added option config value to override default outlet online behavior for specific client use cases.
  • Loading branch information
TrevorPayne authored Jan 30, 2023
2 parents 8d68596 + 4382abb commit 9bd46c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Abstractions/IApDeviceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface IApDeviceBuilder : IKeyName
ReadOnlyDictionary<int, IHasPowerCycle> Outlets { get; }
EssentialsDevice Build();
bool UseEssentialsJoinMap { get; }
bool EnableAsOnline { get; }
}
}
4 changes: 4 additions & 0 deletions src/Builders/Ap89XxBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<int, IHasPowerCycle> Outlets { get; private set; }

Expand All @@ -40,6 +43,7 @@ public static ReadOnlyDictionary<int, IHasPowerCycle> 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))
Expand Down
3 changes: 3 additions & 0 deletions src/Config/ApDeviceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Newtonsoft.Json;
using PepperDash.Core;

namespace ApcEpi.Config
Expand All @@ -14,6 +15,8 @@ public class ApDeviceConfig
public int PowerCycleTimeMs { get; set; }
public Dictionary<string, ApOutletConfig> Outlets { get; set; }
public bool UseEssentialsJoinmap { get; set; }
[JsonProperty("enableOutletsOverride")]
public bool EnableOutletsOverride { get; set; }
}

public class ApOutletConfig
Expand Down
16 changes: 11 additions & 5 deletions src/Devices/ApDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class ApDevice : EssentialsBridgeableDevice, IOutletName, IOutletPower, I
{
private readonly StatusMonitorBase _monitor;
public ReadOnlyDictionary<int, IHasPowerCycle> PduOutlets { get; private set; }
private readonly bool _useEssentialsConfig;
bool _useEssentialsJoinmap;
private readonly bool _enableAsOnline;

public ApDevice(IApDeviceBuilder builder)
: base(builder.Key, builder.Name)
Expand All @@ -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 +=
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9bd46c1

Please sign in to comment.