mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-08 01:04:56 +00:00
Adds Fusion Custom Properties support and bridge to pass values from custom properties to devices
This commit is contained in:
@@ -37,7 +37,7 @@ namespace PepperDash.Essentials
|
||||
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
|
||||
// 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 =>
|
||||
{
|
||||
|
||||
@@ -33,13 +33,13 @@ namespace PepperDash.Essentials.Fusion
|
||||
|
||||
public event EventHandler<EventArgs> RoomInfoChange;
|
||||
|
||||
public FusionCustomPropertiesBridge CustomPropertiesBridge = new FusionCustomPropertiesBridge();
|
||||
|
||||
protected FusionRoom FusionRoom;
|
||||
protected EssentialsRoomBase Room;
|
||||
Dictionary<Device, BoolInputSig> SourceToFeedbackSigs =
|
||||
new Dictionary<Device, BoolInputSig>();
|
||||
|
||||
public RoomInformation RoomInfo {get; protected set;}
|
||||
|
||||
StatusMonitorCollection ErrorMessageRollUp;
|
||||
|
||||
protected StringSigData CurrentRoomSourceNameSig;
|
||||
@@ -431,14 +431,11 @@ namespace PepperDash.Essentials.Fusion
|
||||
|
||||
protected void GetCustomProperties()
|
||||
{
|
||||
try
|
||||
if (FusionRoom.IsOnline)
|
||||
{
|
||||
if (FusionRoom.IsOnline)
|
||||
{
|
||||
string fusionRoomCustomPropertiesRequest = @"<RequestRoomConfiguration><RequestID>RoomConfigurationRequest</RequestID><CustomProperties><Property></Property></CustomProperties></RequestRoomConfiguration>";
|
||||
string fusionRoomCustomPropertiesRequest = @"<RequestRoomConfiguration><RequestID>RoomConfigurationRequest</RequestID><CustomProperties><Property></Property></CustomProperties></RequestRoomConfiguration>";
|
||||
|
||||
FusionRoom.ExtenderFusionRoomDataReservedSigs.RoomConfigQuery.StringValue = fusionRoomCustomPropertiesRequest;
|
||||
}
|
||||
FusionRoom.ExtenderFusionRoomDataReservedSigs.RoomConfigQuery.StringValue = fusionRoomCustomPropertiesRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,6 +774,8 @@ namespace PepperDash.Essentials.Fusion
|
||||
|
||||
string roomConfigResponseArgs = args.Sig.StringValue.Replace("&", "and");
|
||||
|
||||
Debug.Console(1, this, "Fusion Response: \n {0}", roomConfigResponseArgs);
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument roomConfigResponse = new XmlDocument();
|
||||
@@ -787,13 +786,15 @@ namespace PepperDash.Essentials.Fusion
|
||||
|
||||
if (requestRoomConfiguration != null)
|
||||
{
|
||||
RoomInformation roomInformation = new RoomInformation();
|
||||
|
||||
foreach (XmlElement e in roomConfigResponse.FirstChild.ChildNodes)
|
||||
{
|
||||
if (e.Name == "RoomInformation")
|
||||
{
|
||||
XmlReader roomInfo = new XmlReader(e.OuterXml);
|
||||
|
||||
RoomInfo = CrestronXMLSerialization.DeSerializeObject<RoomInformation>(roomInfo);
|
||||
roomInformation = CrestronXMLSerialization.DeSerializeObject<RoomInformation>(roomInfo);
|
||||
}
|
||||
else if (e.Name == "CustomFields")
|
||||
{
|
||||
@@ -821,10 +822,8 @@ namespace PepperDash.Essentials.Fusion
|
||||
customProperty.CustomFieldValue = elm.InnerText;
|
||||
}
|
||||
}
|
||||
if (!RoomInfo.FusionCustomProperties.ContainsKey(customProperty.ID))
|
||||
RoomInfo.FusionCustomProperties.Add(customProperty.ID, customProperty);
|
||||
else
|
||||
RoomInfo.FusionCustomProperties[customProperty.ID] = customProperty;
|
||||
|
||||
roomInformation.FusionCustomProperties.Add(customProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -832,6 +831,8 @@ namespace PepperDash.Essentials.Fusion
|
||||
var handler = RoomInfoChange;
|
||||
if (handler != null)
|
||||
handler(this, new EventArgs());
|
||||
|
||||
CustomPropertiesBridge.EvaluateRoomInfo(roomInformation);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1567,11 +1568,11 @@ namespace PepperDash.Essentials.Fusion
|
||||
public string BacklogMsg { get; set; }
|
||||
public string SubErrorMsg { get; set; }
|
||||
public string EmailInfo { get; set; }
|
||||
public Dictionary<string, FusionCustomProperty> FusionCustomProperties { get; set; }
|
||||
public List<FusionCustomProperty> FusionCustomProperties { get; set; }
|
||||
|
||||
public RoomInformation()
|
||||
{
|
||||
FusionCustomProperties = new Dictionary<string,FusionCustomProperty>();
|
||||
FusionCustomProperties = new List<FusionCustomProperty>();
|
||||
}
|
||||
}
|
||||
public class FusionCustomProperty
|
||||
@@ -1580,5 +1581,15 @@ namespace PepperDash.Essentials.Fusion
|
||||
public string CustomFieldName { get; set; }
|
||||
public string CustomFieldType { get; set; }
|
||||
public string CustomFieldValue { get; set; }
|
||||
|
||||
public FusionCustomProperty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FusionCustomProperty(string id)
|
||||
{
|
||||
ID = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,7 @@
|
||||
<Compile Include="ControlSystem.cs" />
|
||||
<Compile Include="Factory\UiDeviceFactory.cs" />
|
||||
<Compile Include="OTHER\Fusion\EssentialsHuddleVtc1FusionController.cs" />
|
||||
<Compile Include="OTHER\Fusion\FusionCustomPropertiesBridge.cs" />
|
||||
<Compile Include="OTHER\Fusion\FusionEventHandlers.cs" />
|
||||
<Compile Include="OTHER\Fusion\FusionProcessorQueries.cs" />
|
||||
<Compile Include="OTHER\Fusion\FusionRviDataClasses.cs" />
|
||||
|
||||
@@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Devices.Common.Occupancy;
|
||||
|
||||
namespace PepperDash.Essentials.Room.Behaviours
|
||||
@@ -17,7 +18,7 @@ namespace PepperDash.Essentials.Room.Behaviours
|
||||
/// <summary>
|
||||
/// A device that when linked to a room can power the room on when enabled during scheduled hours.
|
||||
/// </summary>
|
||||
public class RoomOnToDefaultSourceWhenOccupied : Device
|
||||
public class RoomOnToDefaultSourceWhenOccupied : Device, IRuntimeConfigurableDevice
|
||||
{
|
||||
RoomOnToDefaultSourceWhenOccupiedConfig Config;
|
||||
|
||||
@@ -72,6 +73,13 @@ namespace PepperDash.Essentials.Room.Behaviours
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
SetUpDevice();
|
||||
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
void SetUpDevice()
|
||||
{
|
||||
Room = DeviceManager.GetDeviceForKey(Config.RoomKey) as EssentialsRoomBase;
|
||||
|
||||
@@ -109,20 +117,23 @@ namespace PepperDash.Essentials.Room.Behaviours
|
||||
Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e);
|
||||
}
|
||||
|
||||
AddEnableEventToGroup();
|
||||
if (!Config.EnableRoomOnWhenOccupied)
|
||||
FeatureEventGroup.ClearAllEvents();
|
||||
else
|
||||
{
|
||||
AddEnableEventToGroup();
|
||||
|
||||
AddDisableEventToGroup();
|
||||
AddDisableEventToGroup();
|
||||
|
||||
FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack);
|
||||
FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack);
|
||||
|
||||
FeatureEventGroup.EnableAllEvents();
|
||||
FeatureEventGroup.EnableAllEvents();
|
||||
}
|
||||
|
||||
FeatureEnabled = CheckIfFeatureShouldBeEnabled();
|
||||
}
|
||||
else
|
||||
Debug.Console(1, this, "Unable to get room from Device Manager with key: {0}", Config.RoomKey);
|
||||
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,6 +145,22 @@ namespace PepperDash.Essentials.Room.Behaviours
|
||||
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>
|
||||
/// Subscribe to feedback from RoomIsOccupiedFeedback on Room
|
||||
/// </summary>
|
||||
@@ -185,11 +212,16 @@ namespace PepperDash.Essentials.Room.Behaviours
|
||||
{
|
||||
if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, CalculateDaysOfWeekRecurrence()))
|
||||
{
|
||||
Debug.Console(1, this, "*****Feature Enabled by startup check.*****");
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(enabled)
|
||||
Debug.Console(1, this, "*****Feature Enabled*****");
|
||||
else
|
||||
Debug.Console(1, this, "*****Feature Disabled*****");
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Submodule essentials-framework updated: a8c1e17b12...09ff7fdc86
Reference in New Issue
Block a user