node package manager

devicehive

devicehive-node

Synopsis

DeviceHive Node Library

In case yu want to use it in the browser:

  1. Clone repo;
  2. Install webpack;
  3. Inside repo folder run webpack;
  4. Get bundle.js in dist folder.

Installation

Package is published in npm - https://www.npmjs.com/package/devicehive

NPM >= 5.0.0

npm i devicehive

NPM < 5.0.0

npm i -S devicehive

Usage

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

Example with Promises

function authPromise(login, password){
  return new DeviceHive({
    serverURL : `http://<host>:<port>/<path>`,
    login,
    password
  });
}
 
function getInfoPromise(login, password){
  return authPromise(login, password)
    .then(deviceHive => deviceHive.getInfo());
}
 
getInfoPromise(`login`, `password`)
.then(...);

Example with Generators

For using Generators you could add additional library co

const co = require(`co`);
...
function* authGenerator(login, password){
  return yield new DeviceHive({
    serverURL : `http://<url>:<port>/<path>`,
    login,
    password
  });
}
 
function* getInfoGenerator(login, password){
  const deviceHive = yield * authGenerator(login, password);
  return yield deviceHive.getInfo()
}
 
co(getInfoGenerator(`login`, `password`))
.then(...);
 

Example with Async/Await

async function authAsyncAwait(login, password){
  return await new DeviceHive({
    serverURL : `http://<host>:<port>/<path>`,
    login,
    password
  });
}
 
async function getInfoAsyncAwait(login, password){
  const deviceHive = await authAsyncAwait(login, password);
  return await deviceHive.getInfo();
}
 
getInfoAsyncAwait(`login`, `password`)
.then(...);

API Reference

class DeviceHive

Public class accessable by default.

new DeviceHive({ serverURL, login, password}) ⇒ Promise

DeviceHive object constructor. Here you need to specify server url, user login and password. You could use either HTTP or WebSocket protocols.

Param Type Description
serverURL String DeviceHive cloud API url
login String User's login
password String User's password

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   login : `login`,
   password : `password`
})

new DeviceHive({ serverURL, accessToken, refreshToken}) ⇒ Promise

DeviceHive object constructor. Here you need to specify server url, user access and refresh tokens.

Param Type Description
serverURL String DeviceHive cloud API url
accessToken String User's access token
refreshToken String User's refresh token

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})

new DeviceHive({ serverURL, refreshToken}) ⇒ Promise

DeviceHive object constructor. Here you need to specify server url, user refresh token. User access token will be requested by default.

Param Type Description
serverURL String DeviceHive cloud API url
refreshToken String User's refresh token

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})

deviceHive.getInfo() ⇒ HttpPromise

Returns version of API, server timestamp and WebSocket base uri.

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
 .then(deviceHive => deviceHive.getInfo())
 .then(info => ...);

deviceHive.getClusterInfo() ⇒ HttpPromise

Returns information about cluster (Kafka, Zookeeper etc.)

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getClusterInfo())
.then(clusterInfo => ...)

deviceHive.createToken(userId, actions, networkIds, deviceIds, expiration) ⇒ HttpPromise

Authenticates by system params and returns a session-level JWT token.

Param Type Description
userId Number User id
actions [Strings] allowed actions
networkIds [Strings] accessable networks
deviceIds [Strings] accessable devices
expiration String expiration date

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.createToken(`userId`, [`actions`], [`networkIds`], [`deviceIds`], `expiration`))
.then(({ accessToken, refreshToken }) => ...)

deviceHive.refreshToken() ⇒ HttpPromise

Refresh JWT access token.

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.refreshToken())
.then(({ accessToken }) => ...)

deviceHive.getConfigurationProperty(name) ⇒ HttpPromise

Returns requested property value

Param Type Description
name String Property name

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getConfigurationProperty(`testName`))
.then(property => ...)

deviceHive.setConfigurationProperty(name, value) ⇒ HttpPromise

Creates new or updates existing property

Param Type Description
name String Property name
value String Property value

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.setConfigurationProperty(`testName`, `testValue`))
.then(() => ...)

deviceHive.removeConfigurationProperty(name) ⇒ HttpPromise

Deletes property

