Compare commits

...

1 Commits

Author SHA1 Message Date
jdevito
b0c206eb61 fix: #1071 - Emergency Contact Closure Null Ref
EssentialsRoomconfig.cs

added debug statements to GetEmergency method
changed 'return null' to return the object 'e'

EssentialsRoomEmergencyConfig.cs

added 'PortDeviceKey' to EssentialsRoomEmergencyTrigerConfig

EssentialsRoomEmergencyContactClosure.cs

added debug statements to constructor to help with debugging
2023-02-28 13:26:24 -06:00
3 changed files with 155 additions and 103 deletions

View File

@@ -55,22 +55,33 @@ namespace PepperDash.Essentials.Room.Config
} }
} }
} }
/// <summary> /// <summary>
/// Gets and operating, standalone emergegncy object that can be plugged into a room. /// Gets and operating, standalone emergegncy object that can be plugged into a room.
/// Returns null if there is no emergency defined /// Returns null if there is no emergency defined
/// </summary> /// </summary>
public static EssentialsRoomEmergencyBase GetEmergency(EssentialsRoomPropertiesConfig props, IEssentialsRoom room) public static EssentialsRoomEmergencyBase GetEmergency(EssentialsRoomPropertiesConfig props, IEssentialsRoom room)
{ {
// This emergency // This emergency
var emergency = props.Emergency; var emergency = props.Emergency;
if (emergency != null) if (emergency == null || room == null) return null;
{
//switch on emergency type here. Right now only contact and shutdown Debug.Console(0, @"emergency config values:
var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", props.Emergency, room); behavior: {0}
DeviceManager.AddDevice(e); portDeviceKey: {1}
} type: {2}
return null; number: {3}
triggerOnClose: {4}",
emergency.Behavior,
emergency.Trigger.PortDeviceKey,
emergency.Trigger.Type,
emergency.Trigger.Number,
emergency.Trigger.TriggerOnClose);
//switch on emergency type here. Right now only contact and shutdown
var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", emergency, room);
DeviceManager.AddDevice(e);
return e;
} }
/// <summary> /// <summary>

View File

@@ -1,36 +1,41 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
namespace PepperDash.Essentials.Room.Config namespace PepperDash.Essentials.Room.Config
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class EssentialsRoomEmergencyConfig public class EssentialsRoomEmergencyConfig
{ {
public EssentialsRoomEmergencyTriggerConfig Trigger { get; set; } public EssentialsRoomEmergencyTriggerConfig Trigger { get; set; }
public string Behavior { get; set; } public string Behavior { get; set; }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class EssentialsRoomEmergencyTriggerConfig public class EssentialsRoomEmergencyTriggerConfig
{ {
/// <summary> /// <summary>
/// contact, /// String representing the port device used to access the type
/// </summary> /// </summary>
public string Type { get; set; } public string PortDeviceKey { get; set; }
/// <summary>
/// Input number if contact /// <summary>
/// </summary> /// contact,
public int Number { get; set; } /// </summary>
public string Type { get; set; }
public bool TriggerOnClose { get; set; } /// <summary>
/// Input number if contact
} /// </summary>
public int Number { get; set; }
public bool TriggerOnClose { get; set; }
}
} }

View File

@@ -1,58 +1,94 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Room.Config; using PepperDash.Essentials.Room.Config;
namespace PepperDash.Essentials.Room namespace PepperDash.Essentials.Room
{ {
public class EssentialsRoomEmergencyContactClosure : EssentialsRoomEmergencyBase
{
IEssentialsRoom Room;
public class EssentialsRoomEmergencyContactClosure : EssentialsRoomEmergencyBase string Behavior;
{ bool TriggerOnClose;
IEssentialsRoom Room;
string Behavior; // TODO [ ] Issue #1071 - Emergency
bool TriggerOnClose; public EssentialsRoomEmergencyContactClosure(string key, EssentialsRoomEmergencyConfig config, IEssentialsRoom room) :
base(key)
public EssentialsRoomEmergencyContactClosure(string key, EssentialsRoomEmergencyConfig config, IEssentialsRoom room) : {
base(key) if (config == null || room == null) return;
{
Room = room; Room = room;
var cs = Global.ControlSystem; Behavior = config.Behavior;
TriggerOnClose = config.Trigger.TriggerOnClose;
if (config.Trigger.Type.Equals("contact", StringComparison.OrdinalIgnoreCase))
{ var cs = Global.ControlSystem;
var portNum = (uint)config.Trigger.Number;
if (portNum <= cs.NumberOfDigitalInputPorts) Debug.Console(0, this, "Control system supports digital inputs {0}", cs.SupportsDigitalInput);
{ Debug.Console(0, this, "Control system supports versiports {0}", cs.SupportsVersiport);
cs.DigitalInputPorts[portNum].Register();
cs.DigitalInputPorts[portNum].StateChange += EsentialsRoomEmergencyContactClosure_StateChange; Debug.Console(0, this, "------> type check");
}
} if (string.IsNullOrEmpty(config.Trigger.Type))
Behavior = config.Behavior; {
TriggerOnClose = config.Trigger.TriggerOnClose; Debug.Console(0, this, "Emergency Contact Closure type is empty or null");
} return;
}
void EsentialsRoomEmergencyContactClosure_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args)
{ if (!config.Trigger.Type.Equals("contact", StringComparison.OrdinalIgnoreCase))
if (args.State && TriggerOnClose || !args.State && !TriggerOnClose) {
RunEmergencyBehavior(); Debug.Console(0, this, "Emergency Contact Closure type is not 'contact'");
} return;
}
/// <summary>
/// Debug.Console(0, this, "------> type passed");
/// </summary> Debug.Console(0, this, "------> portNum check");
public void RunEmergencyBehavior()
{ var portNum = (uint)config.Trigger.Number;
if (Behavior.Equals("shutdown")) if (portNum > cs.NumberOfDigitalInputPorts) return;
Room.Shutdown();
} Debug.Console(0, this, "------> portNum passed");
} Debug.Console(0, this, "------> port check");
var port = cs.DigitalInputPorts[portNum];
if (port == null)
{
Debug.Console(0, this, "Control system does not support digital inputs");
return;
}
Debug.Console(0, this, "------> port passed");
Debug.Console(0, this, "------> port register check");
port.Register();
Debug.Console(0, this, "------> port register passed");
Debug.Console(0, this, "------> port event check");
port.StateChange += EsentialsRoomEmergencyContactClosure_StateChange;
Debug.Console(0, this, "------> port event passed");
}
void EsentialsRoomEmergencyContactClosure_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args)
{
if (args.State && TriggerOnClose || !args.State && !TriggerOnClose)
RunEmergencyBehavior();
}
/// <summary>
///
/// </summary>
public void RunEmergencyBehavior()
{
if (Behavior.Equals("shutdown"))
Room.Shutdown();
}
}
} }