Device | Firebolt

Device Module


Version 0.1.0-alpha.4

Overview

A module for managing device settings.

OpenRPC

Firebolt APIs are maintained in the rdkcentral/firebolt-manage-sdk.git GitHub repository.

You can see this API in the device.json OpenRPC JSON-Schema document.

Table of Contents

 

Usage

To use the Device module, you can import it into your project from the Firebolt SDK:

import { Device } from '@firebolt-js/manage-sdk'

Methods

developerMode

Whether or not developer mode is enabled.

To get the value, call the method with no parameters:

function developerMode(): Promise<boolean>

Promise resolution:

Type Description
boolean  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.developerMode()
    .then(developerMode => {
        console.log(developerMode)
    })

Value of developerMode:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.developerMode",
  "params": {}
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}

To set the value, pass in the new value as the only parameter:

function developerMode(value: boolean): Promise<void>

Parameters:

Param Type Required Summary
value boolean true  

Promise resolution:

Type Summary
void Promise resolves with no value when the operation is complete.

Examples

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.developerMode(true)
    .then(response => {
        // property value has been set
    })
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.setDeveloperMode",
  "params": {
    "value": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": null
}

To subscribe to notifications when the value changes, pass a function as the only parameter:

function developerMode(subscriber: (developerMode: boolean) => void): Promise<boolean>

Parameters:

Param Type Required Summary
subscriber Function Yes A callback that gets invoked when the value for developerMode changes

Promise resolution:

Type Summary
listenerId The id of the listener that can be used with Device.clear(listenerId) to unsubscribe

Callback parameters:

Param Type Required Summary
developerMode boolean Yes  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.developerMode(developerMode => {
  // property value was changed
  console.log(developerMode)
}).then(listenerId => {
  // you can clear this listener w/ Device.clear(listenerId)
})

value of developerMode:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.onDeveloperModeChanged",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "listening": "true"
  }
}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}

listen

Listen for events from this module.

To listen to a specific event pass the event name as the first parameter:

Device.listen(event: string, (data: any) => void): Promise<bigint>

Parameters:

Param Type Required Summary
event string Yes The event to listen for, see Events.
callback function Yes A function that will be invoked when the event occurs.

Promise resolution:

Type Description
bigint Listener ID to clear the callback method and stop receiving the event, e.g. Device.clear(id)

Callback parameters:

Param Type Required Summary
data any Yes The event data, which depends on which event is firing, see Events.

To listen to all events from this module pass only a callback, without specifying an event name:

Device.listen((event: string, data: any) => void): Promise<bigint>

Parameters:

Param Type Required Summary
callback function Yes A function that will be invoked when the event occurs. The event data depends on which event is firing, see Events.

Callback parameters:

Param Type Required Summary
event string Yes The event that has occured listen for, see Events.
data any Yes The event data, which depends on which event is firing, see Events.

Promise resolution:

Type Description
bigint Listener ID to clear the callback method and stop receiving the event, e.g. Device.clear(id)

See Listening for events for more information and examples.


name

The user-assigned name of this device.

To get the value, call the method with no parameters:

function name(): Promise<string>

Promise resolution:

Type Description
string  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.name()
    .then(name => {
        console.log(name)
    })

Value of name:

"Living Room"
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.name",
  "params": {}
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "Living Room"
}

To set the value, pass in the new value as the only parameter:

function name(value: string): Promise<void>

Parameters:

Param Type Required Summary
value string true  

Promise resolution:

Type Summary
void Promise resolves with no value when the operation is complete.

Examples

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.name("Living Room")
    .then(response => {
        // property value has been set
    })
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.setName",
  "params": {
    "value": "Living Room"
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": null
}

To subscribe to notifications when the value changes, pass a function as the only parameter:

function name(subscriber: (name: string) => void): Promise<boolean>

Parameters:

Param Type Required Summary
subscriber Function Yes A callback that gets invoked when the value for name changes

