using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Devices; namespace PepperDash.Essentials.Core { public class LevelControlListItem : AudioControlListItemBase { [JsonIgnore] public IBasicVolumeWithFeedback LevelControl { get { if (_levelControl == null) _levelControl = DeviceManager.GetDeviceForKey(ParentDeviceKey) 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 "---"; } } } /// /// The key of the device in the DeviceManager for control /// [JsonProperty("deviceKey")] public string DeviceKey { get { if(string.IsNullOrEmpty(ItemKey)) return ParentDeviceKey; else { return DeviceManager.AllDevices. Where(d => d.Key.Contains(ParentDeviceKey) && d.Key.Contains(ItemKey)).FirstOrDefault()?.Key ?? $"{ParentDeviceKey}--{ItemKey}"; } } } /// /// Indicates if the item is a level, mute , or both /// [JsonProperty("type")] [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public eLevelControlType Type { get; set; } } [Flags] public enum eLevelControlType { Level = 1, Mute = 2, LevelAndMute = Level | Mute, } }