JavaScript API

From MiOS
(Difference between revisions)
Jump to: navigation, search
m
Line 1: Line 1:
[[Category:Development]]
+
== Usage  ==
 +
<pre>"Tabs": [
  
'''The JavaScript API'''
+
      {
 +
          "Label": {
 +
              "lang_tag": "users",
 +
              "text": "Users"
 +
          },
 +
          "Position": "0",
 +
          "TabType": "&lt;span style="color: rgb(0, 0, 255);"&gt;javascript&lt;/span&gt;", "ScriptName": "&lt;span style="color: rgb(0, 0, 255);"&gt;I_HomeCare.js&lt;/span&gt;", "Function": "&lt;span style="color: rgb(0, 0, 255);"&gt;showUsers&lt;/span&gt;" }, </pre>
 +
To generate a tab using your JavaScript functions you need to specify this by setting ''TabType'' to '''''javascript'''''. Then, you need to specify which function in the given file will be used to draw the tab's content. That function will have one argument, which is the device number.<br>
  
== Variables ==
+
==== &lt;functionName&gt; (deviceNumber)  ====
==== jsonp.ud ====
+
This is the user data.
+
* '''Type''': object
+
* '''Members''':
+
** devices (array)
+
** scenes (array)
+
** users (array)
+
** rooms (array)
+
** eventList (array)
+
** etc.
+
  
 +
This is the tab rendering function. The [[#set_panel_html]] function must be called at the end.<br>
  
==== jsonp.ud.devices ====
+
'''Input:'''  
* '''Type''': array
+
* '''Members''':
+
** id (number)
+
** device_type (string)
+
** room (number)
+
** name (string)
+
** category_num (number)
+
** etc.
+
  
 +
*deviceNumber (number)<br>
  
==== jsonp.ud.scenes ====
+
'''Output:'''  
* '''Type''': array
+
* '''Members''':
+
** id (number)
+
** name (string)
+
** room (number)
+
** Timer_ids (array)
+
** Timer (object)
+
** etc.
+
  
 +
*nothing
  
== Functions ==
+
<br>
==== variable_get (serviceId, variable, deviceId, dynamic) ====
+
  
(wrapper for '''get_device_state (deviceId, serviceId, variable, dynamic)''')
+
== Variables  ==
  
'''Input:'''
+
==== jsonp.ud  ====
* serviceId (string)
+
* variable (string)
+
* deviceId (number)
+
* dynamic (number): if '''1''', the variable's value is taken from ''lu_status'', else, the variable's value is taken from ''user_data''. ''user_data'' is read at Luup startup, so for variables that change their value frequently (like Watts, Temperature, etc.) ''dynamic'' should be '''1'''.
+
'''Output:'''
+
* variable value (string or ''undefined'')
+
  
 +
This is the user data.
 +
 +
*'''Type''': object
 +
*'''Members''':
 +
**devices (array)
 +
**scenes (array)
 +
**users (array)
 +
**rooms (array)
 +
**eventList (array)
 +
**etc.
 +
 +
<br>
 +
 +
==== jsonp.ud.devices  ====
 +
 +
*'''Type''': array
 +
*'''Members''':
 +
**id (number)
 +
**device_type (string)
 +
**room (number)
 +
**name (string)
 +
**category_num (number)
 +
**etc.
 +
 +
<br>
 +
 +
==== jsonp.ud.scenes  ====
 +
 +
*'''Type''': array
 +
*'''Members''':
 +
**id (number)
 +
**name (string)
 +
**room (number)
 +
**Timer_ids (array)
 +
**Timer (object)
 +
**etc.
 +
 +
<br>
 +
 +
== Functions  ==
 +
 +
==== variable_get (serviceId, variable, deviceId, dynamic)  ====
 +
 +
(wrapper for '''get_device_state (deviceId, serviceId, variable, dynamic)''')
 +
 +
'''Input:'''
 +
 +
*serviceId (string)
 +
*variable (string)
 +
*deviceId (number)
 +
*dynamic (number): if '''1''', the variable's value is taken from ''lu_status'', else, the variable's value is taken from ''user_data''. ''user_data'' is read at Luup startup, so for variables that change their value frequently (like Watts, Temperature, etc.) ''dynamic'' should be '''1'''.
 +
 +
'''Output:'''
 +
 +
*variable value (string or ''undefined'')
 +
 +
<br>
  
 
==== variable_set (serviceId, variable, value, deviceId, dynamic)  ====
 
==== variable_set (serviceId, variable, value, deviceId, dynamic)  ====
Line 68: Line 103:
 
*''true'' if the operation succeeded, ''false'' otherwise
 
*''true'' if the operation succeeded, ''false'' otherwise
  
 +
<br>
  
 
==== _console (str)  ====
 
==== _console (str)  ====
Line 79: Line 115:
 
*nothing
 
*nothing
  
 +
<br>
  
 
==== set_panel_html (html)  ====
 
==== set_panel_html (html)  ====
Line 91: Line 128:
  
 
*nothing
 
*nothing
 +
 +
[[Category:Development]]

Revision as of 16:25, 10 June 2011

Contents

Usage

"Tabs": [

       {
           "Label": {
               "lang_tag": "users",
               "text": "Users" 
           },
           "Position": "0",
           "TabType": "<span style="color: rgb(0, 0, 255);">javascript</span>", "ScriptName": "<span style="color: rgb(0, 0, 255);">I_HomeCare.js</span>", "Function": "<span style="color: rgb(0, 0, 255);">showUsers</span>" }, 

To generate a tab using your JavaScript functions you need to specify this by setting TabType to javascript. Then, you need to specify which function in the given file will be used to draw the tab's content. That function will have one argument, which is the device number.

<functionName> (deviceNumber)

This is the tab rendering function. The #set_panel_html function must be called at the end.

Input:

  • deviceNumber (number)

Output:

  • nothing


Variables

jsonp.ud

This is the user data.

  • Type: object
  • Members:
    • devices (array)
    • scenes (array)
    • users (array)
    • rooms (array)
    • eventList (array)
    • etc.


jsonp.ud.devices

  • Type: array
  • Members:
    • id (number)
    • device_type (string)
    • room (number)
    • name (string)
    • category_num (number)
    • etc.


jsonp.ud.scenes

  • Type: array
  • Members:
    • id (number)
    • name (string)
    • room (number)
    • Timer_ids (array)
    • Timer (object)
    • etc.


Functions

variable_get (serviceId, variable, deviceId, dynamic)

(wrapper for get_device_state (deviceId, serviceId, variable, dynamic))

Input:

  • serviceId (string)
  • variable (string)
  • deviceId (number)
  • dynamic (number): if 1, the variable's value is taken from lu_status, else, the variable's value is taken from user_data. user_data is read at Luup startup, so for variables that change their value frequently (like Watts, Temperature, etc.) dynamic should be 1.

Output:

  • variable value (string or undefined)


variable_set (serviceId, variable, value, deviceId, dynamic)

(wrapper for set_device_state (deviceId, serviceId, variable, value, dynamic))

Input:

  • serviceId (string)
  • variable (string)
  • value (string)
  • deviceId (number)
  • dynamic (number): if 1, the variable's value is saved to lu_status (the value is lost after Luup is restarted), else, the variable's value is saved to user_data (requires restart to save the new value).

Output:

  • true if the operation succeeded, false otherwise


_console (str)

Input:

  • str (string): text to be written in the console. You need to have FireBug installed.

Output:

  • nothing


set_panel_html (html)

Used in the tab rendering functions.

Input:

  • html (string): The html to be used for generating the tab content.

Output:

  • nothing
Personal tools