Promise resolution:

Type Summary
listenerId The id of the listener that can be used with Device.clear(listenerId) to unsubscribe

Callback parameters:

Param Type Required Summary
name string Yes  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.name(name => {
  // property value was changed
  console.log(name)
}).then(listenerId => {
  // you can clear this listener w/ Device.clear(listenerId)
})

value of name:

"Living Room"
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.onNameChanged",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "listening": "true"
  }
}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "Living Room"
}

once

Listen for only one occurance of an event from this module. The callback will be cleared after one event.

To listen to a specific event pass the event name as the first parameter:

Device.once(event: string, (data: any) => void): Promise<bigint>

Parameters:

Param Type Required Summary
event string Yes The event to listen for, see Events.
callback function Yes A function that will be invoked when the event occurs.

Promise resolution:

Type Description
bigint Listener ID to clear the callback method and stop receiving the event, e.g. Device.clear(id)

Callback parameters:

Param Type Required Summary
data any Yes The event data, which depends on which event is firing, see Events.

To listen to all events from this module pass only a callback, without specifying an event name:

Device.once((event: string, data: any) => void): Promise<bigint>

Parameters:

Param Type Required Summary
callback function Yes A function that will be invoked when the event occurs. The event data depends on which event is firing, see Events.

Callback parameters:

Param Type Required Summary
event string Yes The event that has occured listen for, see Events.
data any Yes The event data, which depends on which event is firing, see Events.

Promise resolution:

Type Description
bigint Listener ID to clear the callback method and stop receiving the event, e.g. Device.clear(id)

See Listening for events for more information and examples.


postalCode

The user-asigned postal code of this device.

To get the value, call the method with no parameters:

function postalCode(): Promise<string>

Promise resolution:

Type Description
string  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.postalCode()
    .then(code => {
        console.log(code)
    })

Value of code:

"19103"
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.postalCode",
  "params": {}
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "19103"
}

To set the value, pass in the new value as the only parameter:

function postalCode(value: string): Promise<void>

Parameters:

Param Type Required Summary
value string true  

Promise resolution:

Type Summary
void Promise resolves with no value when the operation is complete.

Examples

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.postalCode("19103")
    .then(response => {
        // property value has been set
    })
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.setPostalCode",
  "params": {
    "value": "19103"
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": null
}

To subscribe to notifications when the value changes, pass a function as the only parameter:

function postalCode(subscriber: (code: string) => void): Promise<boolean>

Parameters:

Param Type Required Summary
subscriber Function Yes A callback that gets invoked when the value for postalCode changes

Promise resolution:

Type Summary
listenerId The id of the listener that can be used with Device.clear(listenerId) to unsubscribe

Callback parameters:

Param Type Required Summary
code string Yes  

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.postalCode(code => {
  // property value was changed
  console.log(code)
}).then(listenerId => {
  // you can clear this listener w/ Device.clear(listenerId)
})

value of code:

"19103"
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.onPostalCodeChanged",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "listening": "true"
  }
}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "19103"
}

provide

Register to provide a capability from this module.

See Provider Interfaces, for more info.

function provide(provider: object | class): Promise<void>

Parameters:

Param Type Required Summary
provider `object class` true

Promise resolution:

void

provision

Used by a distributor to push provision info to firebolt.

function provision(accountId: string, deviceId: string): Promise<void>

Parameters:

Param Type Required Summary
accountId string true The id of the account that is device is attached to in the back office.
deviceId string true The id of the device in the back office.

Promise resolution:

void

Examples

Default Example

JavaScript:

import { Device } from '@firebolt-js/manage-sdk'

Device.provision("12345678910", "987654321111")
    .then(result => {
        console.log(result)
    })

Value of result:

null
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "device.provision",
  "params": {
    "accountId": "12345678910",
    "deviceId": "987654321111"
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": null
}

Additional methods

The following methods are documented as part of a related set of method APIs.

