toggledbits / AutoVirtualThermostat

Plugin for Vera Home Automation that performs the function of an auto-changeover thermostat, reading temperature from external sensors, and controlling external devices.
http://www.toggledbits.com/avt
GNU General Public License v3.0
3 stars 0 forks source link

AVT does not run under openLuup #6

Open toggledbits opened 6 years ago

toggledbits commented 6 years ago

Due to a key difference in the way openLuup loads modules compared to Vera Luup, AVT thus far is not able to run under openLuup.

For the curious, the critical differences are these:

  1. Vera Luup loads each module required by an implementation in a separate context (presumably, a subcontext of, or the same context as, the implementation for the device). So if there are 10 devices for a plugin, there are 10 contexts for the module/implementation (which explains Vera's memory-hungry behavior). openLuup loads a module in its own context, and that context is shared between implementations (i.e. the module is actually loaded only once, as is common for Lua require).
  2. Since openLuup does not have separate context for each module, some parts of the luup global are not available, in particular, luup.device, the device number of the plugin device in context. If it is not passed in by the normal behavior of luup (e.g. lul_device), you can't get it.

The combination of the above two facts makes the current code unable to determine, in the watch callback, which AVT device is in context.

toggledbits commented 6 years ago

The current STABLE branch (180724) has a workaround that I think is both simple and diabolically clever for the above problem. It turns out that the implementation functions defined in the functions tag of the implementation file do have separate context (just not the modules it may load), and that luup.device is set within those functions and available. So the answer is to make skeleton callbacks in the implementation that call the module's callback handlers, passing an additional argument for the parent device (which is luup.device in the skeleton). Needs testing, but promising.