Adds Fusion Custom Properties support and bridge to pass values from custom properties to devices

This commit is contained in:
Neil Dorin
2018-09-11 19:36:10 -06:00
parent 6a8ae5b244
commit 7112c50f5a
8 changed files with 158 additions and 25 deletions

View File

@@ -37,7 +37,7 @@ namespace PepperDash.Essentials
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file", //CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
// ConsoleAccessLevelEnum.AccessOperator); // ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(S => { ConfigWriter.WriteConfigFile(null); }, "writeconfig", "writes the current config to a file", ConsoleAccessLevelEnum.AccessOperator); // CrestronConsole.AddNewConsoleCommand(S => { ConfigWriter.WriteConfigFile(null); }, "writeconfig", "writes the current config to a file", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.AddNewConsoleCommand(s =>
{ {

View File

@@ -33,13 +33,13 @@ namespace PepperDash.Essentials.Fusion
public event EventHandler<EventArgs> RoomInfoChange; public event EventHandler<EventArgs> RoomInfoChange;
public FusionCustomPropertiesBridge CustomPropertiesBridge = new FusionCustomPropertiesBridge();
protected FusionRoom FusionRoom; protected FusionRoom FusionRoom;
protected EssentialsRoomBase Room; protected EssentialsRoomBase Room;
Dictionary<Device, BoolInputSig> SourceToFeedbackSigs = Dictionary<Device, BoolInputSig> SourceToFeedbackSigs =
new Dictionary<Device, BoolInputSig>(); new Dictionary<Device, BoolInputSig>();
public RoomInformation RoomInfo {get; protected set;}
StatusMonitorCollection ErrorMessageRollUp; StatusMonitorCollection ErrorMessageRollUp;
protected StringSigData CurrentRoomSourceNameSig; protected StringSigData CurrentRoomSourceNameSig;
@@ -430,8 +430,6 @@ namespace PepperDash.Essentials.Fusion
} }
protected void GetCustomProperties() protected void GetCustomProperties()
{
try
{ {
if (FusionRoom.IsOnline) if (FusionRoom.IsOnline)
{ {
@@ -440,7 +438,6 @@ namespace PepperDash.Essentials.Fusion
FusionRoom.ExtenderFusionRoomDataReservedSigs.RoomConfigQuery.StringValue = fusionRoomCustomPropertiesRequest; FusionRoom.ExtenderFusionRoomDataReservedSigs.RoomConfigQuery.StringValue = fusionRoomCustomPropertiesRequest;
} }
} }
}
void GetTouchpanelInfo() void GetTouchpanelInfo()
{ {
@@ -777,6 +774,8 @@ namespace PepperDash.Essentials.Fusion
string roomConfigResponseArgs = args.Sig.StringValue.Replace("&", "and"); string roomConfigResponseArgs = args.Sig.StringValue.Replace("&", "and");
Debug.Console(1, this, "Fusion Response: \n {0}", roomConfigResponseArgs);
try try
{ {
XmlDocument roomConfigResponse = new XmlDocument(); XmlDocument roomConfigResponse = new XmlDocument();
@@ -787,13 +786,15 @@ namespace PepperDash.Essentials.Fusion
if (requestRoomConfiguration != null) if (requestRoomConfiguration != null)
{ {
RoomInformation roomInformation = new RoomInformation();
foreach (XmlElement e in roomConfigResponse.FirstChild.ChildNodes) foreach (XmlElement e in roomConfigResponse.FirstChild.ChildNodes)
{ {
if (e.Name == "RoomInformation") if (e.Name == "RoomInformation")
{ {
XmlReader roomInfo = new XmlReader(e.OuterXml); XmlReader roomInfo = new XmlReader(e.OuterXml);
RoomInfo = CrestronXMLSerialization.DeSerializeObject<RoomInformation>(roomInfo); roomInformation = CrestronXMLSerialization.DeSerializeObject<RoomInformation>(roomInfo);
} }
else if (e.Name == "CustomFields") else if (e.Name == "CustomFields")
{ {
@@ -821,10 +822,8 @@ namespace PepperDash.Essentials.Fusion
customProperty.CustomFieldValue = elm.InnerText; customProperty.CustomFieldValue = elm.InnerText;
} }
} }
if (!RoomInfo.FusionCustomProperties.ContainsKey(customProperty.ID))
RoomInfo.FusionCustomProperties.Add(customProperty.ID, customProperty); roomInformation.FusionCustomProperties.Add(customProperty);
else
RoomInfo.FusionCustomProperties[customProperty.ID] = customProperty;
} }
} }
} }
@@ -832,6 +831,8 @@ namespace PepperDash.Essentials.Fusion
var handler = RoomInfoChange; var handler = RoomInfoChange;
if (handler != null) if (handler != null)
handler(this, new EventArgs()); handler(this, new EventArgs());
CustomPropertiesBridge.EvaluateRoomInfo(roomInformation);
} }
} }
catch (Exception e) catch (Exception e)
@@ -1567,11 +1568,11 @@ namespace PepperDash.Essentials.Fusion
public string BacklogMsg { get; set; } public string BacklogMsg { get; set; }
public string SubErrorMsg { get; set; } public string SubErrorMsg { get; set; }
public string EmailInfo { get; set; } public string EmailInfo { get; set; }
public Dictionary<string, FusionCustomProperty> FusionCustomProperties { get; set; } public List<FusionCustomProperty> FusionCustomProperties { get; set; }
public RoomInformation() public RoomInformation()
{ {
FusionCustomProperties = new Dictionary<string,FusionCustomProperty>(); FusionCustomProperties = new List<FusionCustomProperty>();
} }
} }
public class FusionCustomProperty public class FusionCustomProperty
@@ -1580,5 +1581,15 @@ namespace PepperDash.Essentials.Fusion
public string CustomFieldName { get; set; } public string CustomFieldName { get; set; }
public string CustomFieldType { get; set; } public string CustomFieldType { get; set; }
public string CustomFieldValue { get; set; } public string CustomFieldValue { get; set; }
public FusionCustomProperty()
{
}
public FusionCustomProperty(string id)
{
ID = id;
}
} }
} }

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Room.Behaviours;
namespace PepperDash.Essentials.Fusion
{
/// <summary>
/// Handles mapping Fusion Custom Property values to system properties
/// </summary>
public class FusionCustomPropertiesBridge
{
/// <summary>
/// Evaluates the room info and custom properties from Fusion and updates the system properties aa needed
/// </summary>
/// <param name="roomInfo"></param>
public void EvaluateRoomInfo(RoomInformation roomInfo)
{
var runtimeConfigurableDevices = DeviceManager.AllDevices.Where(d => d is IRuntimeConfigurableDevice);
try
{
foreach (var device in runtimeConfigurableDevices)
{
var deviceConfig = (device as IRuntimeConfigurableDevice).GetDeviceConfig();
if (device is RoomOnToDefaultSourceWhenOccupied)
{
var devConfig = (deviceConfig as RoomOnToDefaultSourceWhenOccupiedConfig);
var enableFeature = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupied"));
if (enableFeature != null)
devConfig.EnableRoomOnWhenOccupied = bool.Parse(enableFeature.CustomFieldValue);
var enableTime = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("RoomOnWhenOccupiedStartTime"));
if (enableTime != null)
devConfig.OccupancyStartTime = enableTime.CustomFieldValue;
var disableTime = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("RoomOnWhenOccupiedEndTime"));
if (disableTime != null)
devConfig.OccupancyEndTime = disableTime.CustomFieldValue;
var enableSunday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedSun"));
if (enableSunday != null)
devConfig.EnableSunday = bool.Parse(enableSunday.CustomFieldValue);
var enableMonday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedMon"));
if (enableMonday != null)
devConfig.EnableMonday = bool.Parse(enableMonday.CustomFieldValue);
var enableTuesday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedTue"));
if (enableTuesday != null)
devConfig.EnableTuesday = bool.Parse(enableTuesday.CustomFieldValue);
var enableWednesday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedWed"));
if (enableWednesday != null)
devConfig.EnableWednesday = bool.Parse(enableWednesday.CustomFieldValue);
var enableThursday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedThu"));
if (enableThursday != null)
devConfig.EnableThursday = bool.Parse(enableThursday.CustomFieldValue);
var enableFriday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedFri"));
if (enableFriday != null)
devConfig.EnableFriday = bool.Parse(enableFriday.CustomFieldValue);
var enableSaturday = roomInfo.FusionCustomProperties.FirstOrDefault(p => p.ID.Equals("EnRoomOnWhenOccupiedSat"));
if (enableSaturday != null)
devConfig.EnableSaturday = bool.Parse(enableSaturday.CustomFieldValue);
deviceConfig = devConfig;
}
(device as IRuntimeConfigurableDevice).SetDeviceConfig(deviceConfig);
}
}
catch (Exception e)
{
Debug.Console(1, "FusionCustomPropetiesBridge: Error mapping properties: {0}", e);
}
}
}
}

