From 64ab315142c43770b4cab11989d91393d4ddc60e Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 9 May 2024 15:16:35 -0600 Subject: [PATCH] fix: various updates for room combining from testing --- .../EssentialsPartitionController.cs | 21 ++++++++++++------- .../IPartitionStateProvider.cs | 3 +++ .../Room/Combining/EssentialsRoomCombiner.cs | 10 ++++++--- .../Room/EssentialsRoomBase.cs | 1 + .../Timers/CountdownTimer.cs | 9 ++++++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs b/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs index 213cb835..225abb76 100644 --- a/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs +++ b/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; +using PepperDash.Core; namespace PepperDash.Essentials.Core { @@ -17,7 +18,7 @@ namespace PepperDash.Essentials.Core { private IPartitionStateProvider _partitionSensor; - private bool isInAutoMode; + public bool IsInAutoMode { get; private set; } private bool _partitionPresent; @@ -64,7 +65,7 @@ namespace PepperDash.Essentials.Core SetManualMode(); } } - else + else { SetManualMode(); } @@ -74,7 +75,7 @@ namespace PepperDash.Essentials.Core void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e) { - if (isInAutoMode) + if (IsInAutoMode) { PartitionPresentFeedback.FireUpdate(); } @@ -86,7 +87,7 @@ namespace PepperDash.Essentials.Core public void SetAutoMode() { - isInAutoMode = true; + IsInAutoMode = true; if (PartitionPresentFeedback != null) { PartitionPresentFeedback.SetValueFunc(() => _partitionSensor.PartitionPresentFeedback.BoolValue); @@ -98,13 +99,14 @@ namespace PepperDash.Essentials.Core if (_partitionSensor != null) { + _partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange; _partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange; } } public void SetManualMode() { - isInAutoMode = false; + IsInAutoMode = false; if (PartitionPresentFeedback != null) { PartitionPresentFeedback.SetValueFunc(() => _partitionPresent); @@ -123,7 +125,7 @@ namespace PepperDash.Essentials.Core public void SetPartitionStatePresent() { - if (!isInAutoMode) + if (!IsInAutoMode) { PartitionPresent = true; PartitionPresentFeedback.FireUpdate(); @@ -132,7 +134,7 @@ namespace PepperDash.Essentials.Core public void SetPartitionStateNotPresent() { - if (!isInAutoMode) + if (!IsInAutoMode) { PartitionPresent = false; PartitionPresentFeedback.FireUpdate(); @@ -141,7 +143,10 @@ namespace PepperDash.Essentials.Core public void ToggglePartitionState() { - if (!isInAutoMode) + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Toggling Partition State for {Key}", this); + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"IsInAutoMode: {IsInAutoMode}", this); + + if (!IsInAutoMode) { PartitionPresent = !PartitionPresent; PartitionPresentFeedback.FireUpdate(); diff --git a/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs b/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs index 60bd080e..418da80c 100644 --- a/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs +++ b/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs @@ -24,6 +24,9 @@ namespace PepperDash.Essentials.Core [JsonProperty("adjacentRoomKeys")] List AdjacentRoomKeys { get; } + [JsonProperty("isInAutoMode")] + bool IsInAutoMode { get; } + void SetPartitionStatePresent(); void SetPartitionStateNotPresent(); diff --git a/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs b/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs index 11b0a3ec..dfc1066a 100644 --- a/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs +++ b/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs @@ -137,7 +137,11 @@ namespace PepperDash.Essentials.Core void StartDebounceTimer() { - var time = _scenarioChangeDebounceTimeSeconds * 1000; + // default to 500ms for manual mode + var time = 500; + + // if in auto mode, debounce the scenario change + if(IsInAutoMode) time = _scenarioChangeDebounceTimeSeconds * 1000; if (_scenarioChangeDebounceTimer == null) { @@ -211,7 +215,7 @@ namespace PepperDash.Essentials.Core { _currentScenario.Activate(); - Debug.LogMessage(LogEventLevel.Debug, this, "Current Scenario: {0}", _currentScenario.Name); + Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this); } var handler = RoomCombinationScenarioChanged; @@ -246,7 +250,7 @@ namespace PepperDash.Essentials.Core public void TogglePartitionState(string partitionKey) { - var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionKey)) as IPartitionController; + var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionKey)); if (partition != null) { diff --git a/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs b/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs index 82693d4c..413e0ffc 100644 --- a/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs +++ b/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs @@ -141,6 +141,7 @@ namespace PepperDash.Essentials.Core if (!ShutdownPromptTimer.IsRunningFeedback.BoolValue) ShutdownType = eShutdownType.None; }; + ShutdownPromptTimer.HasFinished += (o, a) => Shutdown(); // Shutdown is triggered ShutdownPromptSeconds = 60; diff --git a/src/PepperDash.Essentials.Core/Timers/CountdownTimer.cs b/src/PepperDash.Essentials.Core/Timers/CountdownTimer.cs index 1cac0a50..cbb470d6 100644 --- a/src/PepperDash.Essentials.Core/Timers/CountdownTimer.cs +++ b/src/PepperDash.Essentials.Core/Timers/CountdownTimer.cs @@ -52,8 +52,8 @@ namespace PepperDash.Essentials.Core var timeSpan = FinishTime - DateTime.Now; - Debug.LogMessage(LogEventLevel.Verbose, this, - "timeSpan.Minutes == {0}, timeSpan.Seconds == {1}, timeSpan.TotalSeconds == {2}", + Debug.LogMessage(LogEventLevel.Verbose, + "timeSpan.Minutes == {0}, timeSpan.Seconds == {1}, timeSpan.TotalSeconds == {2}", this, timeSpan.Minutes, timeSpan.Seconds, timeSpan.TotalSeconds); if (Math.Floor(timeSpan.TotalSeconds) < 60 && Math.Floor(timeSpan.TotalSeconds) >= 0) //ignore milliseconds @@ -103,6 +103,7 @@ namespace PepperDash.Essentials.Core public void Reset() { _isRunning = false; + IsRunningFeedback.FireUpdate(); Start(); } @@ -133,7 +134,11 @@ namespace PepperDash.Essentials.Core void StopHelper() { if (_secondTimer != null) + { _secondTimer.Stop(); + _secondTimer = null; + } + _isRunning = false; IsRunningFeedback.FireUpdate(); }