Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
public class GenericDigitalInputDevice : EssentialsBridgeableDevice, IDigitalInput, IHasFeedback
{
private DigitalInput inputPort;
private readonly bool invertState;

/// <summary>
/// Gets or sets the InputStateFeedback
Expand All @@ -41,7 +42,9 @@ public GenericDigitalInputDevice(string key, string name, Func<IOPortConfig, Dig
IOPortConfig config)
: base(key, name)
{
InputStateFeedback = new BoolFeedback("inputState", () => inputPort.State);
invertState = string.Equals(config.CircuitType, "NC", StringComparison.OrdinalIgnoreCase);

InputStateFeedback = new BoolFeedback("inputState", () => invertState ? !inputPort.State : inputPort.State);

AddPostActivationAction(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace PepperDash.Essentials.Core.CrestronIO
public class GenericVersiportDigitalInputDevice : EssentialsBridgeableDevice, IDigitalInput, IPartitionStateProvider, IHasFeedback
{
private Versiport inputPort;
private readonly bool invertState;

/// <summary>
/// Gets or sets the InputStateFeedback
Expand Down Expand Up @@ -47,7 +48,10 @@ public class GenericVersiportDigitalInputDevice : EssentialsBridgeableDevice, ID
public GenericVersiportDigitalInputDevice(string key, string name, Func<IOPortConfig, Versiport> postActivationFunc, IOPortConfig config) :
base(key, name)
{
InputStateFeedback = new BoolFeedback("inputState", () => inputPort.DigitalIn);
var circuitType = string.IsNullOrEmpty(config.CircuitType) ? "NO" : config.CircuitType;
invertState = circuitType.Equals("NC", StringComparison.OrdinalIgnoreCase);

InputStateFeedback = new BoolFeedback("inputState", () => invertState ? !inputPort.DigitalIn : inputPort.DigitalIn);
PartitionPresentFeedback = new BoolFeedback("partitionPresent", () => !inputPort.DigitalIn);

AddPostActivationAction(() =>
Expand Down
7 changes: 7 additions & 0 deletions src/PepperDash.Essentials.Core/CrestronIO/IOPortConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ public class IOPortConfig
/// </summary>
[JsonProperty("minimumChange")]
public int MinimumChange { get; set; }

/// <summary>
/// Gets or sets the circuit type: "NO" (Normally Open) or "NC" (Normally Closed)
/// If set to "NC", the input state will be inverted. Defaults to "NO" if not specified.
/// </summary>
[JsonProperty("circuitType")]
public string CircuitType { get; set; } = "NO";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
Expand Down Expand Up @@ -698,18 +699,26 @@ private void GetTouchpanelInfo()
/// <param name="args"></param>
protected void FusionRoom_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args)
{
if (args.DeviceOnLine)
if (!args.DeviceOnLine)
{
CrestronInvoke.BeginInvoke((o) =>
{
CrestronEnvironment.Sleep(200);
return;
}

if (!_config.EnableSchedulePushNotifications)
{
return;
}

Task.Run(() =>
{
// CrestronEnvironment.Sleep(200);

// Send Push Notification Action request:
// Send Push Notification Action request:

const string requestId = "InitialPushRequest";
const string requestId = "InitialPushRequest";


var actionRequest =
var actionRequest =
string.Format("<RequestAction>\n<RequestID>{0}</RequestID>\n", requestId) +
"<ActionID>RegisterPushModel</ActionID>\n" +
"<Parameters>\n" +
Expand All @@ -734,27 +743,26 @@ protected void FusionRoom_OnlineStatusChange(GenericBase currentDevice, OnlineOf
"</Parameters>\n" +
"</RequestAction>\n";

Debug.LogMessage(LogEventLevel.Verbose, this, "Sending Fusion ActionRequest: \n{0}", actionRequest);
Debug.LogMessage(LogEventLevel.Verbose, this, "Sending Fusion ActionRequest: \n{0}", actionRequest);

FusionRoom.ExtenderFusionRoomDataReservedSigs.ActionQuery.StringValue = actionRequest;
FusionRoom.ExtenderFusionRoomDataReservedSigs.ActionQuery.StringValue = actionRequest;

GetCustomProperties();
GetCustomProperties();

// Request current Fusion Server Time
RequestLocalDateTime(null);
// Request current Fusion Server Time
RequestLocalDateTime(null);

// Setup timer to request time daily
if (_dailyTimeRequestTimer != null && !_dailyTimeRequestTimer.Disposed)
{
_dailyTimeRequestTimer.Stop();
_dailyTimeRequestTimer.Dispose();
}
// Setup timer to request time daily
if (_dailyTimeRequestTimer != null && !_dailyTimeRequestTimer.Disposed)
{
_dailyTimeRequestTimer.Stop();
_dailyTimeRequestTimer.Dispose();
}

_dailyTimeRequestTimer = new CTimer(RequestLocalDateTime, null, 86400000, 86400000);
_dailyTimeRequestTimer = new CTimer(RequestLocalDateTime, null, 86400000, 86400000);

_dailyTimeRequestTimer.Reset(86400000, 86400000);
});
}
_dailyTimeRequestTimer.Reset(86400000, 86400000);
});
}

/// <summary>
Expand Down Expand Up @@ -785,7 +793,7 @@ public void RequestFullRoomSchedule(object callbackObject)

var requestTest =
string.Format(
"<RequestSchedule><RequestID>FullSchedleRequest</RequestID><RoomID>{0}</RoomID><Start>{1}</Start><HourSpan>24</HourSpan></RequestSchedule>",
"<RequestSchedule><RequestID>FullScheduleRequest</RequestID><RoomID>{0}</RoomID><Start>{1}</Start><HourSpan>24</HourSpan></RequestSchedule>",
RoomGuid, currentTime);

Debug.LogMessage(LogEventLevel.Verbose, this, "Sending Fusion ScheduleQuery: \n{0}", requestTest);
Expand Down Expand Up @@ -960,7 +968,7 @@ where parameter.HasAttributes
select parameter.Attributes
into attributes
where attributes["ID"].Value == "Registered"
select Int32.Parse(attributes["Value"].Value))
select int.Parse(attributes["Value"].Value))
{
switch (isRegistered)
{
Expand Down Expand Up @@ -1112,7 +1120,7 @@ select Int32.Parse(attributes["Value"].Value))
protected void FusionRoomSchedule_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender,
SigEventArgs args)
{
Debug.LogMessage(LogEventLevel.Verbose, this, "Scehdule Response Event: {0}\n Sig: {1}\nFusionResponse:\n{2}", args.Event,
Debug.LogMessage(LogEventLevel.Verbose, this, "Schedule Response Event: {0}\n Sig: {1}\nFusionResponse:\n{2}", args.Event,
args.Sig.Name, args.Sig.StringValue);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ public uint IpIdInt
/// </summary>
[JsonProperty("helpRequestTimeoutMs")]
public int HelpRequestTimeoutMs { get; set; } = 30000;

/// <summary>
/// Gets or sets whether to enable schedule push notifications
/// </summary>
/// <remarks>Defaults to false to skip getting schedule unless required</remarks>
[JsonProperty("enableSchedulePushNotifications")]
public bool EnableSchedulePushNotifications { get; set; } = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,51 +69,61 @@ public void Start()

void ProcessStatuses()
{
var InError = Monitors.Where(m => m.Status == MonitorStatus.InError);
var InWarning = Monitors.Where(m => m.Status == MonitorStatus.InWarning);
var IsOk = Monitors.Where(m => m.Status == MonitorStatus.IsOk);
var InError = Monitors.Where(m => m.Status == MonitorStatus.InError).ToList();
var InWarning = Monitors.Where(m => m.Status == MonitorStatus.InWarning).ToList();
var IsOk = Monitors.Where(m => m.Status == MonitorStatus.IsOk).ToList();


MonitorStatus initialStatus;
string prefix = "0:";
if (InError.Count() > 0)
if (InError.Any())
{
initialStatus = MonitorStatus.InError;
prefix = "3:";
}
else if (InWarning.Count() > 0)
else if (InWarning.Any())
{
initialStatus = MonitorStatus.InWarning;
prefix = "2:";
}
else if (IsOk.Count() > 0)
else if (IsOk.Any())
initialStatus = MonitorStatus.IsOk;
else
initialStatus = MonitorStatus.StatusUnknown;

// Build the error message string
if (InError.Count() > 0 || InWarning.Count() > 0)
{
StringBuilder sb = new StringBuilder(prefix);
if (InError.Count() > 0)
{
// Do string splits and joins
sb.Append(string.Format("{0} Errors:", InError.Count()));
foreach (var mon in InError)
sb.Append(string.Format("{0}, ", mon.Parent.Key));
}
if (InWarning.Count() > 0)
{
sb.Append(string.Format("{0} Warnings:", InWarning.Count()));
foreach (var mon in InWarning)
sb.Append(string.Format("{0}, ", mon.Parent.Key));
}
Message = sb.ToString();
}
else
{
Message = "Room Ok.";
}
if (InError.Any() || InWarning.Any())
{
var errorNames = InError
.Select(mon => mon.Parent is IKeyName keyName ? keyName.Name : mon.Parent.Key)
.ToList();
var warningNames = InWarning
.Select(mon => mon.Parent is IKeyName keyName ? keyName.Name : mon.Parent.Key)
.ToList();

var sb = new StringBuilder(prefix);

if (errorNames.Count > 0)
{
sb.Append($"{errorNames.Count} Error{(errorNames.Count > 1 ? "s" : "")}: ");
sb.Append(string.Join(", ", errorNames));
}
if (warningNames.Count > 0)
{
if (errorNames.Count > 0)
sb.Append("; ");

sb.Append($"{warningNames.Count} Warning{(warningNames.Count > 1 ? "s" : "")}: ");
sb.Append(string.Join(", ", warningNames));
}

sb.Append(" Offline");
Message = sb.ToString();
}
else
{
Message = "Room Ok.";
}

// Want to fire even if status doesn't change because the message may.
Status = initialStatus;
Expand Down
Loading