JavaScript API

From MiOS
(Difference between revisions)
Jump to: navigation, search
(set_device_state (deviceId, serviceId, variable, value, dynamic))
(set_device_state (deviceId, serviceId, variable, value, dynamic))
Line 95: Line 95:
 
*variable (string)
 
*variable (string)
 
*value (string)
 
*value (string)
*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 the copy of ''user_data'' from the memory (the real user_data is updated when LuaUPnP is restarted).
+
*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 a copy of ''user_data''; the real user_data is updated when LuaUPnP is restarted.
  
 
'''Output:'''  
 
'''Output:'''  

Revision as of 11:28, 24 January 2012

Contents

Usage

"Tabs": [
       {
           "Label": {
               "lang_tag": "users",
               "text": "Users" 
           },
           "Position": "0",
           "TabType": "javascript",
           "ScriptName": "I_HomeCare.js",
           "Function": "showUsers"
       }, 

To generate a tab using your JavaScript functions you need to specify this by setting TabType to javascript. Then, you need to specify the script file's name and which function in this 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

get_device_state (deviceId, serviceId, variable, dynamic)

Input:

  • deviceId (number)
  • serviceId (string)
  • variable (string)
  • 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)


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

Input:

  • deviceId (number)
  • serviceId (string)
  • variable (string)
  • value (string)
  • 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 a copy of user_data; the real user_data is updated when LuaUPnP is restarted.

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 in order to have a console.

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