Mycodo
Mycodo copied to clipboard
Add an import field in the conditional controler
Is your feature request related to a problem? Please describe.
I need to use functions from python libraries in the conditional controller Conditional Statement part. If I put the import
here, it will be executed at each call. Even if Python is optimised, that can seriously affect performance in some circumstances. PEP 8 states "Imports are always put at the top of the file".
Describe the solution you'd like
Add a field before the "Conditional Statement" one to enable adding imports that would be put at the top of the module.
I like that idea, it's fairly easy change to implement but adds a lot of additional value to the Conditional Function.
There are ways to import in the init function of the Class, but this is not intuitive or easy to use for Python novices, so this is a better alternative.
Thanks for the feedback.
Great. To maximaze useability, it should be in fact a general "start module" section, where one could add anything than imports.
I make a lot of errors with IDs. This "start module" will enable me also to declare an action function where all IDs will be written once:
io = {"tank full":"e38e128e",
"OpenEVwater":"db678182",
"Switch On 12V":"4e4762b0",
}
def action(name, log=None):
if name in io:
self.run_action('"{' + io[name] + '}"', message=name)
if log is None:
log = name + ' "{' + io[name] + '}"'
else:
log = "ERREUR : " + name + " is not defined"
self.logger.info(log)
I just added support for both import and class initialization code blocks. You can upgrade to master if you want to test the latest code prior to release.
This pull request has been mentioned on Radical DIY Forum. There might be relevant details there:
https://forum.radicaldiy.com/t/mycodo-v8-14-0-release/1136/1
Hi Kyle, Would it be possible please to be able to increase the edition window for the Initialize Python Code frame, and of course all of them, possibly a full screen mode? As it is, I have to copy the content and edit it in a text editor since only 4 lines are shown.