Last updated
Last updated
The pairing views consists of .html
files in the /drivers/<driver_id>/pair
-folder. Where the name of the file is the view ID, as id
described in the App Manifest.
The pairing views have a few Homey-specific JavaScript functions available. They are documented below.
The session
property passed in onPair
can control the front-end programmatically.
The following methods are available at the front-end to communicate with the back-end. The Homey
object is globally available.
Homey.emit( String event, Mixed data ): Promise<any>
Emit an event to your app. The function called will be the one registered by session.setHandler( String event, Function callback )
in driver.js
.
Homey.on( String event, Function callback )
Listen to a message from your app. You can trigger this function from your app by calling session.emit()
.
Homey.setTitle( String title )
Set the window's title.
Homey.setSubtitle( String subtitle )
Set the window's subtitle.
Homey.showView( String viewId )
Navigate to another view. The parameter viewId
should be an ID as specified in your App Manifest.
Homey.prevView()
Show the previous view.
Homey.nextView()
Show the next view.
Homey.getCurrentView()
Returns the current view ID.
Homey.createDevice( Object device ): Promise<Object>
Create a device with the properties in device
.
The device
object must at least contain the properties data
and name
and may contain icon
, class
, capabilities
, capabilitiesOptions
, store
and settings
.
Homey.getZone(): Promise<string>
Get the Zone ID of the active Zone. The promise resolves to the zone id.
Homey.getOptions( [String viewId] ): Promise<Object>
Get the options of a view, or the current view when viewId
is omitted. The promise resolves to the viewOptions
of the specified view.
View options may be added to a view by specifying an options
object in the App Manifest.
Homey.setNavigationClose()
Remove all navigation buttons and show a single Close button.
Homey.done()
Close the pairing window.
Homey.alert( String message[, String icon] ): Promise<void>
Show an alert dialog. The second parameter icon
can be null
, error
, warning
or info
.
Homey.confirm( String message[, String icon] ): Promise<boolean>
Show a confirm dialog. The second parameter icon
can be null
, error
, warning
or info
.
The promise will resolve to true
when the user pressed OK
.
Homey.popup( String url )
Show a popup with a remote website.
Homey.__( String key [, Object tokens] )
Translate a string programmatically. The first argument key
is the name in your /locales/__language__.json
. Use dots to get a sub-property, e.g. settings.title
. The optional second argument tokens
is an object with replacers.
Within your custom views, you can also use translations. For example:
Homey.showLoadingOverlay()
Shows the loading overlay.
Homey.hideLoadingOverlay()
Hides the loading overlay.
Homey.getViewStoreValue( String viewId, String key ): Promise<any>
Get's a view's store value. Promise will resolve to the requested value.
Homey.setViewStoreValue( String viewId, String key, Mixes value): Promise<void>
Set a view's store value.
Read more about translations in the .
Most drivers will suffice using the provided pairing templates. Some advanced drivers however can benefit from creating their own views.