2020-07-19 21:50:33 +02:00
|
|
|
# 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
|
2023-01-11 03:41:35 +01:00
|
|
|
import time
|
2020-07-19 21:50:33 +02:00
|
|
|
|
|
|
|
# JSON compatibility
|
|
|
|
null = None
|
|
|
|
true = True
|
|
|
|
false = False
|
|
|
|
|
|
|
|
def _info(msg):
|
2020-10-22 17:59:17 +02:00
|
|
|
json.dump({'t': 'info', 'msg': msg}, sys.stdout)
|
2020-07-19 21:50:33 +02:00
|
|
|
sys.stdout.write('\r\n')
|
|
|
|
|
2020-10-22 17:59:17 +02:00
|
|
|
|
2020-07-19 21:50:33 +02:00
|
|
|
def _error(msg):
|
2020-10-22 17:59:17 +02:00
|
|
|
json.dump({'t': 'error', 'msg': msg}, sys.stdout)
|
2020-07-19 21:50:33 +02:00
|
|
|
sys.stdout.write('\r\n')
|
|
|
|
|
2020-10-22 17:59:17 +02:00
|
|
|
|
2020-07-19 21:50:33 +02:00
|
|
|
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)
|
2020-10-27 18:10:56 +01:00
|
|
|
wasp.watch.vibrator.pulse(ms=wasp.system.notify_duration)
|
2020-07-19 21:50:33 +02:00
|
|
|
elif task == 'notify-':
|
|
|
|
wasp.system.unnotify(cmd['id'])
|
2020-10-22 17:59:17 +02:00
|
|
|
elif task == 'musicstate':
|
|
|
|
wasp.system.toggle_music(cmd)
|
|
|
|
elif task == 'musicinfo':
|
|
|
|
wasp.system.set_music_info(cmd)
|
2021-03-31 01:10:24 +02:00
|
|
|
elif task == 'weather':
|
|
|
|
wasp.system.set_weather_info(cmd)
|
2020-07-19 21:50:33 +02:00
|
|
|
else:
|
2020-08-15 21:37:52 +02:00
|
|
|
pass
|
|
|
|
#_info('Command "{}" is not implemented'.format(cmd))
|
2020-07-19 21:50:33 +02:00
|
|
|
except Exception as e:
|
|
|
|
msg = io.StringIO()
|
|
|
|
sys.print_exception(e, msg)
|
|
|
|
_error(msg.getvalue())
|
|
|
|
msg.close()
|
2023-01-11 03:41:35 +01:00
|
|
|
|
|
|
|
def send_cmd(cmd = ''):
|
|
|
|
print('\r')
|
2023-08-25 21:21:32 +02:00
|
|
|
for i in range(0, len(cmd), 20):
|
|
|
|
print(cmd[i: i + 20], end='')
|
|
|
|
time.sleep(0.2)
|
|
|
|
print(' ')
|
2023-01-11 03:41:35 +01:00
|
|
|
print(' ')
|