Endpoint collection
The endpoint collection object represents a collection of endpoints contained within a device. Typically, the list of endpoints is accessed through the endpoints property of the device object.
Properties
### count (integer) The count property indicates the number of endpoints included in the collection.
Examples
This example shows the number of endpoints of a device in the log console.
env.log('Endpoint count: ', myDevice.endpoints.count);Methods
### byAddress(address) The byAddress() method allows finding an endpoint within the collection by specifying its address.
Parameters
- address (string): this parameter indicates the address of the endpoint being searched. The search is case insensitive.
Result
If the method finds an endpoint with the specified address, an endpoint object representing that endpoint will be returned. If no endpoint with the specified address can be found, the value null will be returned.
Example 1
This example shows the description of the endpoint with address "1" in a device, using the log console.
env.log(myDevice.endpoints.byAddress("1").description);### byIndex(index) The byIndex() method allows finding an endpoint within the collection by specifying its position in the collection.
Parameters
- index (integer): this parameter indicates the position of the endpoint within the collection. The first endpoint in the collection has index 0 (zero).
Result
If the method finds an endpoint with the given index, an endpoint object representing that endpoint will be returned. If no endpoint with the specified index can be found, the value null will be returned.
Example 1
This example shows the description of the fourth endpoint of a device, using the log console.
env.log(myDevice.endpoints.byIndex(3).description);### byType(type [, subType]) The byType() method allows finding the first endpoint of a given type (and optionally of a subtype) within the collection.
Parameters
- type (integer): this parameter indicates the endpoint type being searched. The possible values for the type parameter can be found in the explanation of the endpointType property of the endpoint object.
- subType (optional, integer): if this parameter is included, the method will search for the first endpoint that is of the type specified in the type parameter, and that is also of the subtype specified in the subType parameter. The possible values for the subType parameter can be found in the explanation of the endpointSubType property of the endpoint object.
Result
If the method finds an endpoint with the specified type and subtype, an endpoint object representing that endpoint will be returned. If no endpoint with the given type and subtype can be found, the value null will be returned.
Example 1
This example shows the description of the first temperature sensor contained in a device, using the log console.
env.log(myDevice.endpoints.byType(endpointType.temperatureSensor).description);Example 2
This example shows the description of the first CO2 concentration sensor contained in a device, using the log console.
env.log
(
myDevice.endpoints.byType
(
endpointType.ppmConcentrationSensor,
ppmConcentrationSensorSubType.carbonDioxide
)
.description
);### allByType(type [, subType]) The AllByType() method works similarly to the byType() method, but returns an array with all endpoints that match the specified criteria.
Parameters
- type (integer): this parameter indicates the endpoint type being searched. The possible values for the type parameter can be found in the explanation of the endpointType property of the endpoint object.
- subType (optional, integer): if this parameter is included, the method will search only for endpoints that are of the type specified in the type parameter, and that are also of the subtype specified in the subType parameter. The possible values for the subType parameter can be found in the explanation of the endpointSubType property of the endpoint object.
Result
The method returns an array with all endpoints that match the specified criteria. If no endpoint is found, the method will return an empty array.
Example 1
This example shows the descriptions of all temperature sensors contained in a device, using the log console.
myDevice.endpoints.allByType(endpointType.temperatureSensor).forEach((item) => env.log(item.description));### byTag(tag) The byTag() method allows finding the first endpoint that contains the specified tag within the collection.
Parameters
- tag (string): this parameter indicates the tag being searched. The search is case insensitive.
Result
If the method finds an endpoint with the specified tag, an endpoint object representing that endpoint will be returned. If no endpoint with the specified tag can be found, the value null will be returned.
Example 1
This example shows the description of the first endpoint with the tag "SomeTag".
env.log(myDevice.endpoints.byTag("SomeTag").description);### allByTag(tag) The AllByTag() method works similarly to the byTag() method, but returns an array with all endpoints that match the specified criteria.
Parameters
- tag (string): this parameter indicates the tag being searched. The search is case insensitive.
Result
The method returns an array with all endpoints that match the specified criteria. If no endpoint is found, the method will return an empty array.
Example 1
This example shows the descriptions of all endpoints that contain the tag "SomeTag".
myDevice.endpoints.allByTag("SomeTag").forEach((item) => env.log(item.description));### toArray() The toArray() method allows converting the endpoint collection to an array containing all endpoints in the collection.
Example 1
This example shows the description of all endpoints of a device, using the log console.
myDevice.endpoints.toArray().forEach(element => env.log(element.description));