/// <summary> /// The Discover Attributes Command /// /// The discover attributes command is generated when a remote device wishes to /// discover the identifiers and types of the attributes on a device which are supported /// within the cluster to which this command is directed. /// /// @param startAttributeIdentifier {@link ushort} Start attribute identifier /// @param maximumAttributeIdentifiers {@link byte} Maximum attribute identifiers /// @return the Task<CommandResult> command result Task /// </summary> public Task <CommandResult> DiscoverAttributesCommand(ushort startAttributeIdentifier, byte maximumAttributeIdentifiers) { DiscoverAttributesCommand command = new DiscoverAttributesCommand(); // Set the fields command.StartAttributeIdentifier = startAttributeIdentifier; command.MaximumAttributeIdentifiers = maximumAttributeIdentifiers; return(Send(command)); }
/** * Discovers the list of attributes supported by the cluster on the remote device. * <p> * If the discovery has already been completed, and rediscover is false, then the future will complete immediately * and the user can use existing results. Normally there should not be a need to set rediscover to true. * <p> * This method returns a future to a boolean. Upon success the caller should call {@link #getSupportedAttributes()} * to get the list of supported attributes. * * @param rediscover true to perform a discovery even if it was previously completed * @return {@link Future} returning a {@link Boolean} */ public Task <bool> DiscoverAttributes(bool rediscover) { return(Task.Run(() => { // Synchronise the request to avoid multiple simultaneous requests to this update the list on this // cluster which would cause errors consolidating the responses lock (_supportedAttributes) { // If we don't want to rediscover, and we already have the list of attributes, then return if (!rediscover && !(_supportedAttributes == null || _supportedAttributes.Count == 0)) { return true; } ushort index = 0; bool complete = false; List <AttributeInformation> attributes = new List <AttributeInformation>(); do { DiscoverAttributesCommand command = new DiscoverAttributesCommand(); command.ClusterId = _clusterId; command.DestinationAddress = _zigbeeEndpoint.GetEndpointAddress(); command.StartAttributeIdentifier = index; command.MaximumAttributeIdentifiers = 10; CommandResult result = Send(command).Result; if (result.IsError()) { return false; } DiscoverAttributesResponse response = (DiscoverAttributesResponse)result.GetResponse(); complete = response.DiscoveryComplete; if (response.AttributeInformation != null) { attributes.AddRange(response.AttributeInformation); index = (ushort)(attributes.Max().Identifier + 1); } } while (!complete); _supportedAttributes.Clear(); foreach (AttributeInformation attribute in attributes) { _supportedAttributes.Add(attribute.Identifier); } } return true; })); }