Param Type Description
name String Property name

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.removeConfigurationProperty(`testName`))
.then(() => ...)

deviceHive.listNetworks(filter) ⇒ HttpPromise

Gets list of device networks the client has access to.

Param Type Description
filter NetworkFilter network filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.listNetworks({/*NetworkFilter*/}))
.then(networks => ...)

deviceHive.getNetwork(networkId) ⇒ HttpPromise

Gets information about device network.

Param Type Description
networkId String network id

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getNetwork(`testId`))
.then(network => ...)

deviceHive.removeNetwork(networkId) ⇒ HttpPromise

Deletes an existing device network.

Param Type Description
networkId String network id

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.removeNetwork(`testId`))
.then(() => ...)

deviceHive.createNetwork(name, description) ⇒ HttpPromise

Creates new device network.

Param Type Description
name String network name
description Strings network description

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.createNetwork(`testName`, `testDescription`))
.then(createdNetwork => ...)

deviceHive.listDevices(filter) ⇒ HttpPromise

Gets list of devices.

Param Type Description
filter DeviceFilter search filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.listDevices())
.then(devices => ...)

deviceHive.removeDevice(id) ⇒ HttpPromise

Deletes an existing device.

Param Type Description
id String device unique identifier

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.removeDevice(`testId`))
.then(() => ...)

deviceHive.getDevice(id) ⇒ HttpPromise

Gets information about device.

Param Type Description
id String device unique identifier

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getDevice(`testId`))
.then(device => ...)

deviceHive.putDevice(id, deviceParams) ⇒ HttpPromise

Registers or updates a device. For initial device registration, only 'name' property is required.

Param Type Description
id String device unique identifier
deviceParams DeviceParams device params

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.putDevice(`testId`, {/*DeviceParams*/}))
.then(() => ...)

deviceHive.getCurrentUser() ⇒ HttpPromise

Get information about the current user.

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getCurrentUser())
.then(user => ...)

deviceHive.getUsers(filter) ⇒ HttpPromise

Gets list of users.

Param Type Description
filter UsersFilter users filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.getUsers({/*UsersFilter*/}))
.then(users => ...)

deviceHive.createUser(userParams) ⇒ HttpPromise

Creates new user.

Param Type Description
userParams UserParams user params

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.createUser({/*UserParams*/}))
.then(createdUser => ...)

deviceHive.removeUser(userId) ⇒ HttpPromise

Delete user.

Param Type Description
userId String user id

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.removeUser(`testId`))
.then(() => ...)

deviceHive.subscribeCommands(deviceIds, subscriber, commandFilter) ⇒ Promise

Allows subscribe for Commands to particular Devices with filter

Param Type Description
deviceIds [String] device ids
subscriber Function subscriber function
commandFilter DeviceCommandPollFilter command filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.subscribeCommands([`testId1`, `testId2`], /*function (){}*/, /*DeviceCommandPollFilter*/))

deviceHive.unsubscribeCommands(deviceIds, commandFilter) ⇒ Promise

Allows unsubscribe from Commands to particular Devices with filter

Param Type Description
deviceIds [String] device ids
commandFilter DeviceCommandPollFilter command filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.unsubscribeCommands([`testId1`, `testId2`], /*DeviceCommandPollFilter*/))

deviceHive.subscribeNotifications(deviceIds, subscriber, notificationFilter) ⇒ Promise

Allows subscribe for Notifications to particular Devices with filter

Param Type Description
deviceIds [String] device ids
subscriber Function subscriber function
notificationFilter DevicesNotificationPollFilter command filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.subscribeNotifications([`testId1`, `testId2`], /*function (){}*/, /*DeviceNotificationPollFilter*/))

deviceHive.unsubscribeNotifications(deviceIds, notificationFilter) ⇒ Promise

Allows unsubscribe from Notifications to particular Devices with filter

Param Type Description
deviceIds [String] device ids
notificationFilter DevicesNotificationPollFilter command filter

Example:

new DeviceHive({
   serverURL : `<protocol>://<host>:<port>/<path>`,
   accessToken : `accessToken`,
   refreshToken : `refreshToken`
})
.then(deviceHive => deviceHive.unsubscribeNotifications([`testId1`, `testId2`], /*DeviceNotificationPollFilter*/))

