You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The VeSync Authentication Module provides a clean separation of authentication logic from the main VeSync class, offering improved maintainability, better error handling, and additional features like token persistence.
4
4
5
-
## Features
6
-
7
-
-**Flexible Authentication**: Support for both username/password and token-based authentication
8
-
-**Token Persistence**: Automatic saving and loading of authentication tokens to/from disk
9
-
-**Improved Error Handling**: More granular and descriptive error messages
10
-
-**Better Security**: Secure file permissions for token storage
11
-
-**Graceful Token Validation**: Automatic validation of existing tokens before use
12
-
-**Cross-Region Support**: Automatic handling of region changes during authentication
13
-
14
5
## Usage
15
6
7
+
Username and password must still be provided when instantiating the `VeSync` class, but a token can be loaded instead of logging in. If the loaded token is not valid, the `login()` method will be automatically called.
with VeSync(username="[email protected]", password="password") as manager:
17
+
# Login
18
+
success =await manager.login()
19
+
ifnot success:
20
+
print("Login failed!")
21
+
return
36
22
37
-
await manager.__aexit__()
23
+
print("Login successful!")
38
24
39
25
asyncio.run(main())
40
26
```
41
27
42
-
### Token-Based Authentication
28
+
### Loading authentication data
29
+
30
+
The authentication data can be provided to arguments of the `set_credentials()` or `load_credentials_from_file()` methods of the instantiated `VeSync` object.
31
+
32
+
The credentials needed are: `token`, `account_id`, `country_code`, and `region`.
43
33
44
34
```python
45
35
import asyncio
46
36
from pyvesync import VeSync
47
37
48
38
asyncdefmain():
49
-
# Use existing token (e.g., from previous login)
50
-
manager = VeSync(
51
-
token="your_existing_token",
52
-
account_id="your_account_id",
53
-
country_code="US"
54
-
)
55
-
56
-
# Login with token
57
-
success =await manager.login()
58
-
if success:
59
-
print("Token authentication successful!")
60
-
61
-
await manager.__aexit__()
39
+
with VeSync(username="[email protected]", password="password") as manager:
Credentials can be saved to a file or output as a json string. If no file path is provided the credentials will be saved to the users home directory as `.vesync_auth`.
58
+
59
+
The credentials file is a json file that has the keys `token`, `account_id`, `country_code`, and `region`.
This document outlines the steps to capture network packets for adding support for new devices in the `pyvesync` library. It is intended for developers who want to extend the library's functionality by integrating additional VeSync devices. Packet captures are required in order to add new devices and functionality.
4
+
5
+
The process outlined below is time consuming and can be difficult. An alternative method is to temporarily share the device. If you would prefer this method, please indicate in an issue or contact the maintainer directly. Sharing a device is done by going to the device settings and selecting "Share Device". Please create a post to notify the maintainers to receive the correct email address to share the device with.
6
+
7
+
Please do not post a device request without being will to either capture packets or share the device.
8
+
9
+
## Prerequisites
10
+
11
+
1.**Mumu Emulator**: Download and install the Mumu Android emulator from [Mumu Player](https://www.mumuplayer.com/). This emulator allows you to run Android apps on your computer. Other emulators may work, but Mumu is known to be compatible with Arm64 apk's and allows `adb root` access.
12
+
13
+
2.**VeSync App**: The latest VeSync app from apkpure or another apk sharing site.
14
+
15
+
3.**Charles Proxy**: Download and install Charles Proxy from [Charles](https://www.charlesproxy.com/). The 30
16
+
day trial is sufficient for this purpose. If you do like the software, support the developer by purchasing a license.
17
+
18
+
4.**ADB (Android Debug Bridge)**: Ensure you have ADB installed on your system. This is typically included with Android Studio, but can also be installed separately with Android Command Line Tools. This is the site for [Android Studio](https://developer.android.com/studio). Scroll to the "Command Line Tools Only" section to download just the command line tools. Once installed, ensure adb is in your system PATH. You may have to restart your terminal or IDE to pick up the PATH change. The following path is where the `adb` binary is located: `C:\Users\YOUR_USERNAME\AppData\Local\Android\Skd\platform-tools` on Windows or `/home/YOUR_USERNAME/Android/Sdk/platform-tools` on Linux.
19
+
20
+
5.**frida-server**: Download the latest frida-server from [frida-server](https://github.com/frida/frida/releases). Choose the release that matches the architecture of the MuMu emulator - `frida-server-x.x.x-android-x86_x64.xz`. Extract the `frida-server` binary and place it in the project directory.
21
+
22
+
23
+
## Steps
24
+
25
+
1.**Set up project directory**:
26
+
- Create a new directory for the project and place the extracted `frida-server` binary in it.
27
+
- Move the VeSync (x)apk to the project directory.
28
+
- Open a terminal in the project directory.
29
+
- Create a virtual environment and install frida:
30
+
31
+
```bash
32
+
python -m venv venv
33
+
source venv/bin/activate
34
+
# On Windows cmd use `venv\Scripts\activate`
35
+
# On powershell use `venv\Scripts\Activate.ps1`
36
+
pip install frida-tools
37
+
```
38
+
39
+
2. **Set up Charles Proxy**:
40
+
- Open Charles Proxy and go to `Proxy`>`Proxy Settings`. Note the HTTP Proxy port (default is 8888).
41
+
- Go to `Help`>`SSL Proxying`>`Save Root Certificate`>`cert format`.
42
+
- Save the certificate to the project directory as `cert-der.crt`.
43
+
44
+
3. **Set up MuMu Emulator**:
45
+
- Open the Mumu emulator and install the VeSync app by using the down arrow icon on the top right. Select "Install APK" from the bottom of the menu and choose the VeSync apk in the project directory.
46
+
- Configure the proxy in`System Applications`>`Settings`>`Network & Internet`>`Internet`> Gear icon next to the connected network. If charles is running on the same machine, set the proxy hostname to `localhost:8888` (or the port you noted earlier).
47
+
- Enable SSL Proxying in Charles by going to `Proxy`>`SSL Proxying Settings` and checking `Enable SSL Proxying`. Add a location with Host: `*` and Port: `*`if not already set.
48
+
49
+
4. **Configure MuMu to use Charles Proxy**:
50
+
- Once the MuMu emulator is running, open a new terminal in the project directory and run:
51
+
52
+
```bash
53
+
adb connect 127.0.0.1:7555
54
+
adb root
55
+
adb push cert-der.crt /data/local/tmp/
56
+
adb push frida-server /data/local/tmp/
57
+
adb shell
58
+
59
+
# This should bring up the android emulator command line
60
+
cd /data/local/tmp
61
+
chmod +x frida-server
62
+
./frida-server
63
+
```
64
+
65
+
- **LEAVE THIS TERMINAL OPEN**. There will be no output from the final command.
66
+
67
+
5. **Run the frida script**:
68
+
- With Mumu and the frida-server terminal running, open a separate terminal in the project directory, and ensure that the virtual environment is activated.
69
+
- Run the following command to start frida with the VeSync app:
- This will start the VeSync app and allow charles to capture the packets. You should see output in the terminal indicating that frida has attached to the process and the app will open in the emulator.
76
+
- Login to your VeSync account in the app and check that charles is able to capture and decode the packages. The url should start with `https://smartapi.vesync.com` or `https://smartapi.vesync.eu`. On occasion it may start with `https://smartapi.vesyncapi.com` or `https://smartapi.vesyncapi.eu`.
77
+
78
+
6. **Run actions in the VeSync app**:
79
+
- Perform all of the actions, including timers and schedulers. Ensure that after each action you go back to the device list and then back into the device. This ensures that the status of the device is captured after each action.
80
+
- If you have multiple devices, perform actions on each device.
81
+
82
+
7. **Save the Charles session**:
83
+
- Once all actions have been performed, stop the frida process by pressing `CTRL+C`in the frida terminal.
84
+
- In Charles, go to `File`>`Save Session As...` and save the session as `vesync_session.chls`in the project directory.
85
+
86
+
8. **Share the capture**:
87
+
- **DO NOT** post the capture in an issue. Please create an issue or comment on an issue to notify the maintainers that you have a capture ready to share.
88
+
- Files can be shared via discord or email to webdjoe at gmail.
0 commit comments