{"id":507,"date":"2018-09-25T20:55:45","date_gmt":"2018-09-26T03:55:45","guid":{"rendered":"http:\/\/dragonwarz.net\/?p=507"},"modified":"2018-09-25T20:55:45","modified_gmt":"2018-09-26T03:55:45","slug":"trigger-database-code","status":"publish","type":"post","link":"https:\/\/dragonwarz.net\/?p=507","title":{"rendered":"&#8220;Trigger&#8221; database code"},"content":{"rendered":"\n<p>So I spent a good portion of today, re-working my database code.\u00a0 When I started, I realized my sensor modules ALL get loaded, regardless if they are used or even installed.\u00a0 For my code, it&#8217;s pretty small, but the sensor&#8217;s imported code will add up, especially as more sensors are supported.\u00a0 So I found a way to load them on demand AFTER checking to see which sensors are installed.\u00a0\u00a0<\/p>\n\n\n\n<p>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.\u00a0 This also makes it a bit easier to follow the code, as each instance has all the needed functions.\u00a0 Due to the new simplicity, I was also able to remove 2 other .py modules.\u00a0 I&#8217;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.\u00a0 So that&#8217;s helping with code management.\u00a0<\/p>\n\n\n\n<p>The Trigger code has all the basics EXCEPT the actual variance checks (AKA the triggers).\u00a0 I&#8217;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.\u00a0\u00a0<\/p>\n\n\n\n<p>It seems like every time I get something working, I have another 3 things I want to add!\u00a0 My todo list is getting pretty long, and much of it, is no simple task to do (relatively speaking &#8230; probably take days or weeks).\u00a0 If I&#8217;m not adding a new feature, I&#8217;m refactoring the code!\u00a0 In fact, I seem to be refactoring more then adding functions now, but that&#8217;s mostly because I&#8217;m learning as I go, and start implementing better ways of doing things as I learn them.\u00a0 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.\u00a0\u00a0<\/p>\n\n\n\n<p>As always, I&#8217;m happy with the progress that&#8217;s being made.\u00a0 If not in the program, in my learning how to program ^_^<\/p>\n\n\n\n<p>I still like looking back at my old code and seeing how its changed.\u00a0 I should really remember to take screenshots of the program&#8217;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.\u00a0 The program(s) have come a long way since then (2 months ago), but because I&#8217;m excited about the progress, not the product, my excitement and motivation level is remaining fairly high (when I have had enough sleep).\u00a0\u00a0<\/p>\n\n\n\n<p>I think that&#8217;s enough programing for today.\u00a0 Until next time!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I spent a good portion of today, re-working my database code.\u00a0 When I started, I realized my sensor modules ALL get loaded, regardless if they are used or even installed.\u00a0 For my code, it&#8217;s pretty small, but the sensor&#8217;s &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/dragonwarz.net\/?p=507\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-507","post","type-post","status-publish","format-standard","hentry","category-random"],"_links":{"self":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=507"}],"version-history":[{"count":1,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=\/wp\/v2\/posts\/507\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dragonwarz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}