DeviceHive~NetworkFilter : Struct

Properties

Name Type Description
name String Filter by network name.
namePattern Strings Filter by network name pattern.
sortField Strings Result list sort field.
sortOrder Strings Result list sort order.
take Number Number of records to take from the result list.
skip Number Number of records to skip from the result list.

DeviceHive~DeviceFilter : Struct

Properties

Name Type Description
name String filter by network name
namePattern String filter by network name pattern
networkId Number filter by associated network identifier
networkName String filter by associated network name
sortField String result list sort field
sortOrder String result list sort order
take Number number of records to take from the result list
skip Number number of records to skip from the result list

DeviceHive~DeviceParams : Struct

Properties

Name Type Description
name String device name
data String device data
networkId Number device network id
blocked Boolean device blocked state

DeviceHive~UsersFilter : Struct

Properties

Name Type Description
login String Filter by user login.
loginPattern String Filter by user login pattern.
role Number Filter by user role. 0 is Administrator, 1 is Client.
status Number Filter by user status. 0 is Active, 1 is Locked Out, 2 is Disabled.
sortField String Result list sort field.
sortOrder String Result list sort order. Available values are ASC and DESC.
take Number Number of records to take from the result list.
skip Number Number of records to skip from the result list.

DeviceHive~UserParams : Struct

Properties

Name Type Description
login String User login using during authentication.
role Number User role. 0 is Administrator, 1 is Client.
status Number User status. 0 is Active, 1 is Locked Out, 2 is Disabled.
password String User password.
oldPassword String User old password. Required for non-admin users
data Object User data, a JSON object with an arbitrary structure.

DeviceHive~DeviceCommandPollFilter : Struct

Properties

Name Type Description
names String Command names
timestamp String Timestamp to start from
waitTimeout Number Wait timeout in seconds
limit Number Limit number of commands

DeviceHive~DevicesNotificationPollFilter : Struct

Properties

Name Type Description
waitTimeout Number Wait timeout in seconds
names String Notification names
timestamp String Timestamp to start from

class Device

Private class, only DeviceHive instance have access to it.

new Device({ id, name = id, data = null, networkId = null, isBlocked = false })

ONLY FOR DEVELOPMENT.

Device object constructor. Here you need to specify Device specific data.

Param Type Description
id String Device's id
name String Device's name. Equals to id by default
data String | Object Device's data. Equals to null by default
networkId Number Device's Network id. Equals to null by default
isBlocked Boolean Device's blocked status. Equals to false by default

Example:

new Device({
   id : `testId`,
   name : `testName`,
   data : {/*some data*/},
   networkId : 12345,
   isBlocked : false
})

Device.getId() ⇒ String

Returns Device's id.

Example:

deviceInstance.getId()
.then(/*testId*/ => ...)

Device.getName() ⇒ String

Returns Device's name.

Example:

deviceInstance.getName()
.then(/*testName*/ => ...)

Device.getData() ⇒ Object

Returns Device's data.

Example:

deviceInstance.getData()
.then(/*{some data}*/ => ...)

Device.getNetworkId() ⇒ Number

Returns Device's Network id.

Example:

deviceInstance.getNetworkId()
.then(/*12345*/ => ...)

Device.getBlocked() ⇒ String

Returns Device's blocked state.

Example:

deviceInstance.getBlocked()
.then(/*false*/ => ...)

Device.setId(newId)

Sets Device's id.

Param Type Description
newId String Device's new id

Example:

deviceInstance.setId(`newId`);
deviceInstance...

Device.setName(newName)

Sets Device's name.

Param Type Description
newName String Device's new name

Example:

deviceInstance.setName(`newName`);
deviceInstance...

Device.setData(newData)

Sets Device's data.

Param Type Description
newData Object Device's new data

Example:

deviceInstance.setData({/*newData*/});
deviceInstance...

Device.setNetworkId(newNetworkId)

Sets Device's Network id.

Param Type Description
newNetworkId Number Device's new Network id

Example:

deviceInstance.setNetworkId(67890);
deviceInstance...

Device.setBlocked(newBlocked)

