/// <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);
        }
Esempio n. 2
0
        public override void Update(IHSApplication HS, [AllowNull] string deviceValue)
        {
            if (Property.StringValues.IsEmpty)
            {
                UpdateDeviceData(HS, deviceValue);
            }
            else
            {
                var pairs = HS.DeviceVSP_GetAllStatus(RefId);

                double?doubleValue = null;
                foreach (var value in pairs)
                {
                    if (value.ControlStatus == ePairStatusControl.Control)
                    {
                        continue;
                    }

                    if (string.Compare(value.GetPairString(0, string.Empty, null),
                                       deviceValue, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (value.PairType == VSVGPairs.VSVGPairType.SingleValue)
                        {
                            doubleValue = value.Value;
                        }
                        else
                        {
                            doubleValue = value.RangeStart;
                        }
                        break;
                    }
                }

                UpdateDeviceData(HS, deviceValue, doubleValue);
            }
        }