Tested Amazfit method, set it as default

This commit is contained in:
vanous 2021-02-21 15:12:47 +01:00
parent 2e1e6325e9
commit 0b56845b8f
4 changed files with 117 additions and 41 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ __pycache__/
*$py.class
cep_alm_pak.zip
cep_7days.zip
credentials.json
# C extensions
*.so

View File

@ -36,36 +36,67 @@ Either build apk as per above or get it from the [releases](https://codeberg.org
### Signing into account
This process is pretty unintuitive, so make sure to read this first! Only tested for Xiaomi login method.
This process for Xiaomi login is pretty unintuitive, so make sure to read this first!
1) Install the apk, run it and manually give it permission for storage (only needed if you plan to fetch aGPS).
<img src="screenshots/01a.jpg" width="300" alt="screenshot" />
<img src="screenshots/01b.jpg" width="300" alt="screenshot" />
2) Choose Xiaomi as login method (selected by default). Press `Get token` button.
## Amazfit
- Choose Xiaomi as login method.
- Fill in email and name fields. You can save them in the app by pressing the Save buttons.
### Key
- For key, press `Fetch key`. The key will appear in the `Found key` field, get it by pressing the Copy button.
Note: Only last key provided by the server is displayed.
<img src="screenshots/07.jpg" width="300" alt="screenshot" />
This key must be entered into Gadgetbridge during pairing process with devices that require it:
<img src="screenshots/12.jpeg" width="300" alt="screenshot" />
<img src="screenshots/13.jpeg" width="300" alt="screenshot" />
<img src="screenshots/14.jpeg" width="300" alt="screenshot" />
### aGPS
- For aGPS, press `Fetch aGPS` button. Files will be downloaded and the two important files (`cep_pak.bin` and `gps_alm.bin`) will be unzipped into `/storage/emulated/0`. You can send them into your device with the Gadgetbridge FW/App Installer
<img src="screenshots/08.jpg" width="300" alt="screenshot" />
<img src="screenshots/09.jpg" width="300" alt="screenshot" />
<img src="screenshots/10.jpg" width="300" alt="screenshot" />
<img src="screenshots/11.jpg" width="300" alt="screenshot" />
## Xiaomi
- Choose Xiaomi as login method. Press `Get token` button.
<img src="screenshots/01.jpg" width="300" alt="screenshot" />
3) This will open up your browser. Here you need to sing into your Xiaomi account.
- This will open up your browser. Here you need to sing into your Xiaomi account.
<img src="screenshots/02.jpg" width="300" alt="screenshot" />
4) Once you press Sign in, your browser will either warn you or this gets you to a blank page. In any case, the url starts with `hm.xiaomi.com/watch.do?...`. You must copy this URL:
- Once you press Sign in, your browser will either warn you or this gets you to a blank page. In any case, the url starts with `hm.xiaomi.com/watch.do?...`. You must copy this URL:
<img src="screenshots/03.jpg" width="300" alt="screenshot" />
<img src="screenshots/05.jpg" width="300" alt="screenshot" />
6) Go back to Huafetcher and paste the URL into the URL result field by using the Paste button.
- Go back to Huafetcher and paste the URL into the URL result field by using the Paste button.
<img src="screenshots/06.jpg" width="300" alt="screenshot" />
7) Now you can get a key or aGPS.
- Now you can get a key or aGPS.
### Key
8) For key, press `Fetch key`. The key will appear in the `Found key` field, get it by pressing the Copy button.
- For key, press `Fetch key`. The key will appear in the `Found key` field, get it by pressing the Copy button.
Note: Only last key provided by the server is displayed.
<img src="screenshots/07.jpg" width="300" alt="screenshot" />
This key must be entered into Gadgetbridge during pairing process with devices that require it
@ -74,9 +105,10 @@ This key must be entered into Gadgetbridge during pairing process with devices t
<img src="screenshots/13.jpeg" width="300" alt="screenshot" />
<img src="screenshots/14.jpeg" width="300" alt="screenshot" />
### aGPS
8) For aGPS, press `Fetch aGPS` button. Files will be downloaded and the two important files will be unzipped into `/storage/emulated/0`. You can send them into your device with the Gadgetbridge FW/App Installer
- For aGPS, press `Fetch aGPS` button. Files will be downloaded and the two important files (`cep_pak.bin` and `gps_alm.bin`) will be unzipped into `/storage/emulated/0`. You can send them into your device with the Gadgetbridge FW/App Installer
<img src="screenshots/08.jpg" width="300" alt="screenshot" />
<img src="screenshots/09.jpg" width="300" alt="screenshot" />

