jeedom-request-jsonrpc
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Welcome to jeedom-request-jsonrpc 👋

Jeedom API - JSON RPC 2.0 for NodeJs

Coverage Coverage Coverage

Overview

Node module to calls Jeedom's RPC API : https://jeedom.github.io/core/fr_FR/jsonrpc_api

This module uses phin for request (https://github.com/ethanent/phin)

Install

  • npm i jeedom-request-jsonrpc --save
  • yarn add jeedom-request-jsonrpc

Get Started

Import package:

const { apiJeedom } = require('jeedom-request-jsonrpc')

Instanciate:

const apiJeedomRunnable = new apiJeedom(
    'jeedom-hostname-or-ip',
    'my-api-key'
)

Details of apiJeedom function:

apiJeedom(jeedomHost, apikey, reqParams = {}, jsonrpc = '2.0', uriJeedomApi = '/core/api/jeeApi.php')

  • jeedomHost host of jeedom server
  • apikey api key of jeedom
  • reqParams optionnals params to add to request (phin package options)
  • jsonrpc version of jsonrpc
  • uriJeedomApi base url of jeedom server

Make a request:

const requestJeedom = apiJeedomRunnable.run(
    'scenario::changeState', {
        id: 11,
        state: 'run'
    })

Details of apiJeedomRunnable.run function:

apiJeedomRunnable.run(cmd, params)

  • cmd command of API
  • params params belongs to command

Example 1 : (Promise flow)

requestJeedom
.then(response => {
    console.log('Response : ', response.result)
})
.catch(error => {
    console.log('An error : ', error)
})

Example 2 : (async - await)

const functionToRequestJeedom = async () => {
    try {
        let jeedomResponse = await requestJeedom
        console.log("Response", jeedomResponse)
    } catch (e) {
        cb(e)
    }
}
 
functionToRequestJeedom()

Requests result examples

without a value returned

 
{
    "statusCode": 200,
    "statusMessage":"OK",
    "result": true,
    "error": false
}

with a value returned

{
    "statusCode": 200,
    "statusMessage":"OK",
    "result":{
        "collectDate": "2018-09-30 14:49:03",
        "value": 21.2
     },
    "error": false
}

with an error

{
  "statusCode": 200,
  "statusMessage": "OK",
  "result": false,
  "error": {
    "code": 701,
    "message": "Cmd introuvable : 63334"
  }
}

Useful links

Changelog

https://github.com/clement-berard/jeedom-request-jsonrpc/releases

Readme

Keywords

Package Sidebar

Install

npm i jeedom-request-jsonrpc

Weekly Downloads

19

Version

1.1.1

License

ISC

Unpacked Size

185 kB

Total Files

9

Last publish

Collaborators

  • clement-berard