Sets Device's blocked status.

Param Type Description
newBlocked Boolean Device's new blocked status

Example:

deviceInstance.seBlocked(true);
deviceInstance...

Device.save()

Saves Device's state

Example:

deviceInstance.save()
.then(() => ...)

Device.getCommands(filter)

Gets list of Commands that has been received in specified time range.

Param Type Description
filter DeviceCommandsFilter Device's Command filter

Example:

deviceInstance.getCommands({/*DeviceCommandsFilter*/})
.then(commands => ...)

Device.getNotifications(filter)

Returns Notifications by provided parameters

Param Type Description
filter DeviceNotificationsFilter Device's Notification filter

Example:

deviceInstance.getNotifications({/*DeviceNotificationsFilter*/})
.then(notifications => ...)

Device.sendCommand(command, parameters, updateSubscriber)

Creates new Device's Command, stores and returns Command with generated id.

Also allows to pass callback for subscription on Command's updates.

Param Type Description
command String Command's name
parameters CommandParams Device's Command parameters
updateSubscriber Function Command's on update subscriber

Example:

deviceInstance.sendCommand(`testName`, {/*CommandParams*/}, /*function(){}*/)

Device.sendNotification(notification, parameters)

Creates Notification.

Param Type Description
notification String Notification's name
parameters NotificationParams Device's Notification parameters

Example:

deviceInstance.sendNotification(`testName`, {/*NotificationParams*/})

Device.subscribeCommands(subscriber, commandFilter)

Subscribes to all Commands for this Device by particular filter.

Param Type Description
subscriber Function Command's subscriber
commandFilter CommandPollParams Device's Command filter

Example:

deviceInstance.subscribeCommands(/*function(){}*/, {/*CommandPollParams*/})
.then(() => ...)

Device.unsubscribeCommands(commandFilter)

Unsubscribe from this Device's Commands by particular filter

Param Type Description
commandFilter CommandPollParams Device's Command filter

Example:

deviceInstance.unsubscribeCommands({/*CommandPollParams*/})
.then(() => ...)

Device.subscribeCommands(subscriber, notificationFilter)

Subscribes to all Notifications for this Device by particular filter.

Param Type Description
subscriber Function Command's subscriber
notificationFilter NotificationPollParams Device's Notification filter

Example:

deviceInstance.subscribeNotifications(/*function(){}*/, {/*NotificationPollParams*/})
.then(() => ...)

Device.unsubscribeNotifications(notificationFilter)

Unsubscribe from this Device's Notifications by particular filter

Param Type Description
notificationFilter NotificationPollParams Device's Notification filter

Example:

deviceInstance.unsubscribeNotifications({/*NotificationPollParams*/})
.then(() => ...)

Device~DeviceCommandsFilter : Struct

Properties

Name Type Description
start String Start timestamp
end String End timestamp
command String Command name
status String Command status
sortField String Sort field
sortOrder String Sort order
take Number Limit param
skip Number Skip param

Device~DeviceNotificationsFilter : Struct

Properties

Name Type Description
start String Start timestamp
end String End timestamp
notification String Notification name
sortField String Sort field
sortOrder String Sort order
take Number Limit param
skip Number Skip param

Device~CommandParams : Struct

Properties

Name Type Description
command String command name
timestamp String command timestamp
parameters String command parameters
lifetime Number command lifetime
status String command status
result String command result

Device~NotificationParams : Struct

Properties

Name Type Description
timestamp String notification timestamp
parameters String notification parameters

Device~CommandPollParams : Struct

Properties

Name Type Description
names String Command names
timestamp String Timestamp to start from
waitTimeout Number Wait timeout in seconds
limit Number Limit number of commands

Device~NotificationPollParams : Struct

Properties

Name Type Description
waitTimeout Number Wait timeout
timestamp String Timestamp to start from
names String Notification names

class DeviceCommand

Private class, only DeviceHive instance have access to it.

new DeviceCommand({ id, command, timestamp, userId, deviceId, parameters = null, lifetime = 0, status = null, result = null })

ONLY FOR DEVELOPMENT.

Device Command object constructor. Here you need to specify Command specific data.

