“Trigger” database code

So I spent a good portion of today, re-working my database code.  When I started, I realized my sensor modules ALL get loaded, regardless if they are used or even installed.  For my code, it’s pretty small, but the sensor’s imported code will add up, especially as more sensors are supported.  So I found a way to load them on demand AFTER checking to see which sensors are installed.  

To make this happen, I turned each sensor module, into a class and moved the import into the class initializer. AKA, it only imports when a instance of the class is made.  This also makes it a bit easier to follow the code, as each instance has all the needed functions.  Due to the new simplicity, I was also able to remove 2 other .py modules.  I’m also finding that a lot of my modules are getting smaller and smaller, most are no more than 200 lines of code now, with a lot of it being the license at the top and setting up the logger.  So that’s helping with code management. 

The Trigger code has all the basics EXCEPT the actual variance checks (AKA the triggers).  I’ll probably have that done tomorrow, but in the meantime, I wanted to build up some database readings, so I made it write all the trigger readings to the database every 5 min and updated my sensors with it.  

It seems like every time I get something working, I have another 3 things I want to add!  My todo list is getting pretty long, and much of it, is no simple task to do (relatively speaking … probably take days or weeks).  If I’m not adding a new feature, I’m refactoring the code!  In fact, I seem to be refactoring more then adding functions now, but that’s mostly because I’m learning as I go, and start implementing better ways of doing things as I learn them.  A few examples include the new logger, using classes, making better logic loops and naming things to make sense, based on what they do or hold.  

As always, I’m happy with the progress that’s being made.  If not in the program, in my learning how to program ^_^

I still like looking back at my old code and seeing how its changed.  I should really remember to take screenshots of the program’s progress, to keep a visual record of its development. I found a pic of the program, near its initial development, and I remember how excited I was at the time, that I was able to make something like that.  The program(s) have come a long way since then (2 months ago), but because I’m excited about the progress, not the product, my excitement and motivation level is remaining fairly high (when I have had enough sleep).  

I think that’s enough programing for today.  Until next time!

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>