Skip to content

Commit

Permalink
Add event subscription example and link to Thing / Variable code gists.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualyon committed May 13, 2024
1 parent a039df1 commit 2004e63
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions content/developer-tools/custom-tiles/stio-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ Unlike the standard string, numeric, or boolean settings for a tile which expose
myNum.setValue(10)
```
 
* **`onValue(callback)`**: the `callback` is called with the updated value anytime the variable value updates
* **`onValue(callback)`**: the `callback` is called with the updated value anytime the variable value updates. Returns an object with an `off()` method if you want to stop listening for updates.
```javascript
myVar.onValue(function(value){
console.log('The new value is', value)
})
```


[Example Variable Custom Tile - Code Gist](https://gist.github.com/joshualyon/7a659611d3a63b5e2b74b717df29495e)


### Things
Expand All @@ -87,10 +93,14 @@ Unlike the standard string, numeric, or boolean tile settings which expose the r
* **`attributes`**: an object containing each of the attributes where the key is the attribute name and the value is an `Attribute` object:
* **`value`**: the current value of the attribute
* **`timestamp`**: the current timestamp of the attribute value
* **`onValue(callback)`**: the `callback` is called with the updated value anytime the attribute value updates
* Returns an object with an **`off()`** method if you want to stop listening for updates
* **`onValue(callback)`**: the `callback` is called with the updated value anytime the attribute value updates. Returns an object with an **`off()`** method if you want to stop listening for updates.
```javascript
myThing.attributes['switch'].onValue(function(value){
console.log('The new switch value is', value)
})
```
* **`name`**: the device name
* **`capabilities`**: an array of camelCase capabilities that the device reports that it has implemented (eg. `switch`, `switchLevel`, `colorControl`)
* **`capabilities`**: a string array of camelCase capabilities that the device reports that it has implemented (eg. `switch`, `switchLevel`, `colorControl`)

**Methods**
* **`sendCommand(command, [argsArray])`**: send the specified command to the device with an optional array of arguments
Expand All @@ -106,7 +116,7 @@ Unlike the standard string, numeric, or boolean tile settings which expose the r
myThing.subscribe(['switch', 'switchLevel'])
```


[Example Thing Custom Tile - Code Gist](https://gist.github.com/joshualyon/c8cfab61675aac3c94dc4708ee4eb050)



Expand Down

0 comments on commit 2004e63

Please sign in to comment.