summaryrefslogtreecommitdiff
path: root/wasp/gadgetbridge.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-07-19 19:50:33 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-07-19 19:50:33 (GMT)
commita01fb7df573e13a6f6b9fbf2e7688d4e9713df6d (patch)
tree5118831a0fa174681ade9aaf850b7613309a2803 /wasp/gadgetbridge.py
parent6686f17e724b9a22318ff2248ce126a97dd19db4 (diff)
Introduction basic notification support
This requires a modified version of Gadgetbridge and currently works by implementing the BangleJS protocol. In Gadgetbridge ensure "Sync time" is *not* set and choose "Don't pair" when adding the PineTime device.
Diffstat (limited to 'wasp/gadgetbridge.py')
-rw-r--r--wasp/gadgetbridge.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/wasp/gadgetbridge.py b/wasp/gadgetbridge.py
new file mode 100644
index 0000000..f1219dd
--- /dev/null
+++ b/wasp/gadgetbridge.py
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: LGPL-3.0-or-later
+# Copyright (C) 2020 Daniel Thompson
+"""Gadgetbridge/Bangle.js protocol
+
+Currently implemented messages are:
+
+ * t:"notify", id:int, src,title,subject,body,sender,tel:string - new
+ notification
+ * t:"notify-", id:int - delete notification
+ * t:"alarm", d:[{h,m},...] - set alarms
+ * t:"find", n:bool - findDevice
+ * t:"vibrate", n:int - vibrate
+ * t:"weather", temp,hum,txt,wind,loc - weather report
+ * t:"musicstate", state:"play/pause",position,shuffle,repeat - music
+ play/pause/etc
+ * t:"musicinfo", artist,album,track,dur,c(track count),n(track num) -
+ currently playing music track
+ * t:"call", cmd:"accept/incoming/outgoing/reject/start/end", name: "name", number: "+491234" - call
+"""
+
+import io
+import json
+import sys
+import wasp
+
+# JSON compatibility
+null = None
+true = True
+false = False
+
+def _info(msg):
+ json.dump({'t':'info', 'msg':msg}, sys.stdout)
+ sys.stdout.write('\r\n')
+
+def _error(msg):
+ json.dump({'t':'error', 'msg':msg}, sys.stdout)
+ sys.stdout.write('\r\n')
+
+def GB(cmd):
+ task = cmd['t']
+ del cmd['t']
+
+ try:
+ if task == 'find':
+ wasp.watch.vibrator.pin(not cmd['n'])
+ elif task == 'notify':
+ id = cmd['id']
+ del cmd['id']
+ wasp.system.notify(id, cmd)
+ elif task == 'notify-':
+ wasp.system.unnotify(cmd['id'])
+ else:
+ _info('Command "{}" is not implemented'.format(cmd))
+ except Exception as e:
+ msg = io.StringIO()
+ sys.print_exception(e, msg)
+ _error(msg.getvalue())
+ msg.close()
+
+