Skip to content

Power Plugin

Version: 1.0

Status: ⚫⚪⚪

Power plugin for Thunder framework.

Table of Contents

Introduction

Scope

This document describes purpose and functionality of the Power plugin. It includes detailed specification about its configuration, methods and properties as well as sent notifications.

Case Sensitivity

All identifiers of the interfaces described in this document are case-sensitive. Thus, unless stated otherwise, all keywords, entities, properties, relations and actions should be treated as such.

Acronyms, Abbreviations and Terms

The table below provides and overview of acronyms used in this document and their definitions.

Acronym Description
API Application Programming Interface
HTTP Hypertext Transfer Protocol
JSON JavaScript Object Notation; a data interchange format
JSON-RPC A remote procedure call protocol encoded in JSON

The table below provides and overview of terms and abbreviations used in this document and their definitions.

Term Description
callsign The name given to an instance of a plugin. One plugin can be instantiated multiple times, but each instance the instance name, callsign, must be unique.

References

Ref ID Description
HTTP HTTP specification
JSON-RPC JSON-RPC 2.0 specification
JSON JSON specification
Thunder Thunder API Reference

Configuration

The table below lists configuration options of the plugin.

Name Type M/O Description
callsign string mandatory Plugin instance name (default: Power)
classname string mandatory Class name: Power
locator string mandatory Library name: libThunderPower.so
startmode string mandatory Determines in which state the plugin should be moved to at startup of the framework
configuration object optional ...
configuration?.powerkey integer optional Key associated as powerkey
configuration?.offmode string optional Type of offmode
configuration?.control boolean optional Enable control clients
configuration?.gpiopin integer optional GGIO pin (Broadcom)
configuration?.gpiotype sting optional GPIO type (Broadcom)
configuration?.statechange integer optional Statechange (Broadcom)

Interfaces

This plugin implements the following interfaces:

  • IPower (IPower.h) (version 1.0.0) (compliant format)

    This interface uses legacy lowercase naming convention. With the next major release the naming convention will change to camelCase.

Methods

The following methods are provided by the Power plugin:

Built-in methods:

Method Description
versions Retrieves a list of JSON-RPC interfaces offered by this service
exists Checks if a JSON-RPC method or property exists
register Registers for an asynchronous JSON-RPC notification
unregister Unregisters from an asynchronous JSON-RPC notification

Power interface methods:

Method Description
setstate / set Set the power state

versions method

Retrieves a list of JSON-RPC interfaces offered by this service.

Parameters

This method takes no parameters.

Result

Name Type M/O Description
result array mandatory A list ofsinterfaces with their version numbers
Array length must be at most 255 elements.
result[#] object mandatory ...
result[#].name string mandatory Name of the interface
result[#].major integer mandatory Major part of version number
result[#].minor integer mandatory Minor part of version number
result[#].patch integer mandatory Patch part of version version number

Example

Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.versions"
}

Response

{
  "jsonrpc": "2.0",
  "id": 42,
  "result": [
    {
      "name": "JMyInterface",
      "major": 1,
      "minor": 0,
      "patch": 0
    }
  ]
}

exists method

Checks if a JSON-RPC method or property exists.

Description

This method will return True for the following methods/properties: getstate, versions, exists, register, unregister, setstate.

Parameters

Name Type M/O Description
params object mandatory ...
params.method string mandatory Name of the method or property to look up

Result

Name Type M/O Description
result boolean mandatory Denotes if the method exists or not

Example

Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.exists",
  "params": {
    "method": "methodName"
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 42,
  "result": false
}

register method

Registers for an asynchronous JSON-RPC notification.

Description

This method supports the following event names: statechange.

Parameters

Name Type M/O Description
params object mandatory ...
params.event string mandatory Name of the notification to register for
params.id string mandatory Client identifier

Result

Name Type M/O Description
result null mandatory Always null

Errors

Message Description
ERROR_FAILED_REGISTERED Failed to register for the notification (e.g. already registered)

Example

Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.register",
  "params": {
    "event": "eventName",
    "id": "myapp"
  }
}

Response

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

unregister method

Unregisters from an asynchronous JSON-RPC notification.

Description

This method supports the following event names: statechange.

Parameters

Name Type M/O Description
params object mandatory ...
params.event string mandatory Name of the notification to register for
params.id string mandatory Client identifier

Result

Name Type M/O Description
result null mandatory Always null

Errors

Message Description
ERROR_FAILED_UNREGISTERED Failed to unregister from the notification (e.g. not yet registered)

Example

Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.unregister",
  "params": {
    "event": "eventName",
    "id": "myapp"
  }
}

Response

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

setstate method

Set the power state.

set is an alternative name for this method. This name is deprecated and may be removed in the future. It is not recommended for use in new implementations.

Parameters

Name Type M/O Description
params object mandatory ...
params.state string mandatory The power state to set (must be one of the following: ActiveStandby, Hibernate, On, PassiveStandby, PowerOff, SuspendToRAM)
params.waittime integer mandatory The time to wait for the power state to be set in seconds

Result

Name Type M/O Description
result null mandatory Always null

Errors

Message Description
ERROR_GENERAL General failure
ERROR_DUPLICATE_KEY Trying to set the same power mode
ERROR_ILLEGAL_STATE Power state is not supported
ERROR_BAD_REQUEST Invalid Power state or Bad JSON param data format

Example

Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.setstate",
  "params": {
    "state": "Hibernate",
    "waittime": 10
  }
}

Response

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

Properties

The following properties are provided by the Power plugin:

Power interface properties:

Property R/W Description
getstate / state read-only Get the current power state

getstate property

Provides access to the get the current power state.

This property is read-only.

state is an alternative name for this property. This name is deprecated and may be removed in the future. It is not recommended for use in new implementations.

Value

Name Type M/O Description
(property) string mandatory The current power state (must be one of the following: ActiveStandby, Hibernate, On, PassiveStandby, PowerOff, SuspendToRAM)

Example

Get Request

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.getstate"
}

Get Response

{
  "jsonrpc": "2.0",
  "id": 42,
  "result": "PassiveStandby"
}

Notifications

Notifications are autonomous events triggered by the internals of the implementation and broadcasted via JSON-RPC to all registered observers. Refer to [Thunder] for information on how to register for a notification.

The following events are provided by the Power plugin:

Power interface events:

Notification Description
statechange Signals a change in the power state

statechange notification

Signals a change in the power state.

Notification Parameters

Name Type M/O Description
params object mandatory ...
params.origin string mandatory The state the device is transitioning from (must be one of the following: ActiveStandby, Hibernate, On, PassiveStandby, PowerOff, SuspendToRAM)
params.destination string mandatory The state the device is transitioning to (must be one of the following: ActiveStandby, Hibernate, On, PassiveStandby, PowerOff, SuspendToRAM)
params.phase string mandatory The phase of the transition (must be one of the following: After, Before)

Example

Registration

{
  "jsonrpc": "2.0",
  "id": 42,
  "method": "Power.1.register",
  "params": {
    "event": "statechange",
    "id": "myid"
  }
}

Notification

{
  "jsonrpc": "2.0",
  "method": "myid.statechange",
  "params": {
    "origin": "ActiveStandby",
    "destination": "SuspendToRAM",
    "phase": "After"
  }
}

The client ID parameter is passed within the notification designator, i.e. <client-id>.statechange.