From cb16f2a505f6c65337ad81913734a82a0033dca0 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 16 May 2024 17:17:59 -0600 Subject: [PATCH] feat: Adds LevelControlLists to BasicConfig and LevelControlListItem class --- .../Config/BasicConfig.cs | 5 +- .../Devices/LevelControlListItem.cs | 81 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/PepperDash.Essentials.Core/Devices/LevelControlListItem.cs diff --git a/src/PepperDash.Essentials.Core/Config/BasicConfig.cs b/src/PepperDash.Essentials.Core/Config/BasicConfig.cs index 6e876de8..ca15680c 100644 --- a/src/PepperDash.Essentials.Core/Config/BasicConfig.cs +++ b/src/PepperDash.Essentials.Core/Config/BasicConfig.cs @@ -23,7 +23,10 @@ namespace PepperDash.Essentials.Core.Config public Dictionary> SourceLists { get; set; } [JsonProperty("destinationLists")] - public Dictionary> DestinationLists { get; set; } + public Dictionary> DestinationLists { get; set; } + + [JsonProperty("levelControlLists")] + public Dictionary> LevelControlLists { get; set; } [JsonProperty("tieLines")] public List TieLines { get; set; } diff --git a/src/PepperDash.Essentials.Core/Devices/LevelControlListItem.cs b/src/PepperDash.Essentials.Core/Devices/LevelControlListItem.cs new file mode 100644 index 00000000..2bdd1dcc --- /dev/null +++ b/src/PepperDash.Essentials.Core/Devices/LevelControlListItem.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using PepperDash.Core; + +namespace PepperDash.Essentials.Core +{ + public class LevelControlListItem + { + [JsonProperty("deviceKey")] + public string DeviceKey { get; set; } + + [JsonIgnore] + public IBasicVolumeWithFeedback LevelControl + { + get + { + if (_levelControl == null) + _levelControl = DeviceManager.GetDeviceForKey(DeviceKey) as IBasicVolumeWithFeedback; + return _levelControl; + } + } + IBasicVolumeWithFeedback _levelControl; + + /// + /// Gets the name from the device if it implements IKeyName or else returns the Name property + /// + [JsonProperty("preferredName")] + public string PreferredName + { + get + { + if (!string.IsNullOrEmpty(Name)) return Name; + else + { + if (LevelControl is IKeyName namedLevelControl) + { + if (namedLevelControl == null) + return "---"; + return namedLevelControl.Name; + } + else return "---"; + } + } + } + + /// + /// A name that will override the items's name on the UI + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Indicates if the item should be included in the user accessible list + /// + [JsonProperty("includeInUserList")] + public bool IncludeInUserList { get; set; } + + /// + /// Used to specify the order of the items in the source list when displayed + /// + [JsonProperty("order")] + public int Order { get; set; } + + /// + /// Indicates if the item is a level, mute , or both + /// + [JsonProperty("type")] + public eLevelControlType Type { get; set; } + } + + public enum eLevelControlType + { + Level = 0, + Mute = 1, + LevelAndMute = 2, + } +}