/// <summary> /// 2. Helper for above GetDevices, which takes selection function for extracting items from DeviceDictHS /// </summary> /// <param name="func"></param> /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param> /// <param name="exclude">List<dev_ids> to exclude</param> /// <returns>List of pairs (Name=Value=item) for dropbox</returns> public static MyPairList GetDevicesProps(Func <HSDevice, Int32, string> func, DeviceDictHS devices = null, DeviceIdList exclude = null) { if (devices == null) { devices = Devices(); } if (exclude == null) { exclude = new DeviceIdList(); } // TEMP - TODO: exclude? && Int32.TryParse(item, out int id) && !exclude.Contains(id) IEnumerable <string> sel = devices.Values.Select(func); List <string> sel1 = sel.Distinct().OrderBy(x => x).ToList(); MyPairList items = new MyPairList(); foreach (var item in sel1) { if (item != "") // avoid duplicated "" { items.Add(new MyPair(item, item)); } } return(items); }
/// <summary> /// Process VSPair[] and convert to list of MyPair /// Note: ranges *split* into individual states /// </summary> /// <param name="splitrange">ranges *split* into individual states</param> private MyPairList MakeVSpsListStatus(SplitRangeType splitrange) { // VSPair[] if (this.vsps == null) { this.vsps = hs.DeviceVSP_GetAllStatus(this.deviceId); } MyPairList pairs = new MyPairList(); if (this.vsps != null) { foreach (VSPair pair in this.vsps) { if (pair.PairType == VSVGPairType.SingleValue || splitrange == SplitRangeType.NotSplit) { pairs.Add(MakePair(pair, null)); } else { // Add the range itself first (only for SplitAndNot) if (splitrange == SplitRangeType.SplitAndNot) { pairs.Add(MakePair(pair, null)); } // May need floor/ceil? // Since we want ranges *split* - make new pair for each value in range for (int v = (int)pair.RangeStart; v <= pair.RangeEnd; v++) { pairs.Add(MakePair(pair, v)); // For huge range just add first pair (temporary, need better solution) if (pair.RangeEnd - pair.RangeStart > 100) { break; } } } } } return(pairs); }
/// <summary> /// Process CAPIControl[] and convert to list of MyPair /// </summary> /// <param name="splitrange">ranges *split* into individual states</param> /// <returns></returns> public MyPairList MakeVSpsListControl(SplitRangeType splitrange) { MyPairList pairs = new MyPairList(); // Doesn't make sense for Control? if (splitrange == SplitRangeType.SplitAndNot) { return(pairs); } bool b_splitrange = (splitrange == SplitRangeType.Split); // CAPIControl[] - Note: ranges *split* into individual states if (!capisDict.ContainsKey(b_splitrange)) { capisDict[b_splitrange] = hs.CAPIGetControlEx(deviceId, SingleRangeEntry: !b_splitrange); } if (b_splitrange) { valueCAPIDict = new ValueCAPIDict(); } // Get Control pairs foreach (CAPI.CAPIControl capi in capisDict[b_splitrange]) { if (capi != null) { if (capi.Label != null) { pairs.Add(MakePair(capi)); } // Keep CAPIControl in ValueCAPIDict for SmartDevice.Value if (b_splitrange) { valueCAPIDict[capi.ControlValue] = capi; } } } return(pairs); }
/// <summary> /// Get Union ot two lists, Linq Union didn't work... /// </summary> /// <param name="a">List 1</param> /// <param name="b">List 2</param> /// <returns></returns> public static MyPairList Merge(MyPairList a, MyPairList b) { MyPairList res = new MyPairList(a); foreach (MyPair x in b) { bool found = false; foreach (MyPair y in a) { if (y.Equals(x)) { found = true; break; } } if (!found) { res.Add(x); } } return(res); }
public MyPairList(MyPairList other) : base(other) { }
/// <summary> /// 2. Helper for above GetDevices - selects devices filtered by Location and/or Location2 /// </summary> /// <param name="Location"></param> /// <param name="Location2"></param> /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param> /// <param name="min_vspsCount">Filter devices if their vspsCount exceeds this number</param> /// <param name="exclude">List<dev_ids> to exclude</param> /// <returns>List of pairs (Name=name, Value=deviceID) for dropbox</returns> public static MyPairList GetDevices(string Location, string Location2, DeviceDictHS devices = null, int min_vspsCount = 0, DeviceIdList exclude = null) { IHSApplication _hs = null; //IHSApplication _hs = Hs; if (devices == null) { devices = Devices(); } if (exclude == null) { exclude = new DeviceIdList(); } MyPairList items = new MyPairList(); foreach (int deviceId in devices.Keys) { if (exclude.Contains(deviceId)) { continue; } HSDevice device = devices[deviceId]; string name = device.get_Name(_hs); string dev_loc = device.get_Location(_hs); string dev_loc2 = device.get_Location2(_hs); // Select devices matching Loc/Loc2, or if Loc/Loc2 not specified if ((String.IsNullOrEmpty(Location) || Location == dev_loc) && (String.IsNullOrEmpty(Location2) || Location2 == dev_loc2) ) { // If Loc/Loc2 not specified - prepend them to device name if (String.IsNullOrEmpty(Location)) { name = "[" + dev_loc + "] " + name; } if (String.IsNullOrEmpty(Location2)) { name = "[" + dev_loc2 + "] " + name; } int num_vsps = 0; if (min_vspsCount > 0) { VSVGPairs.VSPair[] vsps = Hs.DeviceVSP_GetAllStatus(deviceId); num_vsps = vsps.Length; } if (num_vsps >= min_vspsCount) { items.Add(new MyPair(name, deviceId)); } } } return(items); }