Skip to content

Commit

Permalink
Added error handlig when LightBluePebbleError and PebbleError related #…
Browse files Browse the repository at this point in the history
…17

Signed-off-by: Gulsah Kose <[email protected]>
  • Loading branch information
GulsahKose committed Jan 13, 2015
1 parent 3fd45fe commit 11ad32d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions libpebble/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
import pexpect
import i18n
import platform
import tkMessageBox

from Tkinter import *

_ = i18n.language.gettext

window = Tk()
window.wm_withdraw()
window.geometry("1x1+200+200") #remember its .geometry("WidthxHeight(+or-)X(+or-)Y")

MAX_ATTEMPTS = 5
LightBluePebbleError = libpebble.LightBluePebble.LightBluePebbleError
PebbleError = libpebble.pebble.PebbleError

def cmd_remote_linux(pebble, args):

Expand Down Expand Up @@ -82,6 +91,14 @@ def music_control_handler(endpoint, resp):
try:
pebble.register_endpoint("MUSIC_CONTROL", music_control_handler)
time.sleep(5)
except LightBluePebbleError as e:
print "Not discovered 7"
raise e
raise KeyboardInterrupt
except PebbleError as p:
print "Not discovered 8"
raise p
raise KeyboardInterrupt
except KeyboardInterrupt:
return

Expand Down Expand Up @@ -128,6 +145,14 @@ def music_control_handler(endpoint, resp):
try:
pebble.register_endpoint("MUSIC_CONTROL", music_control_handler)
time.sleep(5)
except LightBluePebbleError as e:
print "Not discovered 0"
raise e
raise KeyboardInterrupt
except PebbleError as e:
print "Not discovered 1"
raise e
raise KeyboardInterrupt
except KeyboardInterrupt:
return

Expand Down Expand Up @@ -167,12 +192,27 @@ def main():
pebble_id = os.environ["PEBBLE_ID"]
pebble = libpebble.Pebble(pebble_id, args.lightblue, args.pair)
break
except LightBluePebbleError as e:
tkMessageBox.showerror(title="Error", message="Connection fault. Be sure to disconnect bluetooth between your watch and your phone. Please try agan.", parent=window)
raise KeyboardInterrupt
except PebbleError as e:
print "Not discovered 3"
raise e
raise KeyboardInterrupt
except:
time.sleep(5)
attempts += 1

try:
args.func(pebble, args)
except LightBluePebbleError as e:
print "Not discovered 4"
raise e
raise KeyboardInterrupt
except PebbleError as e:
print "Not discovered 5"
raise e
raise KeyboardInterrupt
except Exception as e:
pebble.disconnect()
raise e
Expand Down
2 changes: 1 addition & 1 deletion libpebble/pebble/LightBluePebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __str__(self):
class LightBluePebble(object):
""" a wrapper for LightBlue that provides Serial-style read, write and close"""

def __init__(self, id, should_pair, debug_protocol=False, connection_process_timeout=60):
def __init__(self, id, should_pair, debug_protocol=False, connection_process_timeout=5):

self.mac_address = id
self.debug_protocol = debug_protocol
Expand Down

0 comments on commit 11ad32d

Please sign in to comment.