andrewshilliday / garage-door-controller

Software to monitor and control garage doors via a raspberry pi
MIT License
327 stars 132 forks source link

New error on open event #36

Closed kubodhi closed 7 years ago

kubodhi commented 7 years ago

This just started happening this past week, with no changes made to my configuration that I'm aware of. When the service is first launched, everything looks good. The first open event is registered and that's when this error appears. The app continues to run, but subsequent close events are not reported in the status (i.e. door status will always say "open" until the application is restarted).

$ python controller.py 
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1192, in run
    self.mainLoop()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1201, in mainLoop
    self.runUntilCurrent()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 824, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/task.py", line 218, in __call__
    d = defer.maybeDeferred(self.f, *self.a, **self.kw)
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 139, in maybeDeferred
    result = f(*args, **kw)
  File "controller.py", line 127, in status_check
    self.send_pushbullet(door, title, message)
  File "controller.py", line 173, in send_pushbullet
    door.pb_iden = json.loads(conn.getresponse().read())['iden']
exceptions.KeyError: 'iden'

Any thoughts?

kubodhi commented 7 years ago

Just to clarify, it's been working perfectly for the past month or two - absolutely love it! :)

This error just started up within the past week, when I was actually out of state on vacation (but luckily could SSH in and restart the service).

kubodhi commented 7 years ago

A little more info-

It appears to be the pushbullet implementation, as when I switched to smtp the errors stopped and it's at least running where I can operate the doors now. Sad to be missing the notifications, though. I'll keep poking at it.

kubodhi commented 7 years ago

The response I'm getting back from pushbullet on the initial push doesn't have an 'iden' key, so the logic for setting door.pb_iden is breaking. I've commented out that declaration as well as the push deletion bits (since it relies on the door.pb_iden not being blank) and just have it sending pushes without worrying about cleaning up after itself - and it's working now. Not quite as clean as when I first started using it, but I can't find what changed so this is better than nothing. If anyone has any ideas, I'm all ears. :)

def send_pushbullet(self, door, title, message):
    syslog.syslog("Sending pushbutton message")
    config = self.config['alerts']['pushbullet']

    #if door.pb_iden != None:
    #    conn = httplib.HTTPSConnection("api.pushbullet.com:443")
    #    conn.request("DELETE", '/v2/pushes/' + door.pb_iden, "",
    #                 {'Authorization': 'Bearer ' + config['access_token'], 'Content-Type': 'application/json'})
    #    conn.getresponse()
    #    door.pb_iden = None

    conn = httplib.HTTPSConnection("api.pushbullet.com:443")
    conn.request("POST", "/v2/pushes",
         json.dumps({
             "type": "note",
             "title": title,
             "body": message,
             "channel_tag": "kubo-garagedoor",
         }), {'Authorization': 'Bearer ' + config['access_token'], 'Content-Type': 'application/json'})
    #door.pb_iden = json.loads(conn.getresponse().read())['iden']
kubodhi commented 7 years ago

Closing this. I made some changes on my end that may have caused it.