OO programming with dzEvents

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
garethhowell
Posts: 115
Joined: Tuesday 17 November 2015 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: St Neots, UK
Contact:

OO programming with dzEvents

Post by garethhowell »

I’m working up a design for a “better” central heating controller for Domoticz. (Please don’t flame because you think somebody has already been there).
Coming from an OO background, I am thinking in terms of objects for thermostats, boiler controls, timers, timer plans etc. However, the challenge is persisting their values over the event/timer-driven approach adopted by Domoticz/dzEvents et al.
Has anybody successfully used the global storage capabilities of dzEvents to persist complex table variables?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: OO programming with dzEvents

Post by dannybloe »

You can persist table data with dzVents. Nothing is preventing you from doing this. The only thing is that functions are not persisted and removed from the table.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
garethhowell
Posts: 115
Joined: Tuesday 17 November 2015 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: St Neots, UK
Contact:

Re: OO programming with dzEvents

Post by garethhowell »

dannybloe wrote: The only thing is that functions are not persisted and removed from the table.
Thanks. Any suggestions on how to get around this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: OO programming with dzEvents

Post by waaren »

garethhowell wrote: Saturday 01 December 2018 0:30
dannybloe wrote: The only thing is that functions are not persisted and removed from the table.
Thanks. Any suggestions on how to get around this?
Yes, load your functions from a file like

Code: Select all

    local function getFunctions()
        fn = require("commonFunctions")
    end

    if pcall(getFunctions) then
        dz.log("getFunctions loaded",dz.LOG_DEBUG)
    end	        
I used this here. Although nothing to do with OO it might just prove to be useful for your requirements.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
garethhowell
Posts: 115
Joined: Tuesday 17 November 2015 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9317
Location: St Neots, UK
Contact:

Re: OO programming with dzEvents

Post by garethhowell »

Thanks
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: OO programming with dzEvents

Post by dannybloe »

Well, we are dealing with plain Lua and Lua offers way to create objects. What you should do is pass the persisted data to the constructor of you object and then initialise all the internal data of the object. All this is not dzVents related. I suggest to read the Lua documentation and how to require modules in your code.

Actually, dzVents object model does exactly that. I receives a Lua table from Domoticz and passes that along to the proper object constructors.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest