diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasInputs.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasInputs.cs index ef806d9a..3a9ac617 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasInputs.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasInputs.cs @@ -15,10 +15,8 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces /// /// See MockDisplay for example implemntation /// - public interface IHasInputs: IKeyName + public interface IHasInputs: IKeyName { - ISelectableItems Inputs { get; } - - void SetInput(TSelector selector); + ISelectableItems Inputs { get; } } } diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/ISelectableItems.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/ISelectableItems.cs index c1451afb..0d3968df 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/ISelectableItems.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/ISelectableItems.cs @@ -17,6 +17,6 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces Dictionary Items { get; set; } [JsonProperty("currentItem")] - string CurrentItem { get; set; } + TKey CurrentItem { get; set; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs b/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs index 7066be0e..213cb835 100644 --- a/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs +++ b/src/PepperDash.Essentials.Core/PartitionSensor/EssentialsPartitionController.cs @@ -19,7 +19,29 @@ namespace PepperDash.Essentials.Core private bool isInAutoMode; - private bool partitionPresent; + private bool _partitionPresent; + + public bool PartitionPresent + { + get + { + return _partitionPresent; + } + set + { + if (_partitionPresent == value) + { + return; + } + + _partitionPresent = value; + + if (PartitionPresentFeedback != null) + { + PartitionPresentFeedback.FireUpdate(); + } + } + } public EssentialsPartitionController(string key, string name, IPartitionStateProvider sensor, bool defaultToManualMode, List adjacentRoomKeys) { @@ -42,7 +64,7 @@ namespace PepperDash.Essentials.Core SetManualMode(); } } - else + else { SetManualMode(); } @@ -85,11 +107,11 @@ namespace PepperDash.Essentials.Core isInAutoMode = false; if (PartitionPresentFeedback != null) { - PartitionPresentFeedback.SetValueFunc(() => partitionPresent); + PartitionPresentFeedback.SetValueFunc(() => _partitionPresent); } else { - PartitionPresentFeedback = new BoolFeedback(() => partitionPresent); + PartitionPresentFeedback = new BoolFeedback(() => _partitionPresent); } if (_partitionSensor != null) @@ -103,7 +125,7 @@ namespace PepperDash.Essentials.Core { if (!isInAutoMode) { - partitionPresent = true; + PartitionPresent = true; PartitionPresentFeedback.FireUpdate(); } } @@ -112,7 +134,7 @@ namespace PepperDash.Essentials.Core { if (!isInAutoMode) { - partitionPresent = false; + PartitionPresent = false; PartitionPresentFeedback.FireUpdate(); } } @@ -121,7 +143,7 @@ namespace PepperDash.Essentials.Core { if (!isInAutoMode) { - partitionPresent = !partitionPresent; + PartitionPresent = !PartitionPresent; PartitionPresentFeedback.FireUpdate(); } } diff --git a/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs b/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs index adb420b7..60bd080e 100644 --- a/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs +++ b/src/PepperDash.Essentials.Core/PartitionSensor/IPartitionStateProvider.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; - +using System.Collections.Generic; +using Newtonsoft.Json; using PepperDash.Core; namespace PepperDash.Essentials.Core @@ -13,7 +9,11 @@ namespace PepperDash.Essentials.Core /// public interface IPartitionStateProvider : IKeyName { + [JsonIgnore] BoolFeedback PartitionPresentFeedback { get; } + + [JsonProperty("partitionPresent")] + bool PartitionPresent { get; } } /// @@ -21,6 +21,7 @@ namespace PepperDash.Essentials.Core /// public interface IPartitionController : IPartitionStateProvider { + [JsonProperty("adjacentRoomKeys")] List AdjacentRoomKeys { get; } void SetPartitionStatePresent(); diff --git a/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs b/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs index ac5df758..11b0a3ec 100644 --- a/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs +++ b/src/PepperDash.Essentials.Core/Room/Combining/EssentialsRoomCombiner.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using Serilog.Events; +using Newtonsoft.Json; namespace PepperDash.Essentials.Core { @@ -17,7 +17,33 @@ namespace PepperDash.Essentials.Core private List _rooms; - private bool isInAutoMode; + public List Rooms + { + get + { + return _rooms.Cast().ToList(); + } + } + + private bool _isInAutoMode; + + public bool IsInAutoMode + { + get + { + return _isInAutoMode; + } + set + { + if(value == _isInAutoMode) + { + return; + } + + _isInAutoMode = value; + IsInAutoModeFeedback.FireUpdate(); + } + } private CTimer _scenarioChangeDebounceTimer; @@ -36,14 +62,14 @@ namespace PepperDash.Essentials.Core _scenarioChangeDebounceTimeSeconds = _propertiesConfig.ScenarioChangeDebounceTimeSeconds; } - IsInAutoModeFeedback = new BoolFeedback(() => isInAutoMode); + IsInAutoModeFeedback = new BoolFeedback(() => _isInAutoMode); // default to auto mode - isInAutoMode = true; + IsInAutoMode = true; if (_propertiesConfig.defaultToManualMode) { - isInAutoMode = false; + IsInAutoMode = false; } IsInAutoModeFeedback.FireUpdate(); @@ -56,7 +82,7 @@ namespace PepperDash.Essentials.Core SetRooms(); - if (isInAutoMode) + if (IsInAutoMode) { DetermineRoomCombinationScenario(); } @@ -201,20 +227,17 @@ namespace PepperDash.Essentials.Core public void SetAutoMode() { - isInAutoMode = true; - IsInAutoModeFeedback.FireUpdate(); + IsInAutoMode = true; } public void SetManualMode() { - isInAutoMode = false; - IsInAutoModeFeedback.FireUpdate(); + IsInAutoMode = false; } public void ToggleMode() { - isInAutoMode = !isInAutoMode; - IsInAutoModeFeedback.FireUpdate(); + IsInAutoMode = !IsInAutoMode; } public List RoomCombinationScenarios { get; private set; } @@ -233,7 +256,7 @@ namespace PepperDash.Essentials.Core public void SetRoomCombinationScenario(string scenarioKey) { - if (isInAutoMode) + if (IsInAutoMode) { Debug.LogMessage(LogEventLevel.Information, this, "Cannot set room combination scenario when in auto mode. Set to auto mode first."); return; diff --git a/src/PepperDash.Essentials.Core/Room/Combining/IEssentialsRoomCombiner.cs b/src/PepperDash.Essentials.Core/Room/Combining/IEssentialsRoomCombiner.cs index e6bdd983..0d4a40cc 100644 --- a/src/PepperDash.Essentials.Core/Room/Combining/IEssentialsRoomCombiner.cs +++ b/src/PepperDash.Essentials.Core/Room/Combining/IEssentialsRoomCombiner.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; - +using Newtonsoft.Json; using PepperDash.Core; namespace PepperDash.Essentials.Core @@ -21,13 +18,21 @@ namespace PepperDash.Essentials.Core /// /// The current room combination scenario /// + [JsonProperty("currentScenario")] IRoomCombinationScenario CurrentScenario { get; } /// /// When true, indicates the current mode is auto mode /// + [JsonIgnore] BoolFeedback IsInAutoModeFeedback {get;} + [JsonProperty("isInAutoMode")] + bool IsInAutoMode { get; } + + [JsonProperty("rooms")] + List Rooms { get; } + /// /// Sets auto mode /// @@ -46,11 +51,13 @@ namespace PepperDash.Essentials.Core /// /// The available room combinatino scenarios /// + [JsonProperty("roomCombinationScenarios")] List RoomCombinationScenarios { get; } /// /// The partition /// + [JsonProperty("partitions")] List Partitions { get; } /// @@ -71,8 +78,12 @@ namespace PepperDash.Essentials.Core /// /// When true, indicates that this room combination scenario is active /// + [JsonIgnore] BoolFeedback IsActiveFeedback { get; } + [JsonProperty("isActive")] + bool IsActive { get; } + /// /// Activates this room combination scenario /// @@ -86,11 +97,13 @@ namespace PepperDash.Essentials.Core /// /// The state of the partitions that would activate this scenario /// + [JsonProperty("partitionStates")] List PartitionStates { get; } /// /// The mapping of UIs by key to rooms by key /// + [JsonProperty("uiMap")] Dictionary UiMap { get; set; } } diff --git a/src/PepperDash.Essentials.Core/Room/Combining/RoomCombinationScenario.cs b/src/PepperDash.Essentials.Core/Room/Combining/RoomCombinationScenario.cs index 3a64efb7..9bc0d8ec 100644 --- a/src/PepperDash.Essentials.Core/Room/Combining/RoomCombinationScenario.cs +++ b/src/PepperDash.Essentials.Core/Room/Combining/RoomCombinationScenario.cs @@ -16,20 +16,41 @@ namespace PepperDash.Essentials.Core /// /// Represents a room combination scenario /// - public class RoomCombinationScenario: IRoomCombinationScenario + public class RoomCombinationScenario: IRoomCombinationScenario, IKeyName { private RoomCombinationScenarioConfig _config; + [JsonProperty("key")] public string Key { get; set; } + [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("partitionStates")] public List PartitionStates { get; private set; } + [JsonProperty("uiMap")] public Dictionary UiMap { get; set; } private bool _isActive; + [JsonProperty("isActive")] + public bool IsActive + { + get { return _isActive; } + set + { + if(value == _isActive) + { + return; + } + + _isActive = value; + IsActiveFeedback.FireUpdate(); + } + } + + [JsonIgnore] public BoolFeedback IsActiveFeedback { get; private set; } private List activationActions; @@ -67,8 +88,7 @@ namespace PepperDash.Essentials.Core } } - _isActive = true; - IsActiveFeedback.FireUpdate(); + IsActive = true; } public void Deactivate() @@ -83,8 +103,7 @@ namespace PepperDash.Essentials.Core } } - _isActive = false; - IsActiveFeedback.FireUpdate(); + IsActive = false; } } diff --git a/src/PepperDash.Essentials.Devices.Common/Displays/MockDisplayInputs.cs b/src/PepperDash.Essentials.Devices.Common/Displays/MockDisplayInputs.cs index f6fb7bc0..5013913c 100644 --- a/src/PepperDash.Essentials.Devices.Common/Displays/MockDisplayInputs.cs +++ b/src/PepperDash.Essentials.Devices.Common/Displays/MockDisplayInputs.cs @@ -54,8 +54,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays public class MockDisplayInput : ISelectableItem { - private IHasInputs _parent; - + private MockDisplay _parent; private bool _isSelected;