Code refactor

The last few days have been spent doing some fairly major refactoring and other code improvements. I wanted to add functionality for the FlthyMcNasty HP control systems and realised as I add extra API calls, then the main.py code would start to get a bit unwieldy.

To this end, I started learning about Blueprints in the Flask web framework I use.  Blueprints allow API calls to be added functionally in a modular fashion. This meant all the API definitions and functions could be brought out of main.py and into the actual script for the device in question.

Along with this I learnt how to dynamically import code into main.py, which coupled with using blueprints has given me a much more modular approach to adding various devices.

Now, plugins can be loaded by just adding them to a line in the config file. They will then be dynamically added on startup. This is going to make it a lot easier to add the various modules such as the PSI, logics, Charge Bay, etc. to the API.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.