For more information, follow the links under the “Documentation” column.

JavaScript RPC Parameters Documentation
NA setName (name: string) name
NA setPostalCode (code: string) postalCode
NA setDeveloperMode (developerMode: boolean) developerMode
NA nameResponse (response: ProviderResponse) DeviceSettingsProvider
NA postalCodeResponse (response: ProviderResponse) DeviceSettingsProvider

Events

Additional events

The following events are documented as part of a related set of method APIs.

For more information, follow the links under the “Documentation” column.

JavaScript RPC Payload Documentation
NA onRequestName ProviderRequest  
NA onRequestPostalCode ProviderRequest  
nameChanged onNameChanged string name
postalCodeChanged onPostalCodeChanged string postalCode
developerModeChanged onDeveloperModeChanged boolean developerMode

Provider Interfaces

Providers are interfaces that your app can implement in order to provide certain capabilties back to the platform.

To register a provider, use the provide() method.

Every provider interface method has the following signature:

(parameters: object | void, session: ProviderSession) => {}

ProviderSession has the following interface:


interface ProviderSession {
    correlationId(): string        // Returns the correlation id of the current provider session
}


DeviceSettingsProvider

The provider interface for the xrn:firebolt:capability:settings:device capability.

interface DeviceSettingsProvider {
	name(parameters?: object, session?: ProviderSession): Promise<string>
	postalCode(parameters?: object, session?: ProviderSession): Promise<string>
}

Usage:

Device.provide('xrn:firebolt:capability:settings:device', provider: DeviceSettingsProvider | object)

name

Request the user-assigned name of this device from the device settings provider.

function name(parameters?: object, session?: ProviderSession): Promise<string>

Provider methods always have two arguments:

Param Type Required Summary
parameters object false  
session ProviderSession false  

Promise resolution:

Type Description
string  

postalCode

Request the user-asigned postal code of this device from the device settings provider.

function postalCode(parameters?: object, session?: ProviderSession): Promise<string>

Provider methods always have two arguments:

Param Type Required Summary
parameters object false  
session ProviderSession false  

Promise resolution:

Type Description
string  

Examples

Register your app to provide the xrn:firebolt:capability:settings:device capability.

import { Device } from '@firebolt-js/manage-sdk'

class MyDeviceSettingsProvider {

    async name(parameters, session) {
        return await Promise.resolve("Living Room")
    }

    async postalCode(parameters, session) {
        return await Promise.resolve("19103")
    }

}

Device.provide('xrn:firebolt:capability:settings:device', new MyDeviceSettingsProvider())
**JSON-RPC**

Register to recieve each provider API

Request:


{
    "id": 1,
    "method": "onRequestName",
    "params": {
        "listen": true
    }
}

{
    "id": 2,
    "method": "onRequestPostalCode",
    "params": {
        "listen": true
    }
}

Response:


{
    "id": 1,
    "result": {
        "listening": true,
        "event": "Device.onRequestName"
    }            
 
}

{
    "id": 2,
    "result": {
        "listening": true,
        "event": "Device.onRequestPostalCode"
    }            
 
}

Asynchronous event to initiate name()

Event Response:

{
    "id": 1,
    "result": {
        "correlationId": "123",
        "parameters": null
    }
}

App initiated response to event

Request:

{
    "id": 3,
    "method": "nameResponse",
    "params": {
        "response": {
            "correlationId": "123",
            "result": "Living Room"
        }
    }
}

Response:

{
    "id": 3,
    "result": true
}

Asynchronous event to initiate postalCode()

Event Response:

{
    "id": 2,
    "result": {
        "correlationId": "123",
        "parameters": null
    }
}

App initiated response to event

Request:

{
    "id": 4,
    "method": "postalCodeResponse",
    "params": {
        "response": {
            "correlationId": "123",
            "result": "19103"
        }
    }
}

Response:

{
    "id": 4,
    "result": true
}
Go To Top