Skip to content

Commit

Permalink
fix: remove event sub for route request
Browse files Browse the repository at this point in the history
When route requests made during a destination's cooldown cycle were handled, the event subscription was *NOT* being removed, resulting in the request being run on *EVERY* subsequent cooldown complete event.
  • Loading branch information
Andrew Welker committed Nov 22, 2024
1 parent 35d7994 commit f4c5e6f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/PepperDash.Essentials.Core/Routing/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutp
SignalType = signalType
};

var coolingDevice = destination as IWarmingCooling;


var coolingDevice = destination as IWarmingCooling;

//We already have a route request for this device, and it's a cooling device and is cooling
if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRouteRequest) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == true)
{
{
coolingDevice.IsCoolingDownFeedback.OutputChange -= existingRouteRequest.HandleCooldown;

coolingDevice.IsCoolingDownFeedback.OutputChange += routeRequest.HandleCooldown;
Expand All @@ -80,20 +81,23 @@ private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutp

//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.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down. Storing route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down. Storing route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
return;
}

if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false)
{
var handledRequest = RouteRequests[destination.Key];

coolingDevice.IsCoolingDownFeedback.OutputChange -= handledRequest.HandleCooldown;

RouteRequests.Remove(destination.Key);

Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is NOT cooling down. Removing stored route request and routing to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
}

Expand Down

0 comments on commit f4c5e6f

Please sign in to comment.