mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Merge pull request #991 from PepperDash/hotfix/essentials-cooling-routing
Hotfix/essentials cooling routing
This commit is contained in:
@@ -211,6 +211,9 @@ namespace PepperDash.Essentials.Room.Config
|
|||||||
[JsonProperty("fusion")]
|
[JsonProperty("fusion")]
|
||||||
public EssentialsRoomFusionConfig Fusion { get; set; }
|
public EssentialsRoomFusionConfig Fusion { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("essentialsRoomUiBehaviorConfig", NullValueHandling=NullValueHandling.Ignore)]
|
||||||
|
public EssentialsRoomUiBehaviorConfig UiBehavior { get; set; }
|
||||||
|
|
||||||
[JsonProperty("zeroVolumeWhenSwtichingVolumeDevices")]
|
[JsonProperty("zeroVolumeWhenSwtichingVolumeDevices")]
|
||||||
public bool ZeroVolumeWhenSwtichingVolumeDevices { get; set; }
|
public bool ZeroVolumeWhenSwtichingVolumeDevices { get; set; }
|
||||||
|
|
||||||
@@ -227,6 +230,12 @@ namespace PepperDash.Essentials.Room.Config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EssentialsRoomUiBehaviorConfig
|
||||||
|
{
|
||||||
|
[JsonProperty("disableActivityButtonsWhileWarmingCooling")]
|
||||||
|
public bool DisableActivityButtonsWhileWarmingCooling { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class EssentialsAvRoomPropertiesConfig : EssentialsRoomPropertiesConfig
|
public class EssentialsAvRoomPropertiesConfig : EssentialsRoomPropertiesConfig
|
||||||
{
|
{
|
||||||
[JsonProperty("defaultAudioKey")]
|
[JsonProperty("defaultAudioKey")]
|
||||||
|
|||||||
@@ -32,9 +32,38 @@ namespace PepperDash.Essentials.Core
|
|||||||
bool _IsWarmingUp;
|
bool _IsWarmingUp;
|
||||||
bool _IsCoolingDown;
|
bool _IsCoolingDown;
|
||||||
|
|
||||||
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
|
protected override Func<bool> PowerIsOnFeedbackFunc
|
||||||
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
|
{
|
||||||
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
|
get
|
||||||
|
{
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "*************************************************** Display Power is {0}", _PowerIsOn ? "on" : "off");
|
||||||
|
return _PowerIsOn;
|
||||||
|
};
|
||||||
|
} }
|
||||||
|
protected override Func<bool> IsCoolingDownFeedbackFunc
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "*************************************************** {0}", _IsCoolingDown ? "Display is cooling down" : "Display has finished cooling down");
|
||||||
|
return _IsCoolingDown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override Func<bool> IsWarmingUpFeedbackFunc
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "*************************************************** {0}", _IsWarmingUp ? "Display is warming up" : "Display has finished warming up");
|
||||||
|
return _IsWarmingUp;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
|
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
|
||||||
|
|
||||||
int VolumeHeldRepeatInterval = 200;
|
int VolumeHeldRepeatInterval = 200;
|
||||||
@@ -61,7 +90,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
MuteFeedback = new BoolFeedback("MuteOn", () => _IsMuted);
|
MuteFeedback = new BoolFeedback("MuteOn", () => _IsMuted);
|
||||||
|
|
||||||
WarmupTime = 10000;
|
WarmupTime = 10000;
|
||||||
CooldownTime = 5000;
|
CooldownTime = 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PowerOn()
|
public override void PowerOn()
|
||||||
@@ -88,8 +117,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||||
{
|
{
|
||||||
_IsCoolingDown = true;
|
_IsCoolingDown = true;
|
||||||
_PowerIsOn = false;
|
|
||||||
PowerIsOnFeedback.InvokeFireUpdate();
|
|
||||||
IsCoolingDownFeedback.InvokeFireUpdate();
|
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||||
// Fake cool-down cycle
|
// Fake cool-down cycle
|
||||||
CooldownTimer = new CTimer(o =>
|
CooldownTimer = new CTimer(o =>
|
||||||
@@ -97,6 +124,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
Debug.Console(2, this, "Cooldown timer ending");
|
Debug.Console(2, this, "Cooldown timer ending");
|
||||||
_IsCoolingDown = false;
|
_IsCoolingDown = false;
|
||||||
IsCoolingDownFeedback.InvokeFireUpdate();
|
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||||
|
_PowerIsOn = false;
|
||||||
|
PowerIsOnFeedback.InvokeFireUpdate();
|
||||||
}, CooldownTime);
|
}, CooldownTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,34 @@ using PepperDash.Core;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
|
public class RouteRequest
|
||||||
|
{
|
||||||
|
public IRoutingSink Destination {get; set;}
|
||||||
|
public IRoutingOutputs Source {get; set;}
|
||||||
|
public eRoutingSignalType SignalType {get; set;}
|
||||||
|
|
||||||
|
public void HandleCooldown(object sender, FeedbackEventArgs args)
|
||||||
|
{
|
||||||
|
var coolingDevice = sender as IWarmingCooling;
|
||||||
|
|
||||||
|
if(args.BoolValue == false)
|
||||||
|
{
|
||||||
|
Destination.ReleaseAndMakeRoute(Source, SignalType);
|
||||||
|
|
||||||
|
if(sender == null) return;
|
||||||
|
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extensions added to any IRoutingInputs classes to provide discovery-based routing
|
/// Extensions added to any IRoutingInputs classes to provide discovery-based routing
|
||||||
/// on those destinations.
|
/// on those destinations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class IRoutingInputsExtensions
|
public static class IRoutingInputsExtensions
|
||||||
{
|
{
|
||||||
|
private static Dictionary<string, RouteRequest> RouteRequests = new Dictionary<string, RouteRequest>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute
|
/// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute
|
||||||
/// and then attempts a new Route and if sucessful, stores that RouteDescriptor
|
/// and then attempts a new Route and if sucessful, stores that RouteDescriptor
|
||||||
@@ -24,16 +46,64 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ReleaseAndMakeRoute(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType)
|
public static void ReleaseAndMakeRoute(this IRoutingSink destination, IRoutingOutputs source, eRoutingSignalType signalType)
|
||||||
{
|
{
|
||||||
destination.ReleaseRoute();
|
var routeRequest = new RouteRequest {
|
||||||
|
Destination = destination,
|
||||||
|
Source = source,
|
||||||
|
SignalType = signalType
|
||||||
|
};
|
||||||
|
|
||||||
if (source == null) return;
|
var coolingDevice = destination as IWarmingCooling;
|
||||||
var newRoute = destination.GetRouteToSource(source, signalType);
|
|
||||||
if (newRoute == null) return;
|
RouteRequest existingRouteRequest;
|
||||||
RouteDescriptorCollection.DefaultCollection.AddRouteDescriptor(newRoute);
|
|
||||||
Debug.Console(2, destination, "Executing full route");
|
//We already have a route request for this device, and it's a cooling device and is cooling
|
||||||
newRoute.ExecuteRoutes();
|
if (RouteRequests.TryGetValue(destination.Key, out existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true)
|
||||||
|
{
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown;
|
||||||
|
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown;
|
||||||
|
|
||||||
|
RouteRequests[destination.Key] = routeRequest;
|
||||||
|
|
||||||
|
Debug.Console(2, "******************************************************** Device: {0} is cooling down and already has a routing request stored. Storing new route request to route to source key: {1}", destination.Key, routeRequest.Source.Key);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//New Request
|
||||||
|
if (coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true)
|
||||||
|
{
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange -= routeRequest.HandleCooldown;
|
||||||
|
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown;
|
||||||
|
|
||||||
|
RouteRequests.Add(destination.Key, routeRequest);
|
||||||
|
|
||||||
|
Debug.Console(2, "******************************************************** Device: {0} is cooling down. Storing route request to route to source key: {1}", destination.Key, routeRequest.Source.Key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false)
|
||||||
|
{
|
||||||
|
RouteRequests.Remove(destination.Key);
|
||||||
|
Debug.Console(2, "******************************************************** Device: {0} is NOT cooling down. Removing stored route request and routing to source key: {1}", destination.Key, routeRequest.Source.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
destination.ReleaseRoute();
|
||||||
|
|
||||||
|
RunRouteRequest(routeRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RunRouteRequest(RouteRequest request)
|
||||||
|
{
|
||||||
|
if (request.Source == null) return;
|
||||||
|
var newRoute = request.Destination.GetRouteToSource(request.Source, request.SignalType);
|
||||||
|
if (newRoute == null) return;
|
||||||
|
RouteDescriptorCollection.DefaultCollection.AddRouteDescriptor(newRoute);
|
||||||
|
Debug.Console(2, request.Destination, "Executing full route");
|
||||||
|
newRoute.ExecuteRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will release the existing route on the destination, if it is found in
|
/// Will release the existing route on the destination, if it is found in
|
||||||
/// RouteDescriptorCollection.DefaultCollection
|
/// RouteDescriptorCollection.DefaultCollection
|
||||||
@@ -41,6 +111,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <param name="destination"></param>
|
/// <param name="destination"></param>
|
||||||
public static void ReleaseRoute(this IRoutingSink destination)
|
public static void ReleaseRoute(this IRoutingSink destination)
|
||||||
{
|
{
|
||||||
|
RouteRequest existingRequest;
|
||||||
|
|
||||||
|
if (RouteRequests.TryGetValue(destination.Key, out existingRequest) && destination is IWarmingCooling)
|
||||||
|
{
|
||||||
|
var coolingDevice = destination as IWarmingCooling;
|
||||||
|
|
||||||
|
coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRequest.HandleCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
RouteRequests.Remove(destination.Key);
|
||||||
|
|
||||||
var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination);
|
var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination);
|
||||||
if (current != null)
|
if (current != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user