Renamed Config in Essentials room type classes to PropertiesConfig and modified EssentialsRoomBase to derive from ReconfigurableDevice

This commit is contained in:
Neil Dorin
2018-09-13 16:50:08 -06:00
parent 065075aabd
commit 8dabe732ec
14 changed files with 762 additions and 948 deletions

View File

@@ -11,6 +11,7 @@ using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Devices.Common.Occupancy;
namespace PepperDash.Essentials.Room.Behaviours
@@ -18,9 +19,9 @@ 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, IRuntimeConfigurableDevice
public class RoomOnToDefaultSourceWhenOccupied : ReconfigurableDevice
{
RoomOnToDefaultSourceWhenOccupiedConfig Config;
RoomOnToDefaultSourceWhenOccupiedConfig PropertiesConfig;
public bool FeatureEnabled { get; private set; }
@@ -42,10 +43,10 @@ namespace PepperDash.Essentials.Room.Behaviours
private Fusion.EssentialsHuddleSpaceFusionSystemControllerBase FusionRoom;
public RoomOnToDefaultSourceWhenOccupied(string key, RoomOnToDefaultSourceWhenOccupiedConfig config)
: base(key)
public RoomOnToDefaultSourceWhenOccupied(DeviceConfig config) :
base (config)
{
Config = config;
PropertiesConfig = JsonConvert.DeserializeObject<RoomOnToDefaultSourceWhenOccupiedConfig>(config.Properties.ToString());
FeatureEventGroup = new ScheduledEventGroup(this.Key);
@@ -63,7 +64,7 @@ namespace PepperDash.Essentials.Room.Behaviours
else
Debug.Console(1, this, "Room has no RoomOccupancy object set");
var fusionRoomKey = Config.RoomKey + "-fusion";
var fusionRoomKey = PropertiesConfig.RoomKey + "-fusion";
FusionRoom = DeviceManager.GetDeviceForKey(fusionRoomKey) as Fusion.EssentialsHuddleSpaceFusionSystemControllerBase;
@@ -79,45 +80,48 @@ namespace PepperDash.Essentials.Room.Behaviours
return base.CustomActivate();
}
/// <summary>
/// Sets up device based on config values
/// </summary>
void SetUpDevice()
{
Room = DeviceManager.GetDeviceForKey(Config.RoomKey) as EssentialsRoomBase;
Room = DeviceManager.GetDeviceForKey(PropertiesConfig.RoomKey) as EssentialsRoomBase;
if (Room != null)
{
try
{
FeatureEnabledTime = DateTime.Parse(Config.OccupancyStartTime);
FeatureEnabledTime = DateTime.Parse(PropertiesConfig.OccupancyStartTime);
if (FeatureEnabledTime != null)
{
Debug.Console(1, this, "Enabled Time: {0}", FeatureEnabledTime.ToString());
}
else
Debug.Console(1, this, "Unable to parse {0} to DateTime", Config.OccupancyStartTime);
Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyStartTime);
}
catch (Exception e)
{
Debug.Console(1, this, "Unable to parse OccupancyStartTime property: {0} \n Error: {1}", Config.OccupancyStartTime, e);
Debug.Console(1, this, "Unable to parse OccupancyStartTime property: {0} \n Error: {1}", PropertiesConfig.OccupancyStartTime, e);
}
try
{
FeatureDisabledTime = DateTime.Parse(Config.OccupancyEndTime);
FeatureDisabledTime = DateTime.Parse(PropertiesConfig.OccupancyEndTime);
if (FeatureDisabledTime != null)
{
Debug.Console(1, this, "Disabled Time: {0}", FeatureDisabledTime.ToString());
}
else
Debug.Console(1, this, "Unable to parse {0} to DateTime", Config.OccupancyEndTime);
Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyEndTime);
}
catch (Exception e)
{
Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e);
}
if (!Config.EnableRoomOnWhenOccupied)
if (!PropertiesConfig.EnableRoomOnWhenOccupied)
FeatureEventGroup.ClearAllEvents();
else
{
@@ -133,30 +137,18 @@ namespace PepperDash.Essentials.Room.Behaviours
FeatureEnabled = CheckIfFeatureShouldBeEnabled();
}
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}", PropertiesConfig.RoomKey);
}
/// <summary>
/// Returns a JObject of the device config properties as they currently exist at runtime
/// </summary>
/// <returns></returns>
public JToken GetLocalConfigProperties()
protected override void CustomSetConfig(DeviceConfig config)
{
return JToken.FromObject(Config);
}
var newPropertiesConfig = JsonConvert.DeserializeObject<RoomOnToDefaultSourceWhenOccupiedConfig>(config.Properties.ToString());
public object GetDeviceConfig()
{
return Config;
}
if(newPropertiesConfig != null)
PropertiesConfig = newPropertiesConfig;
public void SetDeviceConfig(object config)
{
var newConfig = config as RoomOnToDefaultSourceWhenOccupiedConfig;
Config = newConfig;
ConfigWriter.UpdateDeviceProperties(this.Key, GetLocalConfigProperties());
ConfigWriter.UpdateDeviceConfig(config);
SetUpDevice();
}
@@ -182,7 +174,7 @@ namespace PepperDash.Essentials.Room.Behaviours
{
if (SchEvent.Name == FeatureEnableEventName)
{
if (Config.EnableRoomOnWhenOccupied)
if (PropertiesConfig.EnableRoomOnWhenOccupied)
FeatureEnabled = true;
Debug.Console(1, this, "*****Feature Enabled by event.*****");
@@ -204,7 +196,7 @@ namespace PepperDash.Essentials.Room.Behaviours
{
bool enabled = false;
if(Config.EnableRoomOnWhenOccupied)
if(PropertiesConfig.EnableRoomOnWhenOccupied)
{
Debug.Console(1, this, "Current Time: {0} \n FeatureEnabledTime: {1} \n FeatureDisabledTime: {2}", DateTime.Now, FeatureEnabledTime, FeatureDisabledTime);
@@ -446,19 +438,19 @@ namespace PepperDash.Essentials.Room.Behaviours
{
ScheduledEventCommon.eWeekDays value = new ScheduledEventCommon.eWeekDays();
if (Config.EnableSunday)
if (PropertiesConfig.EnableSunday)
value = value | ScheduledEventCommon.eWeekDays.Sunday;
if (Config.EnableMonday)
if (PropertiesConfig.EnableMonday)
value = value | ScheduledEventCommon.eWeekDays.Monday;
if (Config.EnableTuesday)
if (PropertiesConfig.EnableTuesday)
value = value | ScheduledEventCommon.eWeekDays.Tuesday;
if (Config.EnableWednesday)
if (PropertiesConfig.EnableWednesday)
value = value | ScheduledEventCommon.eWeekDays.Wednesday;
if (Config.EnableThursday)
if (PropertiesConfig.EnableThursday)
value = value | ScheduledEventCommon.eWeekDays.Thursday;
if (Config.EnableFriday)
if (PropertiesConfig.EnableFriday)
value = value | ScheduledEventCommon.eWeekDays.Friday;
if (Config.EnableSaturday)
if (PropertiesConfig.EnableSaturday)
value = value | ScheduledEventCommon.eWeekDays.Saturday;
return value;
@@ -473,7 +465,7 @@ namespace PepperDash.Essentials.Room.Behaviours
{
if (type == ScheduledEventCommon.eCallbackReason.NormalExpiration)
{
if(Config.EnableRoomOnWhenOccupied)
if(PropertiesConfig.EnableRoomOnWhenOccupied)
FeatureEnabled = true;
Debug.Console(1, this, "RoomOnToDefaultSourceWhenOccupied Feature Enabled.");

View File

@@ -66,7 +66,7 @@ namespace PepperDash.Essentials
}
}
public EssentialsRoomPropertiesConfig Config { get; private set; }
public EssentialsRoomPropertiesConfig PropertiesConfig { get; private set; }
public IRoutingSinkWithSwitching DefaultDisplay { get; private set; }
public IRoutingSinkNoSwitching DefaultAudioDevice { get; private set; }
@@ -156,7 +156,7 @@ namespace PepperDash.Essentials
IRoutingSinkNoSwitching defaultAudio, EssentialsRoomPropertiesConfig config)
: base(key, name)
{
Config = config;
PropertiesConfig = config;
DefaultDisplay = defaultDisplay;
DefaultAudioDevice = defaultAudio;
if (defaultAudio is IBasicVolumeControls)

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,7 @@ using Crestron.SimplSharp.Scheduler;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Devices.Common.Occupancy;
namespace PepperDash.Essentials
@@ -14,7 +15,7 @@ namespace PepperDash.Essentials
/// <summary>
///
/// </summary>
public abstract class EssentialsRoomBase : Device
public abstract class EssentialsRoomBase : ReconfigurableDevice
{
/// <summary>
///
@@ -80,12 +81,9 @@ namespace PepperDash.Essentials
/// </summary>
public bool ZeroVolumeWhenSwtichingVolumeDevices { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public EssentialsRoomBase(string key, string name) : base(key, name)
public EssentialsRoomBase(DeviceConfig config)
: base(config)
{
// Setup the ShutdownPromptTimer
ShutdownPromptTimer = new SecondsCountdownTimer(Key + "-offTimer");
@@ -124,6 +122,50 @@ namespace PepperDash.Essentials
});
}
///// <summary>
/////
///// </summary>
///// <param name="key"></param>
///// <param name="name"></param>
//public EssentialsRoomBase(string key, string name) : base(key, name)
//{
// // Setup the ShutdownPromptTimer
// ShutdownPromptTimer = new SecondsCountdownTimer(Key + "-offTimer");
// ShutdownPromptTimer.IsRunningFeedback.OutputChange += (o, a) =>
// {
// if (!ShutdownPromptTimer.IsRunningFeedback.BoolValue)
// ShutdownType = eShutdownType.None;
// };
// ShutdownPromptTimer.HasFinished += (o, a) => Shutdown(); // Shutdown is triggered
// ShutdownPromptSeconds = 60;
// ShutdownVacancySeconds = 120;
// ShutdownType = eShutdownType.None;
// RoomVacancyShutdownTimer = new SecondsCountdownTimer(Key + "-vacancyOffTimer");
// //RoomVacancyShutdownTimer.IsRunningFeedback.OutputChange += (o, a) =>
// //{
// // if (!RoomVacancyShutdownTimer.IsRunningFeedback.BoolValue)
// // ShutdownType = ShutdownType.Vacancy;
// //};
// RoomVacancyShutdownTimer.HasFinished += new EventHandler<EventArgs>(RoomVacancyShutdownPromptTimer_HasFinished); // Shutdown is triggered
// RoomVacancyShutdownPromptSeconds = 1500; // 25 min to prompt warning
// RoomVacancyShutdownSeconds = 240; // 4 min after prompt will trigger shutdown prompt
// VacancyMode = eVacancyMode.None;
// OnFeedback = new BoolFeedback(OnFeedbackFunc);
// IsWarmingUpFeedback = new BoolFeedback(IsWarmingFeedbackFunc);
// IsCoolingDownFeedback = new BoolFeedback(IsCoolingFeedbackFunc);
// AddPostActivationAction(() =>
// {
// if (RoomOccupancy != null)
// OnRoomOccupancyIsSet();
// });
//}
void RoomVacancyShutdownPromptTimer_HasFinished(object sender, EventArgs e)
{
switch (VacancyMode)