We have moved at community.getvera.com

Author Topic: Plugin: LuaView  (Read 3440 times)

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Plugin: LuaView
« on: August 26, 2018, 10:26:39 am »
LuaView is a simple plugin that puts all of your scene's Lua scripts on a single page, making it easier to see the relationships between them, identify global variables and shared data, etc. The scripts are editable. The startup Lua is also displayed/editable.

This simple project was an interesting exercise. I almost got away with it having no Lua implementation whatsoever (all JavaScript), but alas, there was one thing I could not find in the JavaScript API (saving Startup Lua), so I implemented it as a custom Luup request. In any case, this is a very lightweight, single-instance plugin.

The source code and documentation for this project can be found in its Github repository.

As always, discussions and questions about this plugin in this thread, please.


VERSION HISTORY
2019-01-20: Release 1.5. This version checks syntax of Luup code and reports any problems to the user.

2019-01-03: Release 1.4 loads ACE if it's not loaded, so it offers a syntax-highlighting editor on UI7.

2018-11-11: Release 1.3. This version unifies the UI7 and ALTUI code and makes the decision on which interface to present (dumb textareas or fancy ACE editor) based on availability/resources.

2018-08-27: Release 1.2 is now available in the AltAppStore (only). This version addresses @jswim788's excellent suggestion that it use the ACE editor familiar in other area of ALTUI. ACE does syntax highlighting and code checking.

2018-08-26: Release 1.0 is available in the Vera Plugin Maretplace; version 1.1, exclusively for openLuup, is available in the AltAppStore.
« Last Edit: January 21, 2019, 09:43:14 am by rigpapa »
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Plugin: LuaView
« Reply #1 on: August 26, 2018, 11:35:05 am »
openLuup support?  Thanks.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #2 on: August 26, 2018, 02:50:22 pm »
openLuup support?  Thanks.

Well... OK.  :)

Took a little longer, because openLuup doesn't do Vera Luup's Lua encoding thing, so I had to add detection and exceptions for openLuup, but easy enough. In the AltAppStore.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Plugin: LuaView
« Reply #3 on: August 26, 2018, 03:04:24 pm »
Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window?  That would be fantastic to see the syntax checker built in.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #4 on: August 26, 2018, 03:15:02 pm »
Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window?  That would be fantastic to see the syntax checker built in.

I've added that as issue #1 on Github.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #5 on: August 27, 2018, 05:32:20 pm »
Nicely done - thank you.

For bonus points, any chance of using the AltUI Lua code editor that is in the Lua Code Test window?  That would be fantastic to see the syntax checker built in.

I've added that as issue #1 on Github.

Issue #1 has now been addressed with the release of version 1.2 to the AltAppStore (applies to ALTUI only, available now). Per @jswim788's excellent suggestion, this version uses the ACE editor when running under ALTUI, which gives you syntax highlighting and code validation.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: Plugin: LuaView
« Reply #6 on: August 27, 2018, 10:21:08 pm »
Good work - it's going well over here. Have already found some dusty old code, hiding in a dark corner.

Currently each editor box for each scene is about 8 lines high minimum by default. All my scenes (65 off) just contain one line of code. So lots of white space with all the edit boxes. Would it be possible to auto size the vertical, so it can shrink down to the number of lines code +1 and the auto scroll kicks in, if the box height reaches the current 8 lines?

It would be good if the scenes could be optionally sorted by scene id, as well as by the currently used scene name. Sort setting would persist.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #7 on: August 27, 2018, 10:35:20 pm »
Good work - it's going well over here. Have already found some dusty old code, hiding in a dark corner.

Currently each editor box for each scene is about 8 lines high minimum by default. All my scenes (65 off) just contain one line of code. So lots of white space with all the edit boxes. Would it be possible to auto size the vertical, so it can shrink down to the number of lines code +1 and the auto scroll kicks in, if the box height reaches the current 8 lines?

It would be good if the scenes could be optionally sorted by scene id, as well as by the currently used scene name. Sort setting would persist.

Are you using AltUI or UI7, @a-lurker?
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: Plugin: LuaView
« Reply #8 on: August 27, 2018, 10:52:28 pm »
In AltUI with FireFox & openLuup.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Plugin: LuaView
« Reply #9 on: August 27, 2018, 11:29:37 pm »
This is really nice.  Thank you again.  I can definitely gain some efficiency this way.

I do think it might be nice to have the startup Lua and the scene code on the same page.  The reason is that it is easier to see the scene code and figure out what global functions and constants are needed and work on them in the same page.  AltUI and openLuup.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #10 on: August 27, 2018, 11:38:44 pm »
In AltUI with FireFox & openLuup.

There's a state variable called AceOptions that you can put editor options into as a JSON object. For the moment, try this as a workaround: { minLines: 2, maxLines: 8 }
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: Plugin: LuaView
« Reply #11 on: August 28, 2018, 12:26:29 am »
Yep that worked OK. Thanks.

I had to use quotes:

Code: [Select]
{ "minLines": 2, "maxLines": 8 }
else I got the "Can't apply your custom AceOptions: SyntaxError: JSON.parse ...."

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #12 on: August 28, 2018, 08:28:11 am »
I had to use quotes:

Code: [Select]
{ "minLines": 2, "maxLines": 8 }
else I got the "Can't apply your custom AceOptions: SyntaxError: JSON.parse ...."

And that's what I get for posting when I should be asleep. Sorry about that, but I'm glad you worked it out.

I'm pretty sure you can put any option you want there, including the theme. I went with a lighter theme than ALTUI's by default because I have trouble reading the monokai color scheme on the dark background. But if you want it consistent with the rest of ALTUI, just add "theme": "ace/themes/monokai" to that list.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +187/-3
Re: Plugin: LuaView
« Reply #13 on: August 28, 2018, 08:31:31 am »
This is really nice.  Thank you again.  I can definitely gain some efficiency this way.

I do think it might be nice to have the startup Lua and the scene code on the same page.  The reason is that it is easier to see the scene code and figure out what global functions and constants are needed and work on them in the same page.  AltUI and openLuup.

OK. Question then: a-lurker also suggested sorting options. If I put the startup Lua on the same page with scene Lua, what would you expect from how it's sorted? I'm thinking just pin it to the top/first position, and the scenes come after.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: Plugin: LuaView
« Reply #14 on: August 28, 2018, 08:49:08 am »
Yes, at the top... it is, after all, global to all the other scene code.
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.