View File

@ -28,7 +28,7 @@ source.exclude_dirs = tests, bin, screenshots
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
version = 0.7
version = 0.10
# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]

99
main.py
View File

@ -113,8 +113,8 @@ class Main(App):
#dropdown_button.bind(on_press=lambda x: setattr(dropdown_button,'text','Select'))
dropdown.bind(on_select=lambda instance, x: setattr(dropdown_button, 'text', x))
get_token_button = MyButton(text='Get token')
get_token_button.bind(on_press=self.on_press_button_gettoken)
self.get_token_button = MyButton(text='Get token')
self.get_token_button.bind(on_press=self.on_press_button_gettoken)
self.fetch_key_button = MyButton(text='Fetch key')
self.fetch_key_button.bind(on_press=self.on_press_button_fetch_key)
@ -127,7 +127,7 @@ class Main(App):
share_agps_button = MyButton(text='Share aGPS')
share_agps_button.bind(on_press=self.on_press_button_share_agps)
buttons_layout.add_widget(get_token_button)
buttons_layout.add_widget(self.get_token_button)
#buttons_layout.add_widget(login_button)
buttons_layout.add_widget(self.fetch_key_button)
buttons_layout.add_widget(self.fetch_agps_button)
@ -155,7 +155,6 @@ class Main(App):
multiline=False,
)
self.credentials_email_input.bind(text=lambda instance,x: setattr(self.huamidevice,'email',x))
credentials_email_label.bind(on_press=self.on_press_paste_email)
email_paste_button=MyButton(text='Paste', size_hint=(.3, 1))
email_paste_button.bind(on_press=lambda instance: self.on_press_paste(self.credentials_email_input) )
@ -226,32 +225,46 @@ class Main(App):
self.on_press_load(self.credentials_email_input, 'email')
self.on_press_load(self.credentials_password_input, 'password')
self.set_login_method('xiaomi')
dropdown_button.text='Xiaomi'
#self.set_login_method('xiaomi')
#dropdown_button.text='Xiaomi'
self.set_login_method('amazfit')
dropdown_button.text='Amazfit'
return screen_layout
def hide_widget(self, wid, dohide=True):
debug_print(dohide)
if hasattr(wid, 'saved_attrs'):
debug_print(wid.saved_attrs)
if not dohide:
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = wid.saved_attrs
del wid.saved_attrs
elif dohide:
wid.saved_attrs = wid.height, wid.size_hint_y, wid.opacity, wid.disabled
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = 0, None, 0, True
def set_visibility(self, widget_id, hide=True):
debug_print(hide)
if hasattr(widget_id, 'saved_attrs'):
debug_print(widget_id.saved_attrs)
if not hide:
widget_id.height, widget_id.size_hint_y, widget_id.opacity, widget_id.disabled = widget_id.saved_attrs
del widget_id.saved_attrs
elif hide:
widget_id.saved_attrs = widget_id.height, widget_id.size_hint_y, widget_id.opacity, widget_id.disabled
widget_id.height, widget_id.size_hint_y, widget_id.opacity, widget_id.disabled = 0, None, 0, True
def set_login_method(self,method):
debug_print(method)
self.huamidevice.method=method
if method == 'xiaomi':
self.hide_widget(self.credentials_email_layout, dohide=True)
self.hide_widget(self.credentials_password_layout, dohide=True)
else:
self.hide_widget(self.credentials_email_layout, dohide=False)
self.hide_widget(self.credentials_password_layout, dohide=False)
self.instructions_label.text='Press "Get token", sign in, copy URL and paste here'
self.set_visibility(self.credentials_email_layout, hide=True)
self.set_visibility(self.credentials_password_layout, hide=True)
self.set_visibility(self.paste_token_input_layout, hide=False)
self.set_visibility(self.result_value_layout, hide=False)
self.get_token_button.disabled=False
self.fetch_agps_button.disabled=True
self.fetch_key_button.disabled=True
else: #amazfit
self.instructions_label.text='Email and password must be filled, then use Fetch key or Fetch aGPS'
self.set_visibility(self.credentials_email_layout, hide=False)
self.set_visibility(self.credentials_password_layout, hide=False)
self.set_visibility(self.paste_token_input_layout, hide=True)
#self.set_visibility(self.result_value_layout, hide=True)
self.get_token_button.disabled=True
self.fetch_agps_button.disabled=False
self.fetch_key_button.disabled=False
def set_token(self, instance, text):
debug_print("got", text)
@ -298,14 +311,17 @@ class Main(App):
self.paste_token_input_layout.disabled=False
return
else:
#login methiod amazfit
#login method amazfit
try:
res=self.huamidevice.get_access_token()
print("amazfit get access token result", res)
if res:
if self.huamidevice.user_id is not None:
self.instructions_label.text="Signed in as: {}, getting data".format(self.huamidevice.user_id)
else:
self.instructions_label.text="You must sign in first"
#if self.huamidevice.user_id is not None:
# self.instructions_label.text="Signed in as: {}, getting data".format(self.huamidevice.user_id)
#else:
# self.instructions_label.text="You must sign in first"
self.fetch_key_button.disabled=False
self.fetch_agps_button.disabled=False
except Exception as e:
debug_print(e)
@ -313,10 +329,21 @@ class Main(App):
def on_press_button_fetch_key(self, instance):
debug_print('You pressed the button fetch!')
if self.huamidevice.method=='amazfit':
res=False
try:
res=self.huamidevice.get_access_token()
except Exception as e:
debug_print(e)
self.instructions_label.text=f"{e}"
if not res:
self.instructions_label.text="amazfit login failed"
self.result_value_value.text=''
self.paste_token_input.text=''
self.result_value_layout.disabled=True
self.paste_token_input_layout.disabled=True
if self.huamidevice.method!='amazfit':
self.fetch_key_button.disabled=True
self.fetch_agps_button.disabled=True
debug_print(self.huamidevice)
@ -336,12 +363,17 @@ class Main(App):
device_keys = self.huamidevice.get_wearable_auth_keys()
self.result_value_layout.disabled=False
self.instructions_label.text="Got the key, use the Copy button"
self.result_value_value.text=""
key=""
for device_key in device_keys:
debug_print(f"{device_key} {device_keys[device_key]}")
key=f"{device_key} {device_keys[device_key]}"
self.result_value_value.text=f"{device_keys[device_key]}"
if key=="":
self.instructions_label.text="No keys on the server"
else:
self.instructions_label.text="Got the key, use the Copy button"
self.result_value_value.text=f"{key}"
#Clock.schedule_once(partial(self.doit), 1)
@ -373,10 +405,21 @@ class Main(App):
def on_press_button_agps(self, instance):
debug_print('You pressed the button agps!')
if self.huamidevice.method=='amazfit':
res=False
try:
res=self.huamidevice.get_access_token()
except Exception as e:
debug_print(e)
self.instructions_label.text=f"{e}"
if not res:
self.instructions_label.text="amazfit login failed"
self.result_value_value.text=''
self.paste_token_input.text=''
self.result_value_layout.disabled=True
self.paste_token_input_layout.disabled=True
if self.huamidevice.method!='amazfit':
self.fetch_key_button.disabled=True
self.fetch_agps_button.disabled=True
debug_print(self.huamidevice)