Page 1 of 1
OO programming with dzEvents
Posted: Friday 30 November 2018 14:02
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?
Re: OO programming with dzEvents
Posted: Friday 30 November 2018 14:14
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.
Re: OO programming with dzEvents
Posted: Saturday 01 December 2018 0:30
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?
Re: OO programming with dzEvents
Posted: Saturday 01 December 2018 0:43
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.
Re: OO programming with dzEvents
Posted: Saturday 01 December 2018 10:07
by garethhowell
Thanks
Re: OO programming with dzEvents
Posted: Saturday 01 December 2018 10:15
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.