So it’s been a while since I last posted anything. I moved house and have generally just been busy. Recently however I found some time to do a bit more work on my home automation system. I made some good progress with the python code on my Pi, however it was starting to get in to a bit of a mess.
I started out with a bit of a design in my head but the more work I did the more that design fell apart. After spending quite some time trying to get things working after adding support for a MongoDB backend I decided to take a step back and evaluate the code and see where I could tidy up the design.
The first area I have been looking at is the way I handle talking to different communications systems, like XBee’s, Bluetooth etc. I had decided to make this modular and support plugins. Meaning I could write a handler for a new type, say Z-Wave, drop it in to a folder and have it work with no other code changes required. I had sort of achieved this but it was pretty hacky and still required a few additional code changes to support new plugins. I did some research and decided to change my implementation to use the factory pattern.
After this I wanted to make sure that my plugins were good before they were used. In C++ I would have made the plugins inherit from an interface with some pure virtual methods and that would stop the program from compiling if the plugins didn’t implement the interface completely. The nature of python means that this doesn’t happen with inheritance, however I found a python module that allows me get that functionality. woo!
I’ve written all the details up in these two tutorials: