Mr-Markus / ZigbeeNet

A .NET Standard library for working with ZigBee
Eclipse Public License 1.0
131 stars 47 forks source link

ZclCluster._supportedAttributes should be HashSet #125

Closed spudwebb closed 3 years ago

spudwebb commented 3 years ago

The extension method ConcurrentBagExtensions.Clear() does not work, so you end up with a lot of duplicates if the discovery of supported attributes is done several times. Instead of a ConcurrentBag we should use a simple HashSet for _supportedAttributes to make sure there is no duplicates, and we should lock the end part of DiscoverAttributes where the actual change to the hashset is done:

            lock (_supportedAttributes)
            {
                _supportedAttributes.Clear();

                foreach (AttributeInformation attribute in attributes)
                {
                    _supportedAttributes.Add(attribute.Identifier);
                }
                _supportedAttributesKnown = true;
            }

same thing for _supportedCommandsReceived and _supportedCommandsGenerated

Mr-Markus commented 3 years ago

Fixed by #126