Cleanup for EssentialHuddleSpaceRoom

This commit is contained in:
Andrew Welker
2020-06-24 09:39:43 -06:00
parent 78f4cd6abe
commit 013bcfd9d4

View File

@@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -33,9 +31,7 @@ namespace PepperDash.Essentials
}; };
} }
} }
/// <summary>
///
/// </summary>
protected override Func<bool> IsWarmingFeedbackFunc protected override Func<bool> IsWarmingFeedbackFunc
{ {
get get
@@ -43,16 +39,11 @@ namespace PepperDash.Essentials
return () => return () =>
{ {
var disp = DefaultDisplay as DisplayBase; var disp = DefaultDisplay as DisplayBase;
if (disp != null) return disp != null && disp.IsWarmingUpFeedback.BoolValue;
return disp.IsWarmingUpFeedback.BoolValue;
else
return false;
}; };
} }
} }
/// <summary>
///
/// </summary>
protected override Func<bool> IsCoolingFeedbackFunc protected override Func<bool> IsCoolingFeedbackFunc
{ {
get get
@@ -60,10 +51,7 @@ namespace PepperDash.Essentials
return () => return () =>
{ {
var disp = DefaultDisplay as DisplayBase; var disp = DefaultDisplay as DisplayBase;
if (disp != null) return disp != null && disp.IsCoolingDownFeedback.BoolValue;
return disp.IsCoolingDownFeedback.BoolValue;
else
return false;
}; };
} }
} }
@@ -84,63 +72,63 @@ namespace PepperDash.Essentials
/// If room is off, enables power on to last source. Default true /// If room is off, enables power on to last source. Default true
/// </summary> /// </summary>
public bool EnablePowerOnToLastSource { get; set; } public bool EnablePowerOnToLastSource { get; set; }
string LastSourceKey; string _lastSourceKey;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public IBasicVolumeControls CurrentVolumeControls public IBasicVolumeControls CurrentVolumeControls
{ {
get { return _CurrentAudioDevice; } get { return _currentAudioDevice; }
set set
{ {
if (value == _CurrentAudioDevice) return; if (value == _currentAudioDevice) return;
var oldDev = _CurrentAudioDevice; var oldDev = _currentAudioDevice;
// derigister this room from the device, if it can // derigister this room from the device, if it can
if (oldDev is IInUseTracking) if (oldDev is IInUseTracking)
(oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio"); (oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio");
var handler = CurrentVolumeDeviceChange; var handler = CurrentVolumeDeviceChange;
if (handler != null) if (handler != null)
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange)); CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange));
_CurrentAudioDevice = value; _currentAudioDevice = value;
if (handler != null) if (handler != null)
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange)); CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange));
// register this room with new device, if it can // register this room with new device, if it can
if (_CurrentAudioDevice is IInUseTracking) if (_currentAudioDevice is IInUseTracking)
(_CurrentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio"); (_currentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio");
} }
} }
IBasicVolumeControls _CurrentAudioDevice; IBasicVolumeControls _currentAudioDevice;
/// <summary> /// <summary>
/// The SourceListItem last run - containing names and icons /// The SourceListItem last run - containing names and icons
/// </summary> /// </summary>
public SourceListItem CurrentSourceInfo public SourceListItem CurrentSourceInfo
{ {
get { return _CurrentSourceInfo; } get { return _currentSourceInfo; }
set set
{ {
if (value == _CurrentSourceInfo) return; if (value == _currentSourceInfo) return;
var handler = CurrentSourceChange; var handler = CurrentSourceChange;
// remove from in-use tracker, if so equipped // remove from in-use tracker, if so equipped
if(_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking) if(_currentSourceInfo != null && _currentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control"); (_currentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
if (handler != null) if (handler != null)
handler(_CurrentSourceInfo, ChangeType.WillChange); handler(_currentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value; _currentSourceInfo = value;
// add to in-use tracking // add to in-use tracking
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking) if (_currentSourceInfo != null && _currentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control"); (_currentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
if (handler != null) if (handler != null)
handler( _CurrentSourceInfo, ChangeType.DidChange); handler( _currentSourceInfo, ChangeType.DidChange);
} }
} }
SourceListItem _CurrentSourceInfo; SourceListItem _currentSourceInfo;
public string CurrentSourceInfoKey { get; set; } public string CurrentSourceInfoKey { get; set; }
@@ -193,13 +181,24 @@ namespace PepperDash.Essentials
disp.IsWarmingUpFeedback.OutputChange += (o, a) => disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
{ {
IsWarmingUpFeedback.FireUpdate(); IsWarmingUpFeedback.FireUpdate();
if (!IsWarmingUpFeedback.BoolValue)
(DefaultDisplay as IBasicVolumeWithFeedback).SetVolume(DefaultVolume); if (IsWarmingUpFeedback.BoolValue)
};
disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
{ {
IsCoolingDownFeedback.FireUpdate(); return;
}
var display = DefaultDisplay as IBasicVolumeWithFeedback;
if (display == null)
{
Debug.Console(0, this, Debug.ErrorLogLevel.Error,
"Default display {0} is not volume control control provider", DefaultDisplay.Key);
return;
}
display.SetVolume(DefaultVolume);
}; };
disp.IsCoolingDownFeedback.OutputChange += (o, a) => IsCoolingDownFeedback.FireUpdate();
} }
SourceListKey = "default"; SourceListKey = "default";
@@ -251,7 +250,7 @@ namespace PepperDash.Essentials
{ {
// Add Occupancy object from config // Add Occupancy object from config
if (PropertiesConfig.Occupancy != null) if (PropertiesConfig.Occupancy != null)
this.SetRoomOccupancy(DeviceManager.GetDeviceForKey(PropertiesConfig.Occupancy.DeviceKey) as SetRoomOccupancy(DeviceManager.GetDeviceForKey(PropertiesConfig.Occupancy.DeviceKey) as
IOccupancyStatusProvider, PropertiesConfig.Occupancy.TimeoutMinutes); IOccupancyStatusProvider, PropertiesConfig.Occupancy.TimeoutMinutes);
this.LogoUrlLightBkgnd = PropertiesConfig.LogoLight.GetLogoUrlLight(); this.LogoUrlLightBkgnd = PropertiesConfig.LogoLight.GetLogoUrlLight();
@@ -269,15 +268,14 @@ namespace PepperDash.Essentials
/// <param name="routeKey"></param> /// <param name="routeKey"></param>
public void RunRouteAction(string routeKey) public void RunRouteAction(string routeKey)
{ {
RunRouteAction(routeKey, new Action(() => { })); RunRouteAction(routeKey, () => { });
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="routeKey"></param> /// <param name="routeKey"></param>
/// <param name="souceListKey"></param> /// <param name="sourceListKey"></param>
/// <param name="successCallback"></param>
public void RunRouteAction(string routeKey, string sourceListKey) public void RunRouteAction(string routeKey, string sourceListKey)
{ {
RunRouteAction(routeKey, new Action(() => { })); RunRouteAction(routeKey, new Action(() => { }));
@@ -287,7 +285,7 @@ namespace PepperDash.Essentials
/// ///
/// </summary> /// </summary>
/// <param name="routeKey"></param> /// <param name="routeKey"></param>
/// <param name="souceListKey"></param> /// <param name="sourceListKey"></param>
/// <param name="successCallback"></param> /// <param name="successCallback"></param>
public void RunRouteAction(string routeKey, string sourceListKey, Action successCallback) public void RunRouteAction(string routeKey, string sourceListKey, Action successCallback)
{ {
@@ -303,11 +301,11 @@ namespace PepperDash.Essentials
/// Gets a source from config list SourceListKey and dynamically build and executes the /// Gets a source from config list SourceListKey and dynamically build and executes the
/// route or commands /// route or commands
/// </summary> /// </summary>
/// <param name="name"></param>
public void RunRouteAction(string routeKey, Action successCallback) public void RunRouteAction(string routeKey, Action successCallback)
{ {
// Run this on a separate thread // Run this on a separate thread
new CTimer(o => //new CTimer
CrestronInvoke.BeginInvoke(o =>
{ {
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Run route action '{0}'", routeKey); Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Run route action '{0}'", routeKey);
var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey); var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
@@ -330,13 +328,13 @@ namespace PepperDash.Essentials
// item.SourceKey, item.RouteList.Count); // item.SourceKey, item.RouteList.Count);
// End usage timer on last source // End usage timer on last source
if (!string.IsNullOrEmpty(LastSourceKey)) if (!string.IsNullOrEmpty(_lastSourceKey))
{ {
var lastSource = dict[LastSourceKey].SourceDevice; var lastSource = dict[_lastSourceKey].SourceDevice;
try try
{ {
if (lastSource != null && lastSource is IUsageTracking) if (lastSource is IUsageTracking)
(lastSource as IUsageTracking).UsageTracker.EndDeviceUsage(); (lastSource as IUsageTracking).UsageTracker.EndDeviceUsage();
} }
catch (Exception e) catch (Exception e)
@@ -348,7 +346,7 @@ namespace PepperDash.Essentials
// Let's run it // Let's run it
if (routeKey.ToLower() != "roomoff") if (routeKey.ToLower() != "roomoff")
{ {
LastSourceKey = routeKey; _lastSourceKey = routeKey;
} }
else else
{ {
@@ -458,9 +456,9 @@ namespace PepperDash.Essentials
/// </summary> /// </summary>
public override void PowerOnToDefaultOrLastSource() public override void PowerOnToDefaultOrLastSource()
{ {
if (!EnablePowerOnToLastSource || LastSourceKey == null) if (!EnablePowerOnToLastSource || _lastSourceKey == null)
return; return;
RunRouteAction(LastSourceKey); RunRouteAction(_lastSourceKey);
} }
/// <summary> /// <summary>
@@ -479,9 +477,9 @@ namespace PepperDash.Essentials
/// </summary> /// </summary>
/// <param name="route"></param> /// <param name="route"></param>
/// <returns></returns> /// <returns></returns>
bool DoRoute(SourceRouteListItem route) private bool DoRoute(SourceRouteListItem route)
{ {
IRoutingSink dest = null; IRoutingSink dest;
if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase)) if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase))
dest = DefaultAudioDevice; dest = DefaultAudioDevice;
@@ -525,10 +523,10 @@ namespace PepperDash.Essentials
/// </summary> /// </summary>
public static void AllRoomsOff() public static void AllRoomsOff()
{ {
var allRooms = DeviceManager.AllDevices.Where(d => var allRooms = DeviceManager.AllDevices.OfType<EssentialsHuddleSpaceRoom>().Where(d =>
d is EssentialsHuddleSpaceRoom && !(d as EssentialsHuddleSpaceRoom).ExcludeFromGlobalFunctions); !d.ExcludeFromGlobalFunctions);
foreach (var room in allRooms) foreach (var room in allRooms)
(room as EssentialsHuddleSpaceRoom).RunRouteAction("roomOff"); room.RunRouteAction("roomOff");
} }
} }
} }