LuaTest is a tool for editing and testing scene Lua code. It runs on Vera as an http request handler and provides several advantages over Test Luup code (Lua):
[ul][li]Allows code to be saved in files on Vera[/li]
[li]Displays the return value from your code[/li]
[li]Reports code errors directly[/li]
[li]Indicates code execution time[/li]
[li]Shows output from print statements[/li]
[li]Provides values of local variables after a runtime error[/li]
[li]Creates lists of variables and actions for your system[/li]
[li]Includes option to display all variables for any device[/li][/ul]
To install LuaTest, upload the attached file RBLuaTest.lua using APPS → Develop Apps → Luup files → Choose file → GO and then restart Vera.
Enter the following code into APPS → Develop Apps → Test Luup code (Lua) and click GO:
local rblt = require("RBLuaTest")
rbLuaTest = rblt.rbLuaTest
luup.register_handler("rbLuaTest","LuaTest")
When used this way, the handler will work until Vera is restarted. The three lines can, alternatively, be added to Startup Lua for permanent availability.
To open a new or existing Lua file on Vera, enter:
<veraip>:3480/data_request?id=lr_LuaTest&file=<filename.lua>
Where is the IP address of your Vera (without the <>). If <filename.lua> starts with a / it is assumed to be a full pathname otherwise it will be located in /etc/cmh-ludl/. If you do not provide a filename, the default luatest.lua will be used. If the file does not exist, it will be created when you save your code.
The following command will open LuaTest to edit the default file luatest.lua in the default folder /etc/cmh-ludl/:
<veraip>:3480/data_request?id=lr_LuaTest
Now enter your Lua code in the Code box. You can use simple copy/cut/paste commands by clicking the right mouse button.
You can use the buttons provided to create lists of the variables and actions for all the devices on your system. These are presented in a form that allows simple copy/paste into the luup.variable_get(…) and luup.call_action(…) calls in your code.
The Show Device Status button will open a new browser tab and display all variables for the specified Device Number. The values will be updated whenever the browser page is refreshed (usually F5 key). You may use the button to open pages for multiple devices.
When you have finished editing your code, click Save Code to create or update the file. Now you can click Test Code to have your code run as if it was in a scene. A new browser tab will open to show the results of the test.
Lua’s print statements can be very useful when testing and debugging. With a few strategically placed in your code, you can quickly determine which sections are being executed and the value of key variables. You can leave the print statements in your code, if you wish, as Vera usually sends the output to a black hole.
There is now a LuaTest User Guide initiated by Tim Brien.
Edit: 18/03/2014 19:05 Version 1.1 Added edit and save functions.
Edit: 21/03/2014 11:24 Version 1.2 Minor tweaks and cleanup.
Edit: 22/03/2014 13:38 Version 1.2.1 Simplified runtime/code error messages.
Edit: 23/03/2014 14:08 Version 1.3 Added Device Variable List and Value buttons.
Edit: 24/03/2014 09:03 Version 1.4 Added Device Actions List.
Edit: 26/03/2014 09:39 Version 1.5 Added Device Status button.
Edit: 03/04/2014 13:16 Added link to User Guide.
Edit: 03/04/2014 14:26 Version 1.5.2 Allows use of pretty(…) function. See here.
Edit: 20/08/2014 09:08 Version 1.6 Fixed Device Actions List for UI7.
Edit: 12/01/2018 14:00 Version 1.7 Updated for security enhancements in Vera 7.27.