Implemented Device Usage feature for Fusion.

This commit is contained in:
Neil Dorin
2017-08-18 12:37:09 -06:00
parent 1d54214c55
commit 710bfa3e8f
17 changed files with 477 additions and 325 deletions

View File

@@ -13,7 +13,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// A bridge class to cover the basic features of GenericBase hardware
/// </summary>
public class CrestronGenericBaseDevice : Device, IOnline, IHasFeedback, ICommunicationMonitor
public class CrestronGenericBaseDevice : Device, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
{
public virtual GenericBase Hardware { get; protected set; }
@@ -87,7 +87,13 @@ namespace PepperDash.Essentials.Core
#region IStatusMonitor Members
public StatusMonitorBase CommunicationMonitor { get; private set; }
#endregion
#endregion
#region IUsageTracking Members
public UsageTracking UsageTracker { get; set; }
#endregion
}
//***********************************************************************************

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Essentials.Core
{
public interface IUsageTracking
{
UsageTracking UsageTracker { get; set; }
}
//public static class IUsageTrackingExtensions
//{
// public static void EnableUsageTracker(this IUsageTracking device)
// {
// device.UsageTracker = new UsageTracking();
// }
//}
public class UsageTracking
{
public event EventHandler<DeviceUsageEventArgs> DeviceUsageEnded;
public InUseTracking InUseTracker { get; protected set; }
public bool UsageIsTracked { get; set; }
public DateTime UsageStartTime { get; protected set; }
public DateTime UsageEndTime { get; protected set; }
public UsageTracking()
{
InUseTracker.InUseFeedback.OutputChange +=new EventHandler<EventArgs>(InUseFeedback_OutputChange);
}
void InUseFeedback_OutputChange(object sender, EventArgs e)
{
if(InUseTracker.InUseFeedback.BoolValue)
{
StartDeviceUsage();
}
else
{
EndDeviceUsage();
}
}
/// <summary>
/// Stores the usage start time
/// </summary>
public void StartDeviceUsage()
{
UsageStartTime = DateTime.Now;
}
/// <summary>
/// Calculates the difference between the usage start and end times, gets the total minutes used and fires an event to pass that info to a consumer
/// </summary>
public void EndDeviceUsage()
{
UsageEndTime = DateTime.Now;
var timeUsed = UsageEndTime - UsageStartTime;
var handler = DeviceUsageEnded;
if (handler != null)
{
handler(this, new DeviceUsageEventArgs() { UsageEndTime = UsageEndTime, MinutesUsed = timeUsed.Minutes });
}
}
}
public class DeviceUsageEventArgs : EventArgs
{
public DateTime UsageEndTime { get; set; }
public int MinutesUsed { get; set; }
}
}

View File

@@ -16,12 +16,14 @@ namespace PepperDash.Essentials.Core
/// <summary>
///
/// </summary>
public abstract class DisplayBase : Device, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling
public abstract class DisplayBase : Device, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling, IUsageTracking
{
public BoolFeedback PowerIsOnFeedback { get; protected set; }
public BoolFeedback IsCoolingDownFeedback { get; protected set; }
public BoolFeedback IsWarmingUpFeedback { get; private set; }
public UsageTracking UsageTracker { get; set; }
public uint WarmupTime { get; set; }
public uint CooldownTime { get; set; }
@@ -77,7 +79,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
///
/// </summary>
public abstract class TwoWayDisplayBase : DisplayBase
public abstract class TwoWayDisplayBase : DisplayBase
{
public StringFeedback CurrentInputFeedback { get; private set; }
@@ -104,6 +106,8 @@ namespace PepperDash.Essentials.Core
CooldownTime = 15000;
Feedbacks.Add(CurrentInputFeedback);
}
}

View File

@@ -115,6 +115,7 @@
<Compile Include="Config\DeviceConfig.cs" />
<Compile Include="Constants\CommonCues.cs" />
<Compile Include="Devices\DisplayUiConstants.cs" />
<Compile Include="Devices\IUsageTracking.cs" />
<Compile Include="Devices\REMOVE DeviceConfig.cs" />
<Compile Include="Devices\DeviceJsonApi.cs" />
<Compile Include="Devices\SourceListItem.cs" />