We have moved at community.getvera.com

Author Topic: LuaTest - A Tool for Testing Scene Lua Code  (Read 41036 times)

Offline iHomeCtrl

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #60 on: June 05, 2017, 03:38:35 pm »
Does this still work with the latest UI7.  Looking for some method to test our Lua code and the built in stuff does not cut it.

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #61 on: June 05, 2017, 03:46:36 pm »
It may do.  I was a huge fan of this, but now use AltUI, which is (a) fantastically better interface than UI7, and (b) is great for testing Lua code because the print statement works.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #62 on: June 05, 2017, 03:48:10 pm »
Yes, it did last time I used it.
The other option you may wish to investigate include AltUI and
https://studio.zerobrane.com/vera.html

Offline iHomeCtrl

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #63 on: June 06, 2017, 10:32:08 am »
Seems like Vera would have allot more people doing development work if they had a tools like the ZeroBrane one. 

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #64 on: June 06, 2017, 04:52:35 pm »
It works on UI7. Been using it quite extensively myself.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline cgmartin

  • Newbie
  • *
  • Posts: 15
  • Karma: +2/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #65 on: September 28, 2017, 09:00:30 pm »
Sharing some personal modifications I made to 1.6 in case others find it useful. I've been using this in UI7:

- Added CodeMirror lua syntax highlighting editor support.
- Test results are now displayed in an iframe on the same page as the editor.

See gist: https://gist.github.com/cgmartin/d52409fe473e1d4fc5044c3d676d109c

[Edit: attached screenshot]
« Last Edit: September 29, 2017, 11:32:21 am by cgmartin »

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #66 on: October 01, 2017, 02:28:18 pm »
Hi

I?m a big user of LuaTest

Is there any reason why this should not work on UI5 too ?

Update : Answering my own question it seems to work fine in UI5 too
« Last Edit: October 02, 2017, 04:14:22 am by parkerc »

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #67 on: October 04, 2017, 12:31:54 pm »
Hi @cgmartin

Ive noticed something strange with this version. I am a trying to save this line of code

Code: [Select]
local result = data:match "S(%d+)E" or "error"
But the plus (+) sign is removed each time ?

Code: [Select]
local result = data:match "S(%d )E" or "error"
Any ideas ?

Offline cgmartin

  • Newbie
  • *
  • Posts: 15
  • Karma: +2/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #68 on: October 04, 2017, 09:15:38 pm »
Hi @parkerc,

I was also able to reproduce that issue from your sample code.

I found some lines from v1.6 that encode the plus "+" character into "%0F" before submitting, but weren't being decoded correctly upon receiving the request. The manual encoding seems unnecessary since the browser will urlencode the value just fine - maybe there was a bug in luup with it not urldecoding the params properly? Not sure what the history is there.

I've removed the lines doing the "+" encoding/decoding and it seems to be working better. The code has been updated in the gist link. You can also see the diff of the changes I made.

The following example is saving correctly for me now:

Code: [Select]
local data = "ZS123456EZ"
local result = data:match "S(%d+)E" or "error"
print(result)

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #69 on: October 07, 2017, 07:24:07 pm »
Hi

I copied down the new file and installed it however now, when I try to save some code it adds a plus (+) into every space? E.g

If I enter this.

Code: [Select]
local code = "add anything for now"
After hitting save it goes to this..

Code: [Select]
local+code+=+"add+anything+for+now"


Is it doing that for you too ?
« Last Edit: October 07, 2017, 07:30:06 pm by parkerc »

Offline cgmartin

  • Newbie
  • *
  • Posts: 15
  • Karma: +2/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #70 on: October 07, 2017, 08:13:04 pm »
Quote
Is it doing that for you too ?

It's not - It is working in my tests.

This seems like a bug in UI5 that was patched in UI7 (what I'm running, version "1.7.3015"), and explains some of that code I tried removing in the previous post.

But I'm failing to understand why the original version I posted was causing your other issue. Between 1.6 and 1.7 it should be doing the same type of encoding of the plus sign for UI5.

I don't have a way to test on UI5. You could try this modification of the original version I published, which does the extra "+" encoding and adds a debug log line to try and narrow down the issue. If you can try that, send me the full URL it generates in the browser address bar and the output from the log - I'll try to help.

Feel free to direct message me - we can move this out of the public forum while debugging. There will probably be a bit of back and forth.

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #71 on: October 08, 2017, 06:15:20 am »
Hi @cgmartin

Thanks for assisting with this. 

An interesting observation when I look in the logs is that the code being sent/tested is not showing up ?

Test code
Code: [Select]
local status, ip = luup.inet.wget("http://checkip.dyndns.org")

print (ip: match "%d+%.%d+%.%d+%.%d+")
print(string.sub(ip, -15))
print(string.sub(ip, 21))
print (ip: match "%d+%.%d+%.%d+%.%d+")
print(" ")

Will return print statements in the LuaTest UI, but nothing is in the logs to show that the code has been processed on vera? ...

Quote
Results
No errors
Runtime: 100.8 ms
Code returned: nil

Print output

/body>

     
urrent IP CheckCurrent IP Address: XXX.XXX.XXX.XXX

However the Vera luup log just shows this...

Quote
04   10/08/17 11:10:56.784    <0x2c1d7680>
50   10/08/17 11:11:11.014   luup_log:0: LuaTest No errors
Runtime:  100.8 ms
Code returned: nil <0x3053b680>

I may also have contributed to the ?+? issues as the code I was testing at the time was the following? Not sure as I?m still new to programming.

Code: [Select]
function my_escape (s)
    s = string.gsub(s, " ", "+")
    return s
end

function my_prowl (appl, event, description)
    local prowl_url      = "https://api.prowlapp.com/publicapi/add?apikey="
        .. "yourwouldputyourapikeyhere"
        .. "&application=" .. my_escape(appl)
        .. "&event="         .. my_escape(event)
        .. "&description=" .. my_escape(description)
        .. "&priority=-1"
    luup.inet.wget(prowl_url)
end

-- my_prowl (appl, event, description)
my_prowl ("Vera Home Controller", "Testing code", "this could any description")

-- luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=yourapikeyinhere&application=DSC+Security+Event&event=Armed+Notification&description=The+DSC+alarm+system+has+been+armed&priority=1")
« Last Edit: October 08, 2017, 07:26:31 am by parkerc »

Offline cgmartin

  • Newbie
  • *
  • Posts: 15
  • Karma: +2/-0
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #72 on: October 10, 2017, 09:05:25 am »
@parkerc

Quote
nothing is in the logs to show that the code has been processed on vera

It should log only when the "save" button is used. Your log levels seem good since you are seeing other LuaTest logs. I'm out of ideas why the log wouldn't show up.

Quote
I may also have contributed to the ?+? issues as the code I was testing at the time was the following...

That code you were testing shouldn't affect the behavior of LuaTest.

 

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #73 on: November 14, 2017, 04:55:32 am »
Hi

Im not sure whats changed - maybe it?s the recent firmware updated but Ive starting to get the following Handler error when trying to access the LuaTest Url (192.168.1.183:3480/data_request?id=lr_LuaTest)

Quote
No handler

I?ve checked the start up code is still there and I have reloaded and reuploaded the RBLuatest.lua file, but still get the error? I?ve tried a reboot but no luck there either..

Does anyone have any idea what could be causing this and how to fix it?
« Last Edit: November 14, 2017, 05:02:26 am by parkerc »

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: LuaTest - A Tool for Testing Scene Lua Code
« Reply #74 on: November 14, 2017, 11:20:22 am »
Does your startup lua still have the code to register the handler as noted in the first post of this thread?  Maybe that got lost?