ApiApp

This class represents another App on Homey. When registered, realtime events are fired on the instance.

Example

let otherApp = this.homey.api.getApiApp('com.athom.otherApp');

otherApp
  .on('realtime', (result) => console.log('otherApp.onRealtime', result))
  .on('install', (result) => console.log('otherApp.onInstall', result))
  .on('uninstall', (result) => console.log('otherApp.onUninstall', result));

otherApp.get('/')
  .then((result) => console.log('otherApp.get', result))
  .catch((error) => this.error('otherApp.get', error));

otherApp.getInstalled()
  .then((result) => console.log('otherApp.getInstalled', result))
  .catch((error) => this.error('otherApp.getInstalled', error));

otherApp.getVersion()
  .then((result) => console.log('otherApp.getVersion', result))
  .catch((error) => this.error('otherApp.getVersion', error));

Extends

Methods

delete

delete(uri): Promise.<any>

Perform a DELETE request.

Parameters

Name Type Description
uri
string

The path to request, relative to the endpoint.

Returns

Promise.<any>

get

get(uri): Promise.<any>

Perform a GET request.

Parameters

Name Type Description
uri
string

The path to request, relative to the endpoint.

Returns

Promise.<any>

getInstalled

getInstalled(): Promise.<boolean>

This is a short-hand method to ManagerApps#getInstalled.

Returns

Promise.<boolean>

getVersion

getVersion(): Promise.<string>

This is a short-hand method to ManagerApps#getVersion.

Returns

Promise.<string>

post

post(uri, body): Promise.<any>

Perform a POST request.

Parameters

Name Type Description
uri
string

The path to request, relative to the endpoint.

body
any

The body of the request.

Returns

Promise.<any>

put

put(uri, body): Promise.<any>

Perform a PUT request.

Parameters

Name Type Description
uri
string

The path to request, relative to the endpoint.

body
any

The body of the request.

Returns

Promise.<any>

unregister

unregister()

Unregister the API. This is a shorthand method for ManagerApi#unregisterApi.

Events

install

.on('install')

This event is fired when the app is installed, enabled and running (accessible).

realtime

.on('realtime')

This event is fired when a realtime event is received on this URI.

Parameters

Name Type Description
event
string

Name of the realtime event

data
any <optional>

Data of the realtime event

uninstall

.on('uninstall')

This event is fired when the app is uninstalled, disabled or crashed (inaccessible).