Param Type Description
id String Command's id
command String Command's name
timestamp String Command's timestamp
userId String Command's User id
deviceId String Command's Device id
parameters String | Object Command's parameters. Equals null by default
lifetime Number Command's lifetime. Equals 0 by default
status String Command's status. Equals null by default
result String Command's result. Equals null by default

Example:

new DeviceCommand({
   id : `testId`,
   command : `testName`,
   timestamp : `123456789`,
   userId : `qwerty`,
   deviceId : `deadbeef`,
   parameters : {/*test parameters*/},
   lifetime : 12345,
   status : `testStatus`,
   result : `testResult`
})

DeviceCommand.getId() ⇒ String

Returns Command's id.

Example:

deviceCommandInstance.getId()
.then(/*testId*/ => ...)

DeviceCommand.getCommand() ⇒ String

Returns Command's name.

Example:

deviceCommandInstance.getCommand()
.then(/*testName*/ => ...)

DeviceCommand.getTimestamp() ⇒ String

Returns Command's timestamp.

Example:

deviceCommandInstance.getTimestamp()
.then(/*123456789*/ => ...)

DeviceCommand.getUserId() ⇒ String

Returns Command's User id.

Example:

deviceCommandInstance.getUserId()
.then(/*qwerty*/ => ...)

DeviceCommand.getDeviceId() ⇒ String

Returns Command's Device id.

Example:

deviceCommandInstance.getDeviceId()
.then(/*deadbeef*/ => ...)

DeviceCommand.getParameters() ⇒ Object

Returns Command's parameters.

Example:

deviceCommandInstance.getParameters()
.then(/*{test parameters}*/ => ...)

DeviceCommand.getLifetime() ⇒ Number

Returns Command's lifetime.

Example:

deviceCommandInstance.getLifetime()
.then(/*12345*/ => ...)

DeviceCommand.getStatus() ⇒ String

Returns Command's status.

Example:

deviceCommandInstance.getStatus()
.then(/*testStatus*/ => ...)

DeviceCommand.getResult() ⇒ String

Returns Command's result.

Example:

deviceCommandInstance.getResult()
.then(/*testResult*/ => ...)

DeviceCommand.setId(newId)

Sets Command's id.

Param Type Description
newId String Command's new id

Example:

deviceCommandInstance.setId(`newId`);
deviceCommandInstance...

DeviceCommand.setCommand(newCommand)

Sets Command's name.

Param Type Description
newCommand String Command's new name

Example:

deviceCommandInstance.setCommand(`newCommand`);
deviceCommandInstance...

DeviceCommand.setTimestamp(newTimestamp)

Sets Command's timestamp.

Param Type Description
newTimestamp String Command's new timestamp

Example:

deviceCommandInstance.setTimestamp(`newTimestamp`);
deviceCommandInstance...

DeviceCommand.setUserId(newUserId)

Sets Command's User id.

Param Type Description
newUserId String Command's new User id

Example:

deviceCommandInstance.setUserId(`newUserId`);
deviceCommandInstance...

DeviceCommand.setDeviceId(newDeviceId)

Sets Command's Device id.

Param Type Description
newDeviceId String Command's new Device id

Example:

deviceCommandInstance.setDeviceId(`newDeviceId`);
deviceCommandInstance...

DeviceCommand.setParameters(newParameters)

Sets Command's parameters.

Param Type Description
newParameters Object Command's new parameters

Example:

deviceCommandInstance.setParameters({/*new parameters*/});
deviceCommandInstance...

DeviceCommand.setLifetime(newLifetime)

Sets Command's lifetime.

Param Type Description
newLifetime Number Command's new lifetime

Example:

deviceCommandInstance.setLifetime(67890);
deviceCommandInstance...

DeviceCommand.setStatus(newStatus)

Sets Command's status.

Param Type Description
newStatus String Command's new status

Example:

deviceCommandInstance.setStatus(`newStatus`);
deviceCommandInstance...

DeviceCommand.setResult(newResult)

Sets Command's result.

Param Type Description
newResult String Command's new result

Example:

deviceCommandInstance.setResult(`newResult`);
deviceCommandInstance...

DeviceCommand.fetchCommandStatus()

Returns Command's status.

