TomFaulkner / SenseMe

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

Flask example: Leads to occasional 500 + Traceback #19

Closed TomFaulkner closed 6 years ago

TomFaulkner commented 6 years ago

When clicking Toggle Fan in the example Flask app there is a fairly high chance that the call to fan.speed may return 'OFF' rather than an integer for the speed. I haven't been able to replicate this outside of the flask app. Perhaps it is a function of how little time is between the .fan_toggle and .speed request.

Or, in thinking about this, it is more likely that because the library doesn't listen for responses to commands and then the .speed is catching the response.

For now there is exception handling in the .speed method.

[2018-03-06 20:32:40,496] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tom/Programming/Python/SenseMe/.venv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "flask_app.py", line 17, in index
    flask.flash(str((fan.speed, fan.brightness)))
  File "/home/tom/Programming/Python/SenseMe/senseme/senseme.py", line 100, in speed
    return int(speed)
ValueError: invalid literal for int() with base 10: 'OFF'
127.0.0.1 - - [06/Mar/2018 20:32:40] "GET / HTTP/1.1" 500 -