View File

@@ -133,6 +133,7 @@
<Compile Include="ControlSystem.cs" /> <Compile Include="ControlSystem.cs" />
<Compile Include="Factory\UiDeviceFactory.cs" /> <Compile Include="Factory\UiDeviceFactory.cs" />
<Compile Include="OTHER\Fusion\EssentialsHuddleVtc1FusionController.cs" /> <Compile Include="OTHER\Fusion\EssentialsHuddleVtc1FusionController.cs" />
<Compile Include="OTHER\Fusion\FusionCustomPropertiesBridge.cs" />
<Compile Include="OTHER\Fusion\FusionEventHandlers.cs" /> <Compile Include="OTHER\Fusion\FusionEventHandlers.cs" />
<Compile Include="OTHER\Fusion\FusionProcessorQueries.cs" /> <Compile Include="OTHER\Fusion\FusionProcessorQueries.cs" />
<Compile Include="OTHER\Fusion\FusionRviDataClasses.cs" /> <Compile Include="OTHER\Fusion\FusionRviDataClasses.cs" />

View File

@@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Devices.Common.Occupancy; using PepperDash.Essentials.Devices.Common.Occupancy;
namespace PepperDash.Essentials.Room.Behaviours namespace PepperDash.Essentials.Room.Behaviours
@@ -17,7 +18,7 @@ namespace PepperDash.Essentials.Room.Behaviours
/// <summary> /// <summary>
/// A device that when linked to a room can power the room on when enabled during scheduled hours. /// A device that when linked to a room can power the room on when enabled during scheduled hours.
/// </summary> /// </summary>
public class RoomOnToDefaultSourceWhenOccupied : Device public class RoomOnToDefaultSourceWhenOccupied : Device, IRuntimeConfigurableDevice
{ {
RoomOnToDefaultSourceWhenOccupiedConfig Config; RoomOnToDefaultSourceWhenOccupiedConfig Config;
@@ -72,6 +73,13 @@ namespace PepperDash.Essentials.Room.Behaviours
} }
public override bool CustomActivate() public override bool CustomActivate()
{
SetUpDevice();
return base.CustomActivate();
}
void SetUpDevice()
{ {
Room = DeviceManager.GetDeviceForKey(Config.RoomKey) as EssentialsRoomBase; Room = DeviceManager.GetDeviceForKey(Config.RoomKey) as EssentialsRoomBase;
@@ -109,6 +117,10 @@ namespace PepperDash.Essentials.Room.Behaviours
Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e); Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e);
} }
if (!Config.EnableRoomOnWhenOccupied)
FeatureEventGroup.ClearAllEvents();
else
{
AddEnableEventToGroup(); AddEnableEventToGroup();
AddDisableEventToGroup(); AddDisableEventToGroup();
@@ -116,13 +128,12 @@ namespace PepperDash.Essentials.Room.Behaviours
FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack); FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack);
FeatureEventGroup.EnableAllEvents(); FeatureEventGroup.EnableAllEvents();
}
FeatureEnabled = CheckIfFeatureShouldBeEnabled(); FeatureEnabled = CheckIfFeatureShouldBeEnabled();
} }
else else
Debug.Console(1, this, "Unable to get room from Device Manager with key: {0}", Config.RoomKey); Debug.Console(1, this, "Unable to get room from Device Manager with key: {0}", Config.RoomKey);
return base.CustomActivate();
} }
/// <summary> /// <summary>
@@ -134,6 +145,22 @@ namespace PepperDash.Essentials.Room.Behaviours
return JToken.FromObject(Config); return JToken.FromObject(Config);
} }
public object GetDeviceConfig()
{
return Config;
}
public void SetDeviceConfig(object config)
{
var newConfig = config as RoomOnToDefaultSourceWhenOccupiedConfig;
Config = newConfig;
ConfigWriter.UpdateDeviceProperties(this.Key, GetLocalConfigProperties());
SetUpDevice();
}
/// <summary> /// <summary>
/// Subscribe to feedback from RoomIsOccupiedFeedback on Room /// Subscribe to feedback from RoomIsOccupiedFeedback on Room
/// </summary> /// </summary>
@@ -185,11 +212,16 @@ namespace PepperDash.Essentials.Room.Behaviours
{ {
if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, CalculateDaysOfWeekRecurrence())) if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, CalculateDaysOfWeekRecurrence()))
{ {
Debug.Console(1, this, "*****Feature Enabled by startup check.*****");
enabled = true; enabled = true;
} }
} }
} }
if(enabled)
Debug.Console(1, this, "*****Feature Enabled*****");
else
Debug.Console(1, this, "*****Feature Disabled*****");
return enabled; return enabled;
} }