TomFaulkner / SenseMe

Python Library for Haiku SenseMe app controlled fans/lights
GNU General Public License v3.0
21 stars 10 forks source link

Fix monitor loop exiting with exception in action. #28

Closed mikelawrence closed 6 years ago

mikelawrence commented 6 years ago

I don't know if you were looking for a pull request that would correct issue #25 but here is my take on fixing it.

Since _get_all_bare() is used in multiple places it should continue to produce exceptions and the calling code should decide what to do based on the exception. So _loop() in background_monitor.py should get the exception handling code.

In my code I catch ALL exceptions and some would say this is bad form. In this particular instance I don't think that is the case. Since this a thread running in the background there is no way pass the exceptions up without causing the background _loop() to stop executing. Actually catching exceptions, logging them and then allowing the _loop to try again later is reasonable.

mikelawrence commented 6 years ago

I made changes as you suggested.

I have been working on a custom component for Home Assistant. Home Assistant does not want components to access devices directly but instead requires the use of libraries installed via PIP like your SenseMe library. Would you be willing you create a new release and publish to PyPi? That will make my Home Assistant custom component easily work for others.

TomFaulkner commented 6 years ago

Yeah, I was planning on pushing out an update with your changes. It will probably be this weekend, when I get to try this change.

Thanks for the help!

How is home assistant, by the way? I've looked at it, but not really tried it.

mikelawrence commented 6 years ago

Awesome on the release timing!

Well to be honest Home Assistant is the first home automation aggregator I've used so there may be something better out there but I really like it. I have been able to put all of my disparate systems under one roof. I have a ton of Insteon devices along with Nest, Haiku, Sonos, Harmony remote control, Unifi network and cameras and more that now work together. Now I can push an away button next to my door when I leave and all the lights will turn off, nest thermostat is switched to away mode and my TV system is turned off. In fact I don't have to push the away button; my current configuration detects when everybody is away and will automatically switch to away mode.

Home Assistant is written in Python and primarily uses YAML to configure your system. It is possible to write Python scripts to interact with Home Assistant or even add full custom components in Python. However most things can be done without any coding in Python. I have found the YAML configuration to be oddly inconsistent, and changing the configuration usually requires a reboot.

There is a IOS app that works very similar to the web page app and my wife has been able to use it. Wife Acceptance Factor is pretty high.

All this runs on a Raspberry Pi. Pretty handy!