mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
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
This commit is contained in:
@@ -64,13 +64,24 @@ namespace PepperDash.Essentials.Room.Config
|
|||||||
{
|
{
|
||||||
// This emergency
|
// This emergency
|
||||||
var emergency = props.Emergency;
|
var emergency = props.Emergency;
|
||||||
if (emergency != null)
|
if (emergency == null || room == null) return null;
|
||||||
{
|
|
||||||
|
Debug.Console(0, @"emergency config values:
|
||||||
|
behavior: {0}
|
||||||
|
portDeviceKey: {1}
|
||||||
|
type: {2}
|
||||||
|
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
|
//switch on emergency type here. Right now only contact and shutdown
|
||||||
var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", props.Emergency, room);
|
var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", emergency, room);
|
||||||
DeviceManager.AddDevice(e);
|
DeviceManager.AddDevice(e);
|
||||||
}
|
return e;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ namespace PepperDash.Essentials.Room.Config
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class EssentialsRoomEmergencyTriggerConfig
|
public class EssentialsRoomEmergencyTriggerConfig
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// String representing the port device used to access the type
|
||||||
|
/// </summary>
|
||||||
|
public string PortDeviceKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// contact,
|
/// contact,
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,32 +12,68 @@ using PepperDash.Essentials.Room.Config;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Room
|
namespace PepperDash.Essentials.Room
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsRoomEmergencyContactClosure : EssentialsRoomEmergencyBase
|
public class EssentialsRoomEmergencyContactClosure : EssentialsRoomEmergencyBase
|
||||||
{
|
{
|
||||||
IEssentialsRoom Room;
|
IEssentialsRoom Room;
|
||||||
string Behavior;
|
string Behavior;
|
||||||
bool TriggerOnClose;
|
bool TriggerOnClose;
|
||||||
|
|
||||||
|
// TODO [ ] Issue #1071 - Emergency
|
||||||
public EssentialsRoomEmergencyContactClosure(string key, EssentialsRoomEmergencyConfig config, IEssentialsRoom room) :
|
public EssentialsRoomEmergencyContactClosure(string key, EssentialsRoomEmergencyConfig config, IEssentialsRoom room) :
|
||||||
base(key)
|
base(key)
|
||||||
{
|
{
|
||||||
Room = room;
|
if (config == null || room == null) return;
|
||||||
var cs = Global.ControlSystem;
|
|
||||||
|
|
||||||
if (config.Trigger.Type.Equals("contact", StringComparison.OrdinalIgnoreCase))
|
Room = room;
|
||||||
{
|
|
||||||
var portNum = (uint)config.Trigger.Number;
|
|
||||||
if (portNum <= cs.NumberOfDigitalInputPorts)
|
|
||||||
{
|
|
||||||
cs.DigitalInputPorts[portNum].Register();
|
|
||||||
cs.DigitalInputPorts[portNum].StateChange += EsentialsRoomEmergencyContactClosure_StateChange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Behavior = config.Behavior;
|
Behavior = config.Behavior;
|
||||||
TriggerOnClose = config.Trigger.TriggerOnClose;
|
TriggerOnClose = config.Trigger.TriggerOnClose;
|
||||||
|
|
||||||
|
var cs = Global.ControlSystem;
|
||||||
|
|
||||||
|
Debug.Console(0, this, "Control system supports digital inputs {0}", cs.SupportsDigitalInput);
|
||||||
|
Debug.Console(0, this, "Control system supports versiports {0}", cs.SupportsVersiport);
|
||||||
|
|
||||||
|
Debug.Console(0, this, "------> type check");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(config.Trigger.Type))
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Emergency Contact Closure type is empty or null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.Trigger.Type.Equals("contact", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Emergency Contact Closure type is not 'contact'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Console(0, this, "------> type passed");
|
||||||
|
Debug.Console(0, this, "------> portNum check");
|
||||||
|
|
||||||
|
var portNum = (uint)config.Trigger.Number;
|
||||||
|
if (portNum > cs.NumberOfDigitalInputPorts) return;
|
||||||
|
|
||||||
|
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)
|
void EsentialsRoomEmergencyContactClosure_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args)
|
||||||
|
|||||||
Reference in New Issue
Block a user