If status was updated updates current command on the fly.

Example:

deviceCommandInstance.fetchCommandStatus()
.then(newStatus => ...)

DeviceCommand.fetchCommandResult()

Returns Command's result.

If status was updated updates current command on the fly.

Example:

deviceCommandInstance.fetchCommandResult()
.then(newResult => ...)

DeviceCommand.updateCommand()

Requests current Command update

Example:

deviceCommandInstance.updateCommand()
.then(updatedCommand => ...)

DeviceCommand.save()

Save current Command's state.

Example:

deviceCommandInstance.save()
.then(() => ...)

DeviceCommand.subscribeUpdates(subscriber)

Allow subscription for result updates from server

Param Type Description
subscriber Function Command's updates subscriber

Example:

deviceCommandInstance.subscribeUpdates(/*function(){}*/)

class DeviceNotification

Private class, only DeviceHive instance have access to it.

new DeviceNotification({ id, notification, deviceId, timestamp, parameters = null })

ONLY FOR DEVELOPMENT.

Device Notification object constructor. Here you need to specify Notification specific data.

Param Type Description
id String Notification's id
notification String Notification's name
timestamp String Notification's timestamp
deviceId String Notification's Device id
parameters String | Object Command's parameters. Equals null by default

Example:

new DeviceNotification({
   id : `testId`,
   notification : `testName`,
   timestamp : `123456789`,
   deviceId : `deadbeef`,
   parameters : {/*test parameters*/}
})

DeviceNotification.getId() ⇒ String

Returns Notification's id.

Example:

deviceNotificationInstance.getId()
.then(/*testId*/ => ...)

DeviceNotification.getNotification() ⇒ String

Returns Notification's name.

Example:

deviceNotificationInstance.getNotification()
.then(/*testName*/ => ...)

DevieNotification.getTimestamp() ⇒ String

Returns Notification's timestamp.

Example:

deviceNotificationInstance.getTimestamp()
.then(/*123456789*/ => ...)

DeviceNotification.getDeviceId() ⇒ String

Returns Notification's Device id.

Example:

deviceNotificationInstance.getDeviceId()
.then(/*deadbeef*/ => ...)

DeviceNotification.getParameters() ⇒ Object

Returns Notification's parameters.

Example:

deviceNotificationInstance.getParameters()
.then(/*{test parameters}*/ => ...)

class Network

Private class, only DeviceHive instance have access to it.

new Network({ id, name, description })

ONLY FOR DEVELOPMENT.

Network object constructor. Here you need to specify Network specific data.

Param Type Description
id Number Network's id
name String Network's name
description String Network's description

Example:

new Network({
   id : 12345,
   name : `testName`,
   description : `testDescription`
})

Network.getId() ⇒ Number

Returns Network's id.

Example:

networkInstance.getId()
.then(/*12345*/ => ...)

Network.getName() ⇒ String

Returns Network's name.

Example:

networkInstance.getName()
.then(/*testName*/ => ...)

Network.getDescription() ⇒ String

Returns Network's description.

Example:

networkInstance.getDescription()
.then(/*testDescription*/ => ...)

Network.setId(newId)

Sets Network's id.

Param Type Description
newId Number Network's new id

Example:

networkInstance.setId(67890);
networkInstance...

Network.setId(newName)

Sets Network's name.

Param Type Description
newName String Network's new name

Example:

networkInstance.setName(`newName`);
networkInstance...

Network.setDescription(newDescription)

Sets Network's description.

Param Type Description
newDescription String Network's new description

Example:

networkInstance.setDescription(`newDescription`);
networkInstance...

Network.save()

Save current Network state.

Example:

networkInstance.save()
.then(() => ...)

Network.listDevices()

Get current Network Device list

Example:

networkInstance.listDevices()
.then(devices => ...)

class User

Private class, only DeviceHive instance have access to it.

new User({ id, login, role = 1, status = 0, lastLogin = null, data = null, password = null, oldPassword = null, introReviewed = false })

ONLY FOR DEVELOPMENT.

User object constructor. Here you need to specify User specific data.

