Power | Firebolt

Power Module


Version 0.1.0-alpha.4

Overview

A module for managing device power state and settings.

OpenRPC

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

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

Table of Contents

 

Usage

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

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

Methods

autoStandby

Set whether or not this device is set to go to active-standby when it’s idle, e.g. for enabling a ‘Store Mode’.

function autoStandby(auto?: boolean): Promise<boolean>

Parameters:

Param Type Required Summary
auto boolean false  

Promise resolution:

Type Description
boolean  

Examples

Turn on auto-standby

JavaScript:

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

Power.autoStandby(true)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.autoStandby",
  "params": {
    "auto": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
More examples… Turn off auto-standby

JavaScript:

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

Power.autoStandby(false)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.autoStandby",
  "params": {
    "auto": false
  }
}

Response:

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

Check value of auto-standby

JavaScript:

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

Power.autoStandby(null)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.autoStandby",
  "params": {}
}

Response:

{
  "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:

Power.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. Power.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:

Power.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. Power.clear(id)

See Listening for events for more information and examples.


motionEnabledWhileSuspended

Set whether or not motion-detection will remain enabled when the device is suspended.

function motionEnabledWhileSuspended(enabled?: boolean): Promise<boolean>

Parameters:

Param Type Required Summary
enabled boolean false  

Promise resolution:

Type Description
boolean  

Examples

Turn on motion-detection during suspended

JavaScript:

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

Power.motionEnabledWhileSuspended(true)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.motionEnabledWhileSuspended",
  "params": {
    "enabled": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
More examples… Turn off motion-detection during suspended

JavaScript:

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

Power.motionEnabledWhileSuspended(false)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.motionEnabledWhileSuspended",
  "params": {
    "enabled": false
  }
}

Response:

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

Check value of motion-detection during suspended

JavaScript:

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

Power.motionEnabledWhileSuspended(null)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.motionEnabledWhileSuspended",
  "params": {}
}

Response:

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

networkEnabledWhileSuspended

Set whether or not the network will remain enabled when the device is suspended.

function networkEnabledWhileSuspended(enabled?: boolean): Promise<boolean>

Parameters:

Param Type Required Summary
enabled boolean false  

Promise resolution:

Type Description
boolean  

Examples

Turn on network during suspended

JavaScript:

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

Power.networkEnabledWhileSuspended(true)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.networkEnabledWhileSuspended",
  "params": {
    "enabled": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
More examples… Turn off network during suspended

JavaScript:

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

Power.networkEnabledWhileSuspended(false)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.networkEnabledWhileSuspended",
  "params": {
    "enabled": false
  }
}

Response:

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

Check value of network during suspended

JavaScript:

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

Power.networkEnabledWhileSuspended(null)
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.networkEnabledWhileSuspended",
  "params": {}
}

Response:

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

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:

Power.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. Power.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:

Power.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. Power.clear(id)

See Listening for events for more information and examples.


sleep

Request that the device transition to the active-standby state, presumably from the active state.

function sleep(): Promise<boolean>

Promise resolution:

Type Description
boolean  

Examples

Request the device to sleep

JavaScript:

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

Power.sleep()
    .then(success => {
        console.log(success)
    })

Value of success:

true
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.sleep",
  "params": {}
}

Response:

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

state

Get the current power state. This function is synchronous.

function state(): PowerState

Promise resolution:

Type Description
PowerState Device power states. Note that ‘suspended’ is not included, because it’s impossible for app code to be running during that state.

Examples

Default Example

JavaScript:

import { Power } from ''

const state = Power.state()
console.log(state)

Value of state:

"active"
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.state",
  "params": {}
}

Response:

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

Events

active

Listen for when the device is put into the active power state.

See also: listen(), once(), clear().

Event value:

Type Description
ActiveEvent  

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('active', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onActive",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onActive",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onActive",
    "listening": true
  }
}

activeStandby

Listen for when the device is moved from active to active-standby.

See also: listen(), once(), clear().

Event value:

Type Description
StandbyEvent  

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('activeStandby', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onActiveStandby",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onActiveStandby",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onActiveStandby",
    "listening": true
  }
}

inactivity

Listen for when the device has become idle, and will be moved from active, to active-standby. This will fire with enough time to prompt the user to cancel.

See also: listen(), once(), clear().

Event value:

void

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('inactivity', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onInactivity",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onInactivity",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onInactivity",
    "listening": true
  }
}

inactivityCancelled

Listen for when the something happens to invalidate the previous inactivity state.

See also: listen(), once(), clear().

Event value:

Type Description
InactivityCancelledEvent  

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('inactivityCancelled', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onInactivityCancelled",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onInactivityCancelled",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onInactivityCancelled",
    "listening": true
  }
}

powerOn

Listen for when the device is powered up.

See also: listen(), once(), clear().

Event value:

void

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('powerOn', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onPowerOn",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onPowerOn",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onPowerOn",
    "listening": true
  }
}

resumedFromSuspended

Listen for when the device is woken from a suspended state.

See also: listen(), once(), clear().

Event value:

Type Description
ResumeEvent  

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('resumedFromSuspended', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onResumeFromSuspend",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onResumedFromSuspended",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onResumeFromSuspend",
    "listening": true
  }
}

suspendPending

Listen for when the device will be suspended from the active-standby state. CPU excution will cease shortly after this event.

See also: listen(), once(), clear().

Event value:

Type Description
SuspendEvent  

Examples

Default Example:

JavaScript:

import { Power } from '@firebolt-js/sdk'

Power.listen('suspendPending', value => {
  console.log(value)
})

Value of value

{
  "event": "Power.onSuspendPending",
  "listening": true
}
JSON-RPC:

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "power.onSuspendPending",
  "params": {
    "listen": true
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "event": "Power.onSuspendPending",
    "listening": true
  }
}

Schemas

PowerState

Device power states. Note that ‘suspended’ is not included, because it’s impossible for app code to be running during that state.

type PowerState = 'active' | 'activeStandby'

ActiveEvent

type ActiveEvent = {
  reason: 'firstPowerOn' | 'powerOn' | 'rcu' | 'frontPanel' | 'hdmiCec' | 'dial' | 'motion' | 'farFieldVoice'
}

StandbyEvent

type StandbyEvent = {
  reason: 'inactivity' | 'rcu' | 'frontPanel' | 'hdmiCec' | 'dial' | 'farFieldVoice' | 'ux'
}

ResumeEvent

type ResumeEvent = {
  reason: 'system' | 'rcu' | 'frontPanel' | 'hdmiCec' | 'dial' | 'motion' | 'farFieldVoice'
}

SuspendEvent

type SuspendEvent = {
  reason: 'powerOn' | 'rcu' | 'frontPanel'
}

InactivityCancelledEvent

type InactivityCancelledEvent = {
  reason: 'rcu' | 'frontPanel' | 'farFieldVoice' | 'dial' | 'hdmiCec' | 'motion'
}

Go To Top