devicehive

2.1.0 • Public • Published

DeviceHive-javascript

DeviceHive-javascript is promise-based library for using DeviceHive.

Installation Instructions

For Node.js use case (Node v4.x on Mac, Linux, or Windows on a x86 or x64 processor), DeviceHive-javascript will install nice and easy with:

npm install devicehive

Generation bundle for browser usage

In case you want to use DeviceHive-javascript in the browser:

  1. Clone repo;
  2. Inside repo folder run npm install;
  3. Inside repo folder run npm run build;
  4. Get devicehive.js/devicehive.min.js in dist folder.

Usage

During development you can use this library with Promises, and Async/Await functions.

Connecting to DeviceHive

Using HTTP/HTTPS

Note: Using HTTP/HTTPS you need to pass 3 different service URL`s: mainServiceURL, authServiceURL and pluginServiceURL.

const DeviceHive = require('devicehive');
const httpDeviceHive = new DeviceHive({
    login: 'login',
    password: 'password',
    mainServiceURL: 'http://<host>:<port>/<path>',
    authServiceURL: 'http://<host>:<port>/<path>',
    pluginServiceURL: 'http://<host>:<port>/<path>'
});
httpDeviceHive.connect();

Using WebSocket

Note: Using WebSocket you need to pass only one service URL: mainServiceURL.

const DeviceHive = require('devicehive');
const wsDeviceHive= new DeviceHive({
    login: 'login',
    password: 'password',
    mainServiceURL: 'ws://<host>:<port>/<path>'
});
wsDeviceHive.connect();

Using Models

You can use models described in DeviceHive.models

// Getting Device model
const Device = DeviceHive.models.Device;
 
// Getting Device list query model
const DeviceListQuery = DeviceHive.models.query.DeviceListQuery;

Full Example and using API

You can use API described in DeviceHive.command, DeviceHive.configuration, DeviceHive.device, DeviceHive.deviceType, DeviceHive.info, DeviceHive.notification, DeviceHive.network, DeviceHive.plugin, DeviceHive.token, DeviceHive.user.

Here is example of how you can use DeviceHive-javascript:

const DeviceHive = require('devicehive');
 
// Getting Device model
const Device = DeviceHive.models.Device
// Getting Device list query model
const DeviceListQuery = DeviceHive.models.query.DeviceListQuery;
 
// Configurating DeviceHive
const myDeviceHive = new DeviceHive({
    login: 'login',
    password: 'password',
    mainServiceURL: 'ws://<host>:<port>/<path>'
});
 
// Configurating Device model
const device = new Device({
    id: 'myTestId',
    name: 'myTestName',
    networkId: 1,
    deviceTypeId: 1,
    blocked: false
});
 
// Configurating Device List query
const myDeviceListQuery = new DeviceListQuery({
    networkId: 1
});
 
// Push message handler
myDeviceHive.on(DeviceHive.MESSAGE_EVENT, (message) => {
    console.log(message);
});
 
// Error handler
myDeviceHive.on(DeviceHive.ERROR_EVENT, (error) => {
    console.error(error);
});
 
// Connecting and usin API
myDeviceHive.connect()
    .then(() => myDeviceHive.device.list(myDeviceListQuery))
    .then(data => console.log(data))
    .then(() => myDeviceHive.device.add(device))
    .then(data => console.log(data))
    .then(() => myDeviceHive.device.list(myDeviceListQuery))
    .then(data => console.log(data))
    .then(() => myDeviceHive.device.delete(device.id))
    .then(data => console.log(data))
    .then(() => myDeviceHive.device.list(myDeviceListQuery))
    .then(data => console.log(data))
    .catch(error => console.warn(error));

API Reference

DeviceHive

DeviceHive module

new DeviceHive(options)

DeviceHive module

Param Type Description
options object Initial settings
[options.accessToken] string Access token
[options.refreshToken] string Refresh token
[options.login] string Login
[options.password] string Password
options.mainServiceURL string Main Service URL
[options.authServiceURL] string Auth Service URL (required only for http)
[options.pluginServiceURL] string Plugin Service URL (required only for http)
[options.autoUpdateSession] boolean Flag to enable/disable autoupdating session. Default: true

deviceHive.connect({ accessToken, refreshToken, login, password, reconnectionAttempts, reconnectionInterval })

Connect and authorize

Params:

Param Type Description
options.accessToken string Access token (default DeviceHive constructor configuration) (optional)
options.refreshToken string Refresh token (default DeviceHive constructor configuration) (optional)
options.login string Login (default DeviceHive constructor configuration) (optional)
options.password string Password (default DeviceHive constructor configuration) (optional)
options.reconnectionAttempts number Reconnection attempts (default infinity (-1)) (optional)
options.reconnectionInterval number Reconnection interval in ms (default 5000) (optional)

DeviceHive.models : Object

Returns DeviceHive models

DeviceHive.command: Object

Look at DeviceCommandAPI.

DeviceHive.configuration : Object

Look at ConfigurationAPI.

DeviceHive.device: Object

Look at DeviceAPI.

DeviceHive.deviceType: Object

Look at deviceTypeAPI.

DeviceHive.info: Object

Look at InfoAPI.

DeviceHive.notification: Object

Look at DeviceNotificationAPI.

DeviceHive.network: Object

Look at NetworkAPI.

DeviceHive.plugin: Object

Look at PluginAPI.

DeviceHive.token: Object

Look at TokenAPI.

DeviceHive.user: Object

Look at UserAPI.


Nested DeviceHive API

ConfigurationAPI

Returns information about the current configuration

configurationAPI.get(name) ⇒ Promise

Creates ConfigurationAPI

Param Type
name number

configurationAPI.put(configuration) ⇒ Promise

Updates a configuration

Param Type
configuration Configuration

configurationAPI.delete(name) ⇒ Promise

Deletes an existing configuration

Param Type
name number

DeviceAPI

Returns information about the current device

deviceAPI.get(deviceId) ⇒ Promise

Creates DeviceAPI

Param Type
deviceId string

deviceAPI.list(deviceListQuery) ⇒ Promise

Return a list of devices

Param Type
deviceListQuery DeviceListQuery

deviceAPI.count(deviceCountQuery) ⇒ Promise

Returns count of devices

Param Type
deviceCountQuery DeviceCountQuery

deviceAPI.add(device) ⇒ Promise

Registers or updates a device

Param Type Description
device object data

deviceAPI.delete(deviceId) ⇒ Promise

Deletes an existing device

Param Type
deviceId string

DeviceCommandAPI

Returns information about the current command

deviceCommandAPI.get(deviceId, commandId) ⇒ Promise

Creates DeviceCommandAPI

Param Type Description
deviceId number Device ID
commandId number Command ID

deviceCommandAPI.list(commandListQuery) ⇒ Promise

Return a list of commands

Param Type
commandListQuery CommandListQuery

deviceCommandAPI.insert(deviceId, command) ⇒ Promise

Registers a command

Param Type Description
deviceId number Device ID
command Command

deviceCommandAPI.update(command) ⇒ Promise

Updates a command

Param Type
command Command

deviceCommandAPI.poll(commandPollQuery) ⇒ Promise

Param Type
commandPollQuery CommandPollQuery

deviceCommandAPI.pollMany(commandPollManyQuery) ⇒ Promise

Param Type
commandPollManyQuery CommandPollManyQuery

deviceCommandAPI.wait(deviceId, commandId) ⇒ Promise

Param
deviceId
commandId

deviceCommandAPI.subscribe(commandPollQuery) ⇒ Promise

Param Type
commandPollQuery CommandPollQuery

deviceCommandAPI.unsubscribe(subscriptionId) ⇒ Promise

Param Type
subscriptionId Number

DeviceNotificationAPI

Returns information about the current notification

deviceNotificationAPI.get(deviceId, notificationId) ⇒ Promise

Creates DeviceNotificationAPI

Param Type Description
deviceId number Device ID
notificationId number Notification ID

deviceNotificationAPI.list(notificationListQuery) ⇒ Promise

Return a list of notifications

Param Type
notificationListQuery NotificationListQuery

deviceNotificationAPI.insert(notification) ⇒ Promise

Registers a notification

Param Type
notification Notification

deviceNotificationAPI.poll(notificationPollQuery) ⇒ *

Param Type
notificationPollQuery NotificationPollQuery

deviceNotificationAPI.pollMany(notificationPollManyQuery) ⇒ *

Param Type
notificationPollManyQuery NotificationPollManyQuery

deviceNotificationAPI.subscribe(notificationPollQuery) ⇒ Promise

Param Type
notificationPollQuery NotificationPollQuery

deviceNotificationAPI.unsubscribe(subscriptionId) ⇒ Promise

Param Type
subscriptionId Number

DeviceTypeAPI

Returns information about the current deviceType

deviceTypeAPI.get(deviceTypeId) ⇒ Promise

Creates DeviceTypeAPI

Param Type
deviceTypeId number

deviceTypeAPI.list(deviceTypeListQuery) ⇒ Promise

Return a list of deviceTypes

Param Type
deviceTypeListQuery DeviceTypeListQuery

deviceTypeAPI.count(deviceTypeCountQuery) ⇒ Promise

Returns count of deviceTypes

Param Type
deviceTypeCountQuery DeviceTypeCountQuery

deviceTypeAPI.insert(deviceType) ⇒ Promise

Registers a deviceType

Param Type Description
deviceType DeviceType data

deviceTypeAPI.update(deviceType) ⇒ Promise

Updates a deviceType

Param Type Description
deviceType DeviceType data

deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise

Deletes an existing deviceType

Param Type
deviceTypeDeleteQuery deviceTypeDeleteQuery

NetworkAPI

Returns information about the current network

networkAPI.get(networkId) ⇒ Promise

Returns a network

Param Type
networkId number

networkAPI.list(networkListQuery) ⇒ Promise

Return a list of networks

Param Type
networkListQuery NetworkListQuery

networkAPI.count(networkCountQuery) ⇒ Promise

Returns count of networks

Param Type
networkCountQuery NetworkCountQuery

networkAPI.insert(network) ⇒ Promise

Registers a network

Param Type Description
network Network data

networkAPI.update(networkId, network) ⇒ Promise

Updates a network

Param Type Description
networkId number
network Network data

networkAPI.delete(networkDeleteQuery) ⇒ Promise

Deletes an existing network

Param Type
networkDeleteQuery networkDeleteQuery

PluginAPI

Returns information about the current plugin

pluginAPI.list(pluginListQuery) ⇒ Promise

Return a list of plugins

Param Type
pluginListQuery PluginListQuery

pluginAPI.count(pluginCountQuery) ⇒ Promise

Returns count of plugins

Param Type
pluginCountQuery PluginCountQuery

pluginAPI.insert(plugin, pluginRegisterQuery) ⇒ Promise

Registers a plugin

Param Type
plugin Plugin
pluginRegisterQuery PluginRegisterQuery

pluginAPI.update(plugin) ⇒ Promise

Updates a plugin

Param Type
plugin Promise

pluginAPI.delete(Plugin) ⇒ Promise

Deletes an existing plugin

Param Type
Plugin object

InfoAPI

Get server info

infoAPI.getServerInfo()

Creates InfoAPI

infoAPI.getCacheInfo()

Get cache info

infoAPI.getClusterInfo()

Get cluster info

TokenAPI

Authentificate using login and password

tokenAPI.login(login, password)

Creates TokenAPI

Param Type
login string
password string

tokenAPI.authPlugin(token)

Create user token

Param Type Description
token string Plugin token

tokenAPI.createUserToken(userToken)

Create user token

Param Type
userToken UserToken

tokenAPI.createPluginToken(pluginToken)

Create plugin token

Param Type
pluginToken PluginToken

tokenAPI.refresh(refreshToken)

Refresg token

Param Type
refreshToken string

UserAPI

ConfigurationAPI

Returns information about the current configuration

DeviceAPI

Returns information about the current device

DeviceCommandAPI

Returns information about the current command

DeviceNotificationAPI

Returns information about the current notification

DeviceTypeAPI

Returns information about the current deviceType

NetworkAPI

Returns information about the current network

PluginAPI

Returns information about the current plugin

InfoAPI

Get server info

TokenAPI

Authenticate using login and password

UserAPI

Return a list of users

ConfigurationAPI

Returns information about the current configuration

configurationAPI.get(name) ⇒ Promise

Creates ConfigurationAPI

Returns: Promise - selected configuration

Param Type
name number

configurationAPI.put(configuration) ⇒ Promise

Updates a configuration

Returns: Promise - count of configuration

Param Type
configuration Configuration

configurationAPI.delete(name) ⇒ Promise

Deletes an existing configuration

Param Type
name number

DeviceAPI

Returns information about the current device

deviceAPI.get(deviceId) ⇒ Promise

Creates DeviceAPI

Returns: Promise - selected device

Param Type
deviceId string

deviceAPI.list(deviceListQuery) ⇒ Promise

Return a list of devices

Returns: Promise - list of devices

Param Type
deviceListQuery DeviceListQuery

deviceAPI.count(deviceCountQuery) ⇒ Promise

Returns count of devices

Returns: Promise - count of devices

Param Type
deviceCountQuery DeviceCountQuery

deviceAPI.add(device) ⇒ Promise

Registers or updates a device

Returns: Promise - count of devices

Param Type Description
device object data

deviceAPI.delete(deviceId) ⇒ Promise

Deletes an existing device

Param Type
deviceId string

DeviceCommandAPI

Returns information about the current command

deviceCommandAPI.get(deviceId, commandId) ⇒ Promise

Creates DeviceCommandAPI

Returns: Promise - selected command

Param Type Description
deviceId number Device ID
commandId number Command ID

deviceCommandAPI.list(commandListQuery) ⇒ Promise

Return a list of commands

Returns: Promise - list of commands

Param Type
commandListQuery CommandListQuery

deviceCommandAPI.insert(deviceId, command) ⇒ Promise

Registers a command

Returns: Promise - count of commands

Param Type Description
deviceId number Device ID
command Command

deviceCommandAPI.update(command) ⇒ Promise

Updates a command

Returns: Promise - count of commands

Param Type
command Command

deviceCommandAPI.poll(commandPollQuery) ⇒ Promise

Param Type
commandPollQuery CommandPollQuery

deviceCommandAPI.pollMany(commandPollManyQuery) ⇒ Promise

Param Type
commandPollManyQuery CommandPollManyQuery

deviceCommandAPI.wait(deviceId, commandId) ⇒ Promise

Param
deviceId
commandId

deviceCommandAPI.subscribe(commandPollQuery) ⇒ Promise

Param Type
commandPollQuery CommandPollQuery

deviceCommandAPI.unsubscribe(subscriptionId) ⇒ Promise

Param Type
subscriptionId Number

DeviceNotificationAPI

Returns information about the current notification

deviceNotificationAPI.get(deviceId, notificationId) ⇒ Promise

Creates DeviceNotificationAPI

Returns: Promise - selected notification

Param Type Description
deviceId number Device ID
notificationId number Notification ID

deviceNotificationAPI.list(notificationListQuery) ⇒ Promise

Return a list of notifications

Returns: Promise - list of notifications

Param Type
notificationListQuery NotificationListQuery

deviceNotificationAPI.insert(deviceId, notification) ⇒ Promise

Registers a notification

Returns: Promise - count of notifications

Param Type
deviceId Number
notification Notification

deviceNotificationAPI.poll(notificationPollQuery) ⇒ *

Param Type
notificationPollQuery NotificationPollQuery

deviceNotificationAPI.pollMany(notificationPollManyQuery) ⇒ *

Param Type
notificationPollManyQuery NotificationPollManyQuery

deviceNotificationAPI.subscribe(notificationPollQuery) ⇒ Promise

Param Type
notificationPollQuery NotificationPollQuery

deviceNotificationAPI.unsubscribe(subscriptionId) ⇒ Promise

Param Type
subscriptionId Number

DeviceTypeAPI

Returns information about the current deviceType

deviceTypeAPI.get(deviceTypeId) ⇒ Promise

Creates DeviceTypeAPI

Returns: Promise - selected deviceType

Param Type
deviceTypeId number

deviceTypeAPI.list(deviceTypeListQuery) ⇒ Promise

Return a list of deviceTypes

Returns: Promise - list of deviceTypes

Param Type
deviceTypeListQuery DeviceTypeListQuery

deviceTypeAPI.count(deviceTypeCountQuery) ⇒ Promise

Returns count of deviceTypes

Returns: Promise - count of deviceTypes

Param Type
deviceTypeCountQuery DeviceTypeCountQuery

deviceTypeAPI.insert(deviceType) ⇒ Promise

Registers a deviceType

Returns: Promise - count of deviceTypes

Param Type Description
deviceType DeviceType data

deviceTypeAPI.update(deviceType) ⇒ Promise

Updates a deviceType

Returns: Promise - count of deviceTypes

Param Type Description
deviceType DeviceType data

deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise

Deletes an existing deviceType

Param Type
deviceTypeDeleteQuery deviceTypeDeleteQuery

NetworkAPI

Returns information about the current network

networkAPI.get(networkId) ⇒ Promise

Returns a network

Returns: Promise - selected network

Param Type
networkId number

networkAPI.list(networkListQuery) ⇒ Promise

Return a list of networks

Returns: Promise - list of networks

Param Type
networkListQuery NetworkListQuery

networkAPI.count(networkCountQuery) ⇒ Promise

Returns count of networks

Returns: Promise - count of networks

Param Type
networkCountQuery NetworkCountQuery

networkAPI.insert(network) ⇒ Promise

Registers a network

Returns: Promise - Network

Param Type Description
network Network data

networkAPI.update(network) ⇒ Promise

Updates a network

Returns: Promise - Network

Param Type Description
network Network data

networkAPI.delete(networkDeleteQuery) ⇒ Promise

Deletes an existing network

Returns: Promise - Network

Param Type
networkDeleteQuery networkDeleteQuery

PluginAPI

Returns information about the current plugin

pluginAPI.list(pluginListQuery) ⇒ Promise

Return a list of plugins

Returns: Promise - list of plugins

Param Type
pluginListQuery PluginListQuery

pluginAPI.count(pluginCountQuery) ⇒ Promise

Returns count of plugins

Returns: Promise - count of plugins

Param Type
pluginCountQuery PluginCountQuery

pluginAPI.register(plugin, pluginRegisterQuery) ⇒ Promise

Registers a plugin

Returns: Promise - Plugin

Param Type
plugin Plugin
pluginRegisterQuery PluginRegisterQuery

pluginAPI.update(pluginUpdateQuery) ⇒ Promise

Updates a plugin

Returns: Promise - Plugin

Param Type
pluginUpdateQuery PluginUpdateQuery

pluginAPI.delete(topicName) ⇒ Promise

Deletes an existing plugin

Returns: Promise - Plugin

Param Type
topicName string

InfoAPI

Get server info

infoAPI.getServerInfo() ⇒ Promise

Get server info

infoAPI.getCacheInfo() ⇒ Promise

Get cache info

infoAPI.getClusterInfo() ⇒ Promise

Get cluster info

TokenAPI

Authenticate using login and password

tokenAPI.login(login, password)

Creates TokenAPI

Param Type
login string
password string

tokenAPI.authPlugin(token)

Create user token

Param Type Description
token string Plugin token

tokenAPI.createUserToken(userToken)

Create user token

Param Type
userToken UserToken

tokenAPI.createPluginToken(pluginToken)

Create plugin token

Param Type
pluginToken PluginToken

tokenAPI.refresh(refreshToken)

Refresh token

Param Type
refreshToken string

UserAPI

Return a list of users

userAPI.list(userListQuery) ⇒ Promise

Creates UserAPI

Returns: Promise - list of users

Param Type
userListQuery UserListQuery

userAPI.count(userCountQuery) ⇒ Promise

Returns count of users

Returns: Promise - count of users

Param Type
userCountQuery UserCountQuery

userAPI.get(userId) ⇒ Promise

Returns information about the current user

Returns: Promise - selected user

Param Type
userId number

userAPI.insert(user) ⇒ Promise

Registers a user

Returns: Promise - count of users

Param Type Description
user User data

userAPI.update(user) ⇒ Promise

Updates a user (only for administrators)

Returns: Promise - count of users

Param Type Description
user User data

userAPI.delete(userId) ⇒ Promise

Deletes an existing user

Param Type
userId number

userAPI.getCurrent() ⇒ Promise

Returns information about the current user

Returns: Promise - selected user

userAPI.updateCurrent(user) ⇒ Promise

Updates a user (only for administrators)

Returns: Promise - count of users

Param Type Description
user User data

userAPI.getDeviceTypes(userId) ⇒ Promise

Param
userId

userAPI.unassignAllDeviceTypes(userId) ⇒ Promise

Param
userId

userAPI.assignAllDeviceTypes(userId) ⇒ Promise

Param
userId

userAPI.unassignDeviceType(userId, deviceTypeId) ⇒ Promise

Param
userId
deviceTypeId

userAPI.getDeviceType(userId, deviceTypeId) ⇒ Promise

Param
userId
deviceTypeId

userAPI.assignDeviceType(userId, deviceTypeId) ⇒ Promise

Param
userId
deviceTypeId

userAPI.getNetwork(userId, networkId) ⇒ Promise

Gets information about user/network association

Param Type Description
userId number User ID
networkId number Network ID

userAPI.assignNetwork(userId, networkId) ⇒ Promise

Associates network with the user

Param Type Description
userId number User ID
networkId number Network ID

userAPI.unassignNetwork(userId, networkId) ⇒ Promise

Removes association between network and user

Param Type Description
userId number User ID
networkId number Network ID

Models

Configuration

Configuration model

Device

Device model

DeviceCommand

DeviceCommand model

DeviceNotification

DeviceNotification model

DeviceType

DeviceType model

Network

Network model

Plugin

Plugin model

PluginToken

PluginToken model

User

User model

UserToken

UserToken model

Configuration

Configuration model

new Configuration(options)

Creates new Configuration model

Param Type Description
options Object model options object
options.name string Configuration parameter name.
options.value string Configuration parameter value.
options.entityVersion number Specifies the version field or property of an entity class.

configuration.toObject() ⇒ Object

Returns instance as a plain JS object

Device

Device model

new Device(options)

Creates new Device model

Param Type Description
options object model options object
options.id string Device unique identifier
options.name string Device display name
options.data object Device data, a JSON object with an arbitrary structure
options.networkId number Associated network id
options.deviceTypeId number Associated deviceType id
options.blocked boolean Indicates whether device is blocked

device.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceCommand

DeviceCommand model

new DeviceCommand(options)

Creates new DeviceCommand model

Param Type Description
options object model options object
options.id number Command identifier
options.command string Command name
options.timestamp string Command UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601)
options.lastUpdated string Last command update UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601)
options.userId number Associated user identifier
options.deviceId string Device unique identifier
options.networkId number Network unique identifier
options.deviceTypeId number DeviceType unique identifier
options.parameters object Command parameters, a JSON object with an arbitrary structure
options.lifetime number Command lifetime, a number of seconds until this command expires
options.status string Command status, as reported by device or related infrastructure
options.result object Command execution result, an optional value that could be provided by device

deviceCommand.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceNotification

DeviceNotification model

new DeviceNotification(options)

Creates new DeviceNotification model

Param Type Description
options object model options object
options.id number Notification identifier
options.deviceId string Device unique identifier
options.networkId number Network unique identifier
options.deviceTypeId number Device type unique identifier
options.notification string Notification name
options.timestamp string Notification UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601)
options.parameters object Notification parameters, a JSON object with an arbitrary structure

deviceNotification.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceType

DeviceType model

new DeviceType(options)

Creates new DeviceType model

Param Type Description
options object model options object
options.id number Device type identifier
options.name string Device type name
options.description string Device type description

deviceType.toObject() ⇒ Object

Returns instance as a plain JS object

Network

Network model

new Network(options)

Creates new Network model

Param Type Description
options object model options object
options.id number Network identifier
options.name string Network name
options.description string Network description

network.toObject() ⇒ Object

Returns instance as a plain JS object

Plugin

Plugin model

new Plugin(options)

Creates new Plugin model

Param Type Description
options object model options object
options.id id Plgin unique idnetifier
options.name string Plugin name
options.description string Plugin description
options.topicName string Plugin topic name
options.filter string Plugin filter
options.status string Plugin status
options.subscriptionId string Plugin subscribtion id
options.userId number Plugin user id
options.parameters object Json object with parameters

plugin.toObject() ⇒ Object

Returns instance as a plain JS object

PluginToken

PluginToken model

new PluginToken(options)

Creates new PluginToken model

Param Type Description
options object model options object
options.actions Array Plugin Token actions
options.expiration string Plugin expiration
options.type number Plugin type
options.topicName string Plugin topic name

pluginToken.toObject() ⇒ Object

Returns instance as a plain JS object

User

User model

new User(options)

Creates new User model

Param Type Description
options object model options object
options.id numebr User identifier
options.login string User login using during authentication
options.role number User role. Available values: 0: Administrator role, 1: Client role.
options.status number User status. Available values: 0: The user is active, 1: The user has been locked out due to invalid login attempts, 2: The user has been disabled
options.lastLogin string User last login timestamp (UTC)
options.data object User data, a JSON object with an arbitrary structure
options.password string User Password
options.introReviewed boolean Indicates if user reviewed an intro
options.allDeviceTypesAvailable boolean Is all device types awailable

user.toObject() ⇒ Object

Returns instance as a plain JS object

UserToken

UserToken model

new UserToken(options)

Creates new UserToken model

Param Type Description
options object model options object
options.userId number User id
options.actions Array User Actions
options.networkIds Array Network id's
options.deviceTypeIds Array Devicetype id's
options.expiration string Token expiration datetme

userToken.toObject() ⇒ Object

Returns instance as a plain JS object

Query models

CommandListQuery

CommandListQuery class

CommandPollManyQuery

CommandPollManyQuery class

CommandPollQuery

CommandPollQuery class

CommandWaitQuery

CommandWaitQuery class

DeviceCountQuery

DeviceCountQuery class

DeviceListQuery

DeviceListQuery class

DeviceTypeCountQuery

DeviceTypeCountQuery class

DeviceTypeListQuery

DeviceTypeListQuery class

NetworkCountQuery

NetworkCountQuery class

NetworkListQuery

NetworkListQuery class

NotificationListQuery

NotificationListQuery class

NotificationPollManyQuery

NotificationPollManyQuery class

NotificationPollQuery

NotificationPollQuery class

PluginCountQuery

PluginCountQuery class

PluginListQuery

PluginListQuery class

PluginRegisterQuery

PluginRegisterQuery class

PluginUpdateQuery

PluginUpdateQuery class

UserCountQuery

UserCountQuery class

UserListQuery

UserListQuery class

CommandListQuery

CommandListQuery class

new CommandListQuery(options)

Creates new CommandListQuery model

Param Type Description
options object model options object
options.deviceId string Device ID
options.start string Start timestamp
options.end string End timestamp
options.command string Command name
options.status string Command status
options.sortField string Sort field
options.sortOrder string Sort order
options.take number Limit param
options.skip number Skip param

commandListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

CommandPollManyQuery

CommandPollManyQuery class

new CommandPollManyQuery(options)

Creates new CommandPollManyQuery model

Param Type Description
options object model options object
options.deviceIds string List of device IDs
options.networkIds string List of network IDs
options.deviceTypeIds string List of devicetype IDs
options.names string Command names
options.timestamp string Timestamp to start from
options.waitTimeout number Wait timeout in seconds
options.limit number Limit number of commands

commandPollManyQuery.toObject() ⇒ Object

Returns instance as a plain JS object

CommandPollQuery

CommandPollQuery class

new CommandPollQuery(options)

Creates new CommandPollQuery model

Param Type Description
options object model options object
options.deviceId string Device ID
options.names string Command names
options.timestamp number Timestamp to start from
options.returnUpdatedCommands boolean Checks if updated commands should be returned
options.waitTimeout number Wait timeout in seconds
options.limit number Limit number of commands

commandPollQuery.toObject() ⇒ Object

Returns instance as a plain JS object

CommandWaitQuery

CommandWaitQuery class

new CommandWaitQuery(options)

Creates new CommandWaitQuery model

Param Type Description
options Object model options object
options.waitTimeout Number wait timeout (sec)

commandWaitQuery.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceCountQuery

DeviceCountQuery class

new DeviceCountQuery(options)

Creates new DeviceCountQuery model

Param Type Description
options object model options object
options.name string Filter by device name
options.namePattern string Filter by device name pattern. In pattern wildcards '%' and '_' can be used
options.networkId number Filter by associated network identifier
options.networkName string Filter by associated network name

deviceCountQuery.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceListQuery

DeviceListQuery class

new DeviceListQuery(options)

Creates new DeviceListQuery model

Param Type Description
options object model options object
options.name string Filter by device name
options.namePattern string Filter by device name pattern. In pattern wildcards '%' and '_' can be used
options.networkId number Filter by associated network identifier
options.networkName string Filter by associated network name
options.sortField string Result list sort field
options.sortOrder string Result list sort order. The sortField should be specified
options.take number Number of records to take from the result list
options.skip number Number of records to skip from the result list

deviceListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceTypeCountQuery

DeviceTypeCountQuery class

new DeviceTypeCountQuery(options)

Creates new DeviceTypeCountQuery model

Param Type Description
options object model options object
options.name string Filter by device type name
options.namePattern string Filter by device type name pattern. In pattern wildcards '%' and '_' can be used

deviceTypeCountQuery.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceTypeListQuery

DeviceTypeListQuery class

new DeviceTypeListQuery(options)

Creates new DeviceTypeListQuery model

Param Type Description
options object model options object
options.name string Filter by device type name
options.namePattern string Filter by device type name pattern. In pattern wildcards '%' and '_' can be used
options.sortField string Result list sort field
options.sortOrder string Result list sort order. The sortField should be specified
options.take number Number of records to take from the result list
options.skip number Number of records to skip from the result list

deviceTypeListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

DeviceTypeDeleteQuery

DeviceTypeDeleteQuery class

new DeviceTypeDeleteQuery(options)

Creates new DeviceTypeDeleteQuery model

Param Type Description
options object model options object
options.deviceTypeId number Id of device type
options.force boolean Flag, if true then it will delete device type with existing devices

deviceTypeDeleteQuery.toObject() ⇒ Object

Returns instance as a plain JS object

NetworkCountQuery

NetworkCountQuery class

new NetworkCountQuery(options)

Creates new NetworkCountQuery model

Param Type Description
options object model options object
options.name string Filter by device type name
options.namePattern string Filter by device type name pattern. In pattern wildcards '%' and '_' can be used

networkCountQuery.toObject() ⇒ Object

Returns instance as a plain JS object

NetworkListQuery

NetworkListQuery class

new NetworkListQuery(options)

Creates new NetworkListQuery model

Param Type Description
options object model options object
options.name string Filter by device type name
options.namePattern string Filter by device type name pattern. In pattern wildcards '%' and '_' can be used
options.sortField string Result list sort field
options.sortOrder string Result list sort order. The sortField should be specified
options.take number Number of records to take from the result list
options.skip number Number of records to skip from the result list

networkListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

NetworkDeleteQuery

NetworkDeleteQuery class

new NetworkDeleteQuery(options)

Creates new NetworkDeleteQuery model

Param Type Description
options object model options object
options.networkId number Id of network
options.force boolean Flag, if true then it will delete network with existing devices

networkDeleteQuery.toObject() ⇒ Object

Returns instance as a plain JS object

NotificationListQuery

NotificationListQuery class

new NotificationListQuery(options)

Creates new NotificationListQuery model

Param Type Description
options object model options object
options.deviceId string Device ID
options.start string Start timestamp
options.end string End timestamp
options.notification string Notification name
options.status string Command status
options.sortField string Sort field
options.sortOrder string Sort order
options.take number Limit param
options.skip number Skip param

notificationListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

NotificationPollManyQuery

NotificationPollManyQuery class

new NotificationPollManyQuery(options)

Creates new NotificationPollManyQuery model

Param Type Description
options object model options object
options.deviceIds string List of device IDs
options.networkIds string List of network IDs
options.deviceTypeIds string List of devicetype IDs
options.names string Notification names
options.timestamp string Timestamp to start from
options.waitTimeout number Wait timeout in seconds

notificationPollManyQuery.toObject() ⇒ Object

NotificationPollQuery

NotificationPollQuery class

new NotificationPollQuery(options)

Creates new NotificationPollQuery model

Param Type Description
options object model options object
options.deviceId string Device ID
options.names string Notification names
options.timestamp number Timestamp to start from
options.waitTimeout number Wait timeout in seconds

notificationPollQuery.toObject() ⇒ Object

Returns instance as a plain JS object

PluginCountQuery

PluginCountQuery class

new PluginCountQuery(options)

Creates new PluginCountQuery model

Param Type Description
options object model options object
options.name string Filter by plugin name
options.namePattern string Filter by plugin name pattern. In pattern wildcards '%' and '_' can be used
options.topicName string Filter by plugin topic name
options.status number Filter by plugin status
options.userId number Filter by associated user identifier. Only admin can see other users' plugins

pluginCountQuery.toObject() ⇒ Object

Returns instance as a plain JS object

PluginListQuery

PluginListQuery class

new PluginListQuery(options)

Creates new PluginListQuery model

Param Type Description
options object model options object
options.name string Filter by plugin name
options.namePattern string Filter by plugin name pattern. In pattern wildcards '%' and '_' can be used
options.topicName string Filter by plugin topic nathis.
options.status string Filter by plugin status.
options.userId number Filter by associated user identifier. Only admin can see other users' plugins
options.sortField string Result list sort field
options.sortOrder string Result list sort order. The sortField should be specified
options.take number Number of records to take from the result list
options.skip number Number of records to skip from the result list

pluginListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

PluginRegisterQuery

PluginRegisterQuery class

new PluginRegisterQuery(options)

Creates new PluginRegisterQuery model

Param Type Description
options object model options object
[options.deviceId] string Device device_id
[options.networkIds] string Network ids
[options.deviceTypeIds] string Device type ids
[options.names] string Command/Notification names
[options.returnCommands] boolean Checks if commands should be returned
[options.returnUpdatedCommands] boolean Checks if updated commands should be returned
[options.returnNotifications] boolean Checks if commands should be returned

pluginRegisterQuery.toObject() ⇒ Object

Returns instance as a plain JS object

PluginUpdateQuery

PluginUpdateQuery class

new PluginUpdateQuery(options)

Creates Plugin Update Query model

Param Type Description
options object Options for instance
options.topicName string Name of topic that was created for the plugin
[options.deviceId] string Device device_id
[options.networkIds] string Network ids
[options.deviceTypeIds] string Device type ids
[options.names] string Command/Notification names
[options.returnCommands] boolean Checks if commands should be returned
[options.returnUpdatedCommands] boolean Checks if updated commands should be returned
[options.returnNotifications] boolean Checks if commands should be returned
[options.status] string Plugin status - active or disabled (ACTIVE
[options.name] string Plugin name
[options.description] string Plugin description
[options.parameters] string Plugin parameters

pluginUpdateQuery.toObject() ⇒ Object

UserCountQuery

UserCountQuery class

new UserCountQuery(options)

Creates User Count Query

Param Type Description
options object Options for instance
options.login string Filter by user login
options.loginPattern string Filter by user login pattern
options.role number Filter by user login patter
options.status number Filter by user status. 0 is Active, 1 is Locked Out, 2 is Disabled

userCountQuery.toObject() ⇒ Object

Returns instance as a plain JS object

UserListQuery

UserListQuery class

new UserListQuery(options)

Creates User List Query

Param Type Description
options object Options for instance
options.login string Filter by user login
options.loginPattern string Filter by user login pattern
options.role number Filter by user login patter
options.status number Filter by user status. 0 is Active, 1 is Locked Out, 2 is Disabled
options.sortField string Result list sort field
options.sortOrder string Result list sort order. The sortField should be specified
options.take number Number of records to take from the result list
options.skip number Number of records to skip from the result list

userListQuery.toObject() ⇒ Object

Returns instance as a plain JS object

Readme

Keywords

none

Package Sidebar

Install

npm i devicehive

Weekly Downloads

54

Version

2.1.0

License

Apache-2.0

Unpacked Size

1.15 MB

Total Files

137

Last publish

Collaborators

  • devicehive