Param Type Description
id String User's id
login String User's login
role Number User's role. Equals 1 by default.
status Number User's status. Equals 0 by default.
lastLogin String User's last login. Equals null by default
data Object User's data. Equals null by default
password String User's password. Equals null by default
oldPassword String User's old password. Equals null by default
introReviewed Boolean User's intro reviewed state. Equals false by default

Example:

new User({
   id : `testId`,
   login : `testLogin`,
   role : 12345,
   status : 6789,
   lastLogin : `testLastLogin`,
   data : {/*test data*/},
   password : `testPassword`,
   oldPassword : `testOldPassword`,
   introReviewed : false
})

User.getId() ⇒ String

Returns User's id.

Example:

userInstance.getId()
.then(/*testId*/ => ...)

User.getLogin() ⇒ String

Returns User's login.

Example:

userInstance.getLogin()
.then(/*testLogin*/ => ...)

User.getRole() ⇒ Number

Returns User's role.

Example:

userInstance.getRole()
.then(/*12345*/ => ...)

User.getStatus() ⇒ Number

Returns User's status.

Example:

userInstance.getStatus()
.then(/*6789*/ => ...)

User.getLastLogin() ⇒ String

Returns User's last login.

Example:

userInstance.getLastLogin()
.then(/*testLastLogin*/ => ...)

User.getData() ⇒ Object

Returns User's data.

Example:

userInstance.getData()
.then(({/*test data*/}) => ...)

User.getPassword() ⇒ String

Returns User's password.

Example:

userInstance.getPassword()
.then(/*testPassword*/ => ...)

User.getOldPassword() ⇒ String

Returns User's old password.

Example:

userInstance.getOldPassword()
.then(/*testPassword*/ => ...)

User.getIntroReviewed() ⇒ Boolean

Returns User's intro reviewed.

Example:

userInstance.getIntroReviewed()
.then(/*false*/ => ...)

User.setId(newId)

Sets User's id.

Param Type Description
newId String User's new id

Example:

userInstance.setId(`newId`)
userInstance...

User.setLogin(newLogin)

Sets User's login.

Param Type Description
newLogin String User's new login

Example:

userInstance.setLogin(`newLogin`)
userInstance...

User.setRole(newRole)

Sets User's role.

Param Type Description
newRole Number User's new role

Example:

userInstance.setRole(6789)

User.setStatus(newStatus)

Sets User's status.

Param Type Description
newStatus Number User's new status

Example:

userInstance.setStatus(12345)
userInstance...

User.setLastLogin(newLastLogin)

Sets User's last login.

Param Type Description
newLastLogin String User's new last login

Example:

userInstance.setLastLogin(`newLastLogin`)
userInstance...

User.setData(newData)

Sets User's data.

Param Type Description
newData Object User's new data

Example:

userInstance.setData({/*new data*/})
userInstance...

User.setPassword(newPassword)

Sets User's password.

Param Type Description
newPassword String User's new password

Example:

userInstance.setPassword(`newPassword`)
userInstance...

User.setOldPassword(newOldPassword)

Sets User's old password.

Param Type Description
newOldPassword String User's new old password

Example:

userInstance.setOldPassword(`newOldPassword`)
userInstance...

User.setIntroReviewed(newIntroReviewed)

Sets User's intro reviewed.

Param Type Description
newIntroReviewed Boolean User's new intro reviewed

Example:

userInstance.setIntroReviewed(true)
userInstance...

User.save()

Saves current User's state

Example:

userInstance.save()
.then(() => ...)

User.getNetworks()

Returns User's networks

Example:

userInstance.getNetworks()
.then(networks => ...)

User.assignNetwork(networkId)

Assign Network to User

Param Type Description
networkId Number Network's id to assign

Example:

userInstance.assignNetwork(12345)
.then(() => ...)

User.unassignNetwork(networkId)

Unassing Network from User

Param Type Description
networkId Number Network's id to unassign

Example:

userInstance.unassignNetwork(12345)
.then(() => ...)

Development

It's quite easy to add more functionality to Rest library. Check utils.js file for info about sending request to API with proper params.

License

[DeviceHive] is developed by [DataArt] Apps and distributed under Open Source Apache 2.0 license.

Creators

© Copyright 2017 [DataArt] Apps © All Rights Reserved