Hi,
Very promising library, hides complexities of integration while allowing to focus on actual value conversion routines. I found one issue and one suggestion:
1) ISSUE: lack of scope isolation between scripts. If code will be reused by copy&paste, any issue where user failed to use "local" definition (variable or function) will cause to overwrite values between scripts, which can cause hard to debug issues.
However, if fixed, i would like you to retain global scope within script, that is any defined global variable keeps its value between script executions. If not fixed, this should be explicitly mentioned in the documentation, and also suggestion that follows my post should be implemented .
One of the examples where it's beneficial having global variable retain its value is having Throttle function implementation like this:
2) SUGGESTION: like in example above, i would like to have Throttle as a function that can be reused multiple times without having to copy-paste it. Right now with global scope creep this can be done indirectly, but it's a bad practice and also will depend on event execution order (event that defines function must be guaranteed to be launched first). It would be great to have separate script editor where i can define all global functions/variables.
UPD: after thinking for a while, it might be a bit more tricky to implement this function, as Throttle usually implemented via capturing state variable in closure, creating new function instance for each usage. Need to think more about how to best implement it in this plugin. Anyway, having set of global functions is still a good addition.
3) SUGGESTION: add enable/disable flag to each object to allow for quick temporary enable and disable of mapping
question: how data can be backed up / restored? if i recover LM from backup, how i can make sure that application configuration is restored as well?
Very promising library, hides complexities of integration while allowing to focus on actual value conversion routines. I found one issue and one suggestion:
1) ISSUE: lack of scope isolation between scripts. If code will be reused by copy&paste, any issue where user failed to use "local" definition (variable or function) will cause to overwrite values between scripts, which can cause hard to debug issues.
However, if fixed, i would like you to retain global scope within script, that is any defined global variable keeps its value between script executions. If not fixed, this should be explicitly mentioned in the documentation, and also suggestion that follows my post should be implemented .
One of the examples where it's beneficial having global variable retain its value is having Throttle function implementation like this:
Code:
local data = json.pdecode(payload)
if type(data) == 'table' then
val = data.illuminance
-- global variable here that should retain its value between executions
last_update = last_update == nil and 0 or last_update
---
local now = os.time()
if((now - last_update) < 60) then
return nil
else
last_update = now
return val
end
end
2) SUGGESTION: like in example above, i would like to have Throttle as a function that can be reused multiple times without having to copy-paste it. Right now with global scope creep this can be done indirectly, but it's a bad practice and also will depend on event execution order (event that defines function must be guaranteed to be launched first). It would be great to have separate script editor where i can define all global functions/variables.
UPD: after thinking for a while, it might be a bit more tricky to implement this function, as Throttle usually implemented via capturing state variable in closure, creating new function instance for each usage. Need to think more about how to best implement it in this plugin. Anyway, having set of global functions is still a good addition.
3) SUGGESTION: add enable/disable flag to each object to allow for quick temporary enable and disable of mapping
question: how data can be backed up / restored? if i recover LM from backup, how i can make sure that application configuration is restored as well?