/// <summary> /// The Discover Commands Generated /// /// The Discover Commands Generated command is generated when a remote device wishes to discover the /// commands that a cluster may generate on the device to which this command is directed. /// /// @param startCommandIdentifier {@link byte} Start command identifier /// @param maximumCommandIdentifiers {@link byte} Maximum command identifiers /// @return the Task<CommandResult> command result Task /// </summary> public Task <CommandResult> DiscoverCommandsGenerated(byte startCommandIdentifier, byte maximumCommandIdentifiers) { DiscoverCommandsGenerated command = new DiscoverCommandsGenerated(); // Set the fields command.StartCommandIdentifier = startCommandIdentifier; command.MaximumCommandIdentifiers = maximumCommandIdentifiers; return(Send(command)); }
/** * Discovers the list of commands generated by the cluster on the remote device If the discovery is successful, * users should call {@link ZclCluster#getSupportedCommandsGenerated()} to get the list of supported commands. * <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. * * @param rediscover true to perform a discovery even if it was previously completed * @return Command future {@link Boolean} with the success of the discovery */ public Task <bool> DiscoverCommandsGenerated(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 (_supportedCommandsGenerated) { // If we don't want to rediscover, and we already have the list of attributes, then return if (!rediscover && !(_supportedCommandsGenerated == null | _supportedCommandsGenerated.Count == 0)) { return true; } byte index = 0; bool complete = false; List <byte> commands = new List <byte>(); do { DiscoverCommandsGenerated command = new DiscoverCommandsGenerated(); command.ClusterId = _clusterId; command.DestinationAddress = _zigbeeEndpoint.GetEndpointAddress(); command.StartCommandIdentifier = index; command.MaximumCommandIdentifiers = 20; CommandResult result = Send(command).Result; if (result.IsError()) { return false; } DiscoverCommandsGeneratedResponse response = (DiscoverCommandsGeneratedResponse)result.GetResponse(); complete = response.DiscoveryComplete; if (response.CommandIdentifiers != null) { commands.AddRange(response.CommandIdentifiers); index = (byte)(commands.Max() + 1); } } while (!complete); _supportedCommandsGenerated.Clear(); _supportedCommandsGenerated.AddRange(commands); } return true; })); }