yarbo-data-sdk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: yarbo-data-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Yarbo robot devices
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: cryptography>=41.0
9
+ Requires-Dist: paho-mqtt>=2.0
10
+ Requires-Dist: requests>=2.28
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest-mock>=3.0; extra == 'dev'
13
+ Requires-Dist: pytest>=7.0; extra == 'dev'
14
+ Requires-Dist: responses>=0.23; extra == 'dev'
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Yarbo Data SDK
18
+
19
+ Python SDK for Yarbo robot devices. Enables integration with smart home platforms and custom applications.
20
+
21
+ ## Features
22
+
23
+ - **Authentication** — Login with email/password (RSA-encrypted), token refresh, session restore
24
+ - **Device Management** — Query device list via REST API
25
+ - **MQTT Real-time Data** — Subscribe to device messages and heart beats with automatic zlib decompression (firmware >= 3.9.0)
26
+ - **Device Control** — Publish commands via MQTT with automatic compression and debug logging
27
+ - **Request with Feedback** — Send commands and wait for device response via data_feedback topic
28
+ - **Device Registry** — JSON-driven device capability definitions with structured field and control metadata
29
+ - **Custom Extractors** — Extensible field extraction logic (network priority, volume scaling, RTK signal, planning/recharging status)
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install yarbo-data-sdk
35
+ ```
36
+
37
+ **Requirements**: Python >= 3.10
38
+
39
+ ## Quick Start
40
+
41
+ ```python
42
+ from yarbo_robot_sdk import YarboClient
43
+
44
+ client = YarboClient(api_base_url="https://api.yarbo.com")
45
+ client.login("user@email.com", "password")
46
+
47
+ devices = client.get_devices()
48
+ for device in devices:
49
+ print(f"{device.name} ({device.sn}) - Online: {device.online}")
50
+ ```
51
+
52
+ ## MQTT Real-time Updates
53
+
54
+ ```python
55
+ client.mqtt_connect()
56
+
57
+ # Subscribe to device status messages
58
+ def on_device_message(topic, data):
59
+ print(f"Status update: {data}")
60
+
61
+ client.subscribe_device_message("SN123", "yarbo_Y", on_device_message)
62
+
63
+ # Subscribe to heart beat
64
+ def on_heart_beat(topic, data):
65
+ print(f"Heart beat: {data}")
66
+
67
+ client.subscribe_heart_beat("SN123", "yarbo_Y", on_heart_beat)
68
+ ```
69
+
70
+ ## Device Control
71
+
72
+ ```python
73
+ # Set working state
74
+ client.mqtt_publish_command("SN123", "yarbo_Y", "set_working_state", {"state": 1, "source": "smart_home"})
75
+
76
+ # Sound control
77
+ client.mqtt_publish_command("SN123", "yarbo_Y", "set_sound_param", {"enable": True, "vol": 0.5, "mode": 0})
78
+
79
+ # Headlight control (all 7 light fields required)
80
+ client.mqtt_publish_command("SN123", "yarbo_Y", "light_ctrl", {
81
+ "body_left_r": 255, "body_right_r": 255, "led_head": 255,
82
+ "led_left_w": 255, "led_right_w": 255, "tail_left_r": 255, "tail_right_r": 255
83
+ })
84
+
85
+ # Start auto plan
86
+ client.mqtt_publish_command("SN123", "yarbo_Y", "start_plan", {"id": 123, "percent": 0})
87
+
88
+ # Pause / Resume / Stop plan
89
+ client.mqtt_publish_command("SN123", "yarbo_Y", "pause", {})
90
+ client.mqtt_publish_command("SN123", "yarbo_Y", "resume", {})
91
+ client.mqtt_publish_command("SN123", "yarbo_Y", "stop", {})
92
+
93
+ # Return to charge (disable wireless charging first)
94
+ client.mqtt_publish_command("SN123", "yarbo_Y", "wireless_charging_cmd", {"cmd": 0})
95
+ client.mqtt_publish_command("SN123", "yarbo_Y", "cmd_recharge", {"cmd": 2})
96
+ ```
97
+
98
+ ## Request with Feedback
99
+
100
+ Some commands return data via the `data_feedback` MQTT topic:
101
+
102
+ ```python
103
+ # Fetch full device status snapshot
104
+ device_msg = client.get_device_msg("SN123", "yarbo_Y", timeout=10.0)
105
+
106
+ # Fetch all auto plans
107
+ plans = client.read_all_plan("SN123", "yarbo_Y", timeout=10.0)
108
+
109
+ # Fetch GPS reference origin
110
+ gps_ref = client.read_gps_ref("SN123", "yarbo_Y", timeout=10.0)
111
+ ```
112
+
113
+ ## Device Registry
114
+
115
+ Access device field definitions programmatically:
116
+
117
+ ```python
118
+ from yarbo_robot_sdk import get_field_definitions, get_control_field_definitions
119
+
120
+ # Sensor/binary_sensor field definitions
121
+ fields = get_field_definitions("yarbo_Y")
122
+ for f in fields:
123
+ print(f"{f.path} -> {f.name} ({f.entity_type})")
124
+
125
+ # Control field definitions (select/switch/number)
126
+ controls = get_control_field_definitions("yarbo_Y")
127
+ for c in controls:
128
+ print(f"{c.path} -> {c.name} ({c.entity_type})")
129
+ ```
130
+
131
+ ### Supported Control Topics
132
+
133
+ | Topic | Description | Payload Example |
134
+ |-------|-------------|-----------------|
135
+ | set_working_state | Set working state | `{"state": 1, "source": "smart_home"}` |
136
+ | set_sound_param | Sound control | `{"enable": true, "vol": 0.5, "mode": 0}` |
137
+ | light_ctrl | Headlight control | `{"body_left_r": 255, ...}` (7 fields) |
138
+ | start_plan | Start auto plan | `{"id": 123, "percent": 0}` |
139
+ | pause | Pause plan | `{}` |
140
+ | resume | Resume plan | `{}` |
141
+ | stop | Stop plan | `{}` |
142
+ | cmd_recharge | Return to charge | `{"cmd": 2}` |
143
+ | wireless_charging_cmd | Wireless charging | `{"cmd": 0}` |
144
+ | read_all_plan | Request plans | `{}` (response via data_feedback) |
145
+ | get_device_msg | Request full status | `{}` (response via data_feedback) |
146
+ | read_gps_ref | Request GPS ref | `{}` (response via data_feedback) |
147
+ | get_map | Request map data | `{}` (response via data_feedback) |
148
+
149
+ ### Network Helper
150
+
151
+ ```python
152
+ from yarbo_robot_sdk import extract_active_network
153
+
154
+ # Determine active network from route_priority data
155
+ # Returns the interface with the lowest non-negative priority value
156
+ result = extract_active_network({"hg0": 10, "wlan0": 600, "wwan0": -1})
157
+ # result = "Halow" (hg0 has lowest priority value)
158
+ ```
159
+
160
+ ## Session Persistence
161
+
162
+ ```python
163
+ # Save tokens
164
+ saved_token = client.token
165
+ saved_refresh_token = client.refresh_token
166
+
167
+ # Restore in a new client (no re-login needed)
168
+ client2 = YarboClient(api_base_url="https://api.yarbo.com")
169
+ client2.restore_session(
170
+ username="user@email.com",
171
+ token=saved_token,
172
+ refresh_token=saved_refresh_token,
173
+ )
174
+ ```
175
+
176
+ ## Documentation
177
+
178
+ - [API Reference](docs/api.md) — All methods, parameters, and return types
179
+ - [MQTT Topics](docs/mqtt-topics.md) — Topic formats, payload structures, compression
180
+ - [Device Fields](docs/device-fields.md) — Complete field definitions for all device types
181
+
182
+ ## License
183
+
184
+ MIT
@@ -0,0 +1,18 @@
1
+ yarbo_robot_sdk/__init__.py,sha256=KpRXjaq6gm9EuDyquef8-b4rwIEpEwxLuPyZEpXQpno,814
2
+ yarbo_robot_sdk/auth.py,sha256=IQ_-TK7WINyx8JT0QMml1xkSm5hid8pjpOWvQYy1sVg,4563
3
+ yarbo_robot_sdk/client.py,sha256=RGB08NIGUZMwludNmS4IiMQ08LJEKzd8YKBJgbiKTBE,16301
4
+ yarbo_robot_sdk/codec.py,sha256=odW6vnUh3Lclzp0svlo5wY_jO6axj-N2KSlZNRgi5V8,2678
5
+ yarbo_robot_sdk/config.py,sha256=OGhdvYZEjFliRvDym3ZG-ZO_fEMh5q2DdqoeSLKgBP4,383
6
+ yarbo_robot_sdk/config_provider.py,sha256=ur3VfS_6W6Hhxb8VMiQHTxYe7Kin3tgXjJbajpTG9Jo,2539
7
+ yarbo_robot_sdk/device_helpers.py,sha256=fD5UCTtyi9956BFA6c9R06h9vcyTAmRlwxp-zM1dCo0,10047
8
+ yarbo_robot_sdk/device_registry.py,sha256=wSPeyj1tc82mfYo8u1-KxoWKSv6e5FbEETGReqx8zAU,9395
9
+ yarbo_robot_sdk/endpoints.py,sha256=0_kVOmmWH_J9hqBaKrM5mUNzcHRMXdc2dRvZXQ2cULU,164
10
+ yarbo_robot_sdk/exceptions.py,sha256=8eMKgWdhDR0sev4RhgZcMTamIGCyR5UESjSalDMQrOQ,633
11
+ yarbo_robot_sdk/models.py,sha256=vKHY5tHpeqXZRDHYH_3KUvqsl_CKuFFPOG-VOyFlQMM,3619
12
+ yarbo_robot_sdk/mqtt_client.py,sha256=ayYGsf6N-cmuQfaF5zZrlz0t7Ql0y4dry6INrX4HfqY,5765
13
+ yarbo_robot_sdk/rest_client.py,sha256=n5w4b8t9tcKi9ejNprymDobGNybjF-IbSF2F2Z4xkL0,2220
14
+ yarbo_robot_sdk/devices/yarbo_Y.json,sha256=91ytut2UHAod42HdjmTcuDvYcngo2E37zPLe3Uzdbps,10938
15
+ yarbo_data_sdk-0.1.0.dist-info/METADATA,sha256=AGdQhbtmxDnIgxwf6sxJ1EemKLkS4FB4QoHSSCDFOnk,5976
16
+ yarbo_data_sdk-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
17
+ yarbo_data_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=89cswvj-Zn7s_llS9OEkvKgTAOXDhJy65tJwqzV4ROs,1062
18
+ yarbo_data_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yarbo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,33 @@
1
+ """Yarbo Robot SDK - Python SDK for Yarbo robot devices."""
2
+
3
+ from yarbo_robot_sdk.client import YarboClient
4
+ from yarbo_robot_sdk.device_helpers import (
5
+ convert_local_to_gps,
6
+ convert_map_to_geojson,
7
+ extract_active_network,
8
+ extract_field,
9
+ )
10
+ from yarbo_robot_sdk.device_registry import (
11
+ get_control_field_definitions,
12
+ get_field_definitions,
13
+ )
14
+ from yarbo_robot_sdk.exceptions import (
15
+ AuthenticationError,
16
+ TokenExpiredError,
17
+ YarboSDKError,
18
+ )
19
+ from yarbo_robot_sdk.models import Device
20
+
21
+ __all__ = [
22
+ "YarboClient",
23
+ "YarboSDKError",
24
+ "AuthenticationError",
25
+ "TokenExpiredError",
26
+ "Device",
27
+ "get_field_definitions",
28
+ "get_control_field_definitions",
29
+ "extract_field",
30
+ "extract_active_network",
31
+ "convert_local_to_gps",
32
+ "convert_map_to_geojson",
33
+ ]
@@ -0,0 +1,121 @@
1
+ """Authentication manager — login, token refresh, RSA password encryption."""
2
+
3
+ import base64
4
+
5
+ import requests
6
+ from cryptography.hazmat.primitives import hashes, serialization
7
+ from cryptography.hazmat.primitives.asymmetric import padding
8
+
9
+ from yarbo_robot_sdk import endpoints
10
+ from yarbo_robot_sdk.config import REQUEST_TIMEOUT
11
+ from yarbo_robot_sdk.exceptions import (
12
+ AuthenticationError,
13
+ TokenExpiredError,
14
+ YarboSDKError,
15
+ )
16
+
17
+
18
+ class AuthManager:
19
+ """Manages authentication lifecycle: login, token storage, refresh."""
20
+
21
+ def __init__(self, api_base_url: str, rsa_public_key: str):
22
+ self._api_base_url = api_base_url
23
+ self._rsa_public_key = rsa_public_key
24
+ self._username: str | None = None
25
+ self._token: str | None = None
26
+ self._refresh_token: str | None = None
27
+
28
+ def login(self, username: str, password: str) -> None:
29
+ """Encrypt password with RSA and call the login endpoint."""
30
+ if not username:
31
+ raise AuthenticationError("Username must not be empty")
32
+ if not password:
33
+ raise AuthenticationError("Password must not be empty")
34
+
35
+ encrypted_password = self._encrypt_password(password)
36
+ try:
37
+ resp = requests.post(
38
+ f"{self._api_base_url}{endpoints.AUTH_LOGIN}",
39
+ json={"username": username, "password": encrypted_password},
40
+ timeout=REQUEST_TIMEOUT,
41
+ )
42
+ except requests.RequestException as exc:
43
+ raise YarboSDKError(f"Login request failed: {exc}") from exc
44
+
45
+ if resp.status_code == 401:
46
+ raise AuthenticationError("Invalid username or password")
47
+ if not resp.ok:
48
+ raise YarboSDKError(f"Login failed with status {resp.status_code}: {resp.text}")
49
+
50
+ data = resp.json()
51
+ payload = data.get("data", data) # Support {"code":0,"data":{...}} wrapper
52
+ self._username = username.lower()
53
+ self._token = payload.get("accessToken") or payload.get("token")
54
+ self._refresh_token = payload.get("refreshToken") or payload.get("refresh_token")
55
+
56
+ def refresh(self) -> None:
57
+ """Use refresh_token to obtain a new token."""
58
+ if not self._refresh_token:
59
+ raise TokenExpiredError("No refresh token available, please login again")
60
+
61
+ try:
62
+ resp = requests.post(
63
+ f"{self._api_base_url}{endpoints.AUTH_REFRESH}",
64
+ json={"refresh_token": self._refresh_token},
65
+ timeout=REQUEST_TIMEOUT,
66
+ )
67
+ except requests.RequestException as exc:
68
+ raise YarboSDKError(f"Token refresh request failed: {exc}") from exc
69
+
70
+ if resp.status_code == 401:
71
+ raise TokenExpiredError("Refresh token expired, please login again")
72
+ if not resp.ok:
73
+ raise YarboSDKError(f"Token refresh failed with status {resp.status_code}")
74
+
75
+ data = resp.json()
76
+ payload = data.get("data", data) # Support {"code":0,"data":{...}} wrapper
77
+ self._token = payload.get("accessToken") or payload.get("token")
78
+ new_refresh = payload.get("refreshToken") or payload.get("refresh_token")
79
+ if new_refresh:
80
+ self._refresh_token = new_refresh # Auth0 Refresh Token Rotation
81
+
82
+ def restore(self, username: str, token: str, refresh_token: str) -> None:
83
+ """Restore a previous session from saved tokens."""
84
+ self._username = username.lower()
85
+ self._token = token
86
+ self._refresh_token = refresh_token
87
+
88
+ @property
89
+ def username(self) -> str | None:
90
+ return self._username
91
+
92
+ @property
93
+ def token(self) -> str | None:
94
+ return self._token
95
+
96
+ @property
97
+ def refresh_token(self) -> str | None:
98
+ return self._refresh_token
99
+
100
+ @property
101
+ def is_authenticated(self) -> bool:
102
+ return self._token is not None
103
+
104
+ def _encrypt_password(self, password: str) -> str:
105
+ """Encrypt password using RSA-OAEP + SHA-256, return base64-encoded ciphertext."""
106
+ try:
107
+ public_key = serialization.load_pem_public_key(
108
+ self._rsa_public_key.encode()
109
+ )
110
+ except Exception as exc:
111
+ raise YarboSDKError(f"Invalid RSA public key: {exc}") from exc
112
+
113
+ ciphertext = public_key.encrypt(
114
+ password.encode(),
115
+ padding.OAEP(
116
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
117
+ algorithm=hashes.SHA256(),
118
+ label=None,
119
+ ),
120
+ )
121
+ return base64.b64encode(ciphertext).decode()