yarbo-data-sdk 0.1.0__tar.gz

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.
Files changed (33) hide show
  1. yarbo_data_sdk-0.1.0/.github/workflows/publish-pypi.yml +76 -0
  2. yarbo_data_sdk-0.1.0/LICENSE +21 -0
  3. yarbo_data_sdk-0.1.0/PKG-INFO +184 -0
  4. yarbo_data_sdk-0.1.0/README.md +168 -0
  5. yarbo_data_sdk-0.1.0/docs/api.md +412 -0
  6. yarbo_data_sdk-0.1.0/docs/device-fields.md +128 -0
  7. yarbo_data_sdk-0.1.0/docs/mqtt-topics.md +366 -0
  8. yarbo_data_sdk-0.1.0/pyproject.toml +26 -0
  9. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/__init__.py +33 -0
  10. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/auth.py +121 -0
  11. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/client.py +457 -0
  12. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/codec.py +83 -0
  13. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/config.py +16 -0
  14. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/config_provider.py +72 -0
  15. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/device_helpers.py +311 -0
  16. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/device_registry.py +309 -0
  17. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/devices/yarbo_Y.json +364 -0
  18. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/endpoints.py +8 -0
  19. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/exceptions.py +25 -0
  20. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/models.py +92 -0
  21. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/mqtt_client.py +170 -0
  22. yarbo_data_sdk-0.1.0/src/yarbo_robot_sdk/rest_client.py +59 -0
  23. yarbo_data_sdk-0.1.0/tests/__init__.py +0 -0
  24. yarbo_data_sdk-0.1.0/tests/conftest.py +69 -0
  25. yarbo_data_sdk-0.1.0/tests/test_auth.py +176 -0
  26. yarbo_data_sdk-0.1.0/tests/test_client.py +267 -0
  27. yarbo_data_sdk-0.1.0/tests/test_codec.py +112 -0
  28. yarbo_data_sdk-0.1.0/tests/test_config_provider.py +92 -0
  29. yarbo_data_sdk-0.1.0/tests/test_device_helpers.py +270 -0
  30. yarbo_data_sdk-0.1.0/tests/test_device_registry.py +451 -0
  31. yarbo_data_sdk-0.1.0/tests/test_ha_entity_logic.py +171 -0
  32. yarbo_data_sdk-0.1.0/tests/test_mqtt_client.py +192 -0
  33. yarbo_data_sdk-0.1.0/tests/test_rest_client.py +96 -0
@@ -0,0 +1,76 @@
1
+ # Publish yarbo-data-sdk to PyPI / TestPyPI using Trusted Publisher (OIDC).
2
+ #
3
+ # Tag format determines the target:
4
+ # v0.1.0 → publish to PyPI (production)
5
+ # v0.1.0-test → publish to TestPyPI (testing)
6
+
7
+ name: Publish to PyPI
8
+
9
+ on:
10
+ push:
11
+ tags:
12
+ - "v[0-9]+.[0-9]+.[0-9]+"
13
+ - "v[0-9]+.[0-9]+.[0-9]+-test"
14
+
15
+ jobs:
16
+ build:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+
25
+ - name: Verify tag matches package version
26
+ run: |
27
+ # Strip 'v' prefix and '-test' suffix to get version
28
+ TAG_VERSION=$(echo "${GITHUB_REF_NAME}" | sed 's/^v//' | sed 's/-test$//')
29
+ TOML_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
30
+ if [ "$TAG_VERSION" != "$TOML_VERSION" ]; then
31
+ echo "::error::Version mismatch — tag=$TAG_VERSION, pyproject.toml=$TOML_VERSION"
32
+ exit 1
33
+ fi
34
+ echo "Version verified: $TAG_VERSION"
35
+
36
+ - name: Build package
37
+ run: |
38
+ pip install build
39
+ python -m build
40
+
41
+ - uses: actions/upload-artifact@v4
42
+ with:
43
+ name: dist
44
+ path: dist/
45
+
46
+ publish-pypi:
47
+ if: ${{ !endsWith(github.ref_name, '-test') }}
48
+ needs: build
49
+ runs-on: ubuntu-latest
50
+ environment: pypi
51
+ permissions:
52
+ id-token: write
53
+ steps:
54
+ - uses: actions/download-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
58
+
59
+ - uses: pypa/gh-action-pypi-publish@release/v1
60
+
61
+ publish-testpypi:
62
+ if: ${{ endsWith(github.ref_name, '-test') }}
63
+ needs: build
64
+ runs-on: ubuntu-latest
65
+ environment: testpypi
66
+ permissions:
67
+ id-token: write
68
+ steps:
69
+ - uses: actions/download-artifact@v4
70
+ with:
71
+ name: dist
72
+ path: dist/
73
+
74
+ - uses: pypa/gh-action-pypi-publish@release/v1
75
+ with:
76
+ repository-url: https://test.pypi.org/legacy/
@@ -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,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,168 @@
1
+ # Yarbo Data SDK
2
+
3
+ Python SDK for Yarbo robot devices. Enables integration with smart home platforms and custom applications.
4
+
5
+ ## Features
6
+
7
+ - **Authentication** — Login with email/password (RSA-encrypted), token refresh, session restore
8
+ - **Device Management** — Query device list via REST API
9
+ - **MQTT Real-time Data** — Subscribe to device messages and heart beats with automatic zlib decompression (firmware >= 3.9.0)
10
+ - **Device Control** — Publish commands via MQTT with automatic compression and debug logging
11
+ - **Request with Feedback** — Send commands and wait for device response via data_feedback topic
12
+ - **Device Registry** — JSON-driven device capability definitions with structured field and control metadata
13
+ - **Custom Extractors** — Extensible field extraction logic (network priority, volume scaling, RTK signal, planning/recharging status)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install yarbo-data-sdk
19
+ ```
20
+
21
+ **Requirements**: Python >= 3.10
22
+
23
+ ## Quick Start
24
+
25
+ ```python
26
+ from yarbo_robot_sdk import YarboClient
27
+
28
+ client = YarboClient(api_base_url="https://api.yarbo.com")
29
+ client.login("user@email.com", "password")
30
+
31
+ devices = client.get_devices()
32
+ for device in devices:
33
+ print(f"{device.name} ({device.sn}) - Online: {device.online}")
34
+ ```
35
+
36
+ ## MQTT Real-time Updates
37
+
38
+ ```python
39
+ client.mqtt_connect()
40
+
41
+ # Subscribe to device status messages
42
+ def on_device_message(topic, data):
43
+ print(f"Status update: {data}")
44
+
45
+ client.subscribe_device_message("SN123", "yarbo_Y", on_device_message)
46
+
47
+ # Subscribe to heart beat
48
+ def on_heart_beat(topic, data):
49
+ print(f"Heart beat: {data}")
50
+
51
+ client.subscribe_heart_beat("SN123", "yarbo_Y", on_heart_beat)
52
+ ```
53
+
54
+ ## Device Control
55
+
56
+ ```python
57
+ # Set working state
58
+ client.mqtt_publish_command("SN123", "yarbo_Y", "set_working_state", {"state": 1, "source": "smart_home"})
59
+
60
+ # Sound control
61
+ client.mqtt_publish_command("SN123", "yarbo_Y", "set_sound_param", {"enable": True, "vol": 0.5, "mode": 0})
62
+
63
+ # Headlight control (all 7 light fields required)
64
+ client.mqtt_publish_command("SN123", "yarbo_Y", "light_ctrl", {
65
+ "body_left_r": 255, "body_right_r": 255, "led_head": 255,
66
+ "led_left_w": 255, "led_right_w": 255, "tail_left_r": 255, "tail_right_r": 255
67
+ })
68
+
69
+ # Start auto plan
70
+ client.mqtt_publish_command("SN123", "yarbo_Y", "start_plan", {"id": 123, "percent": 0})
71
+
72
+ # Pause / Resume / Stop plan
73
+ client.mqtt_publish_command("SN123", "yarbo_Y", "pause", {})
74
+ client.mqtt_publish_command("SN123", "yarbo_Y", "resume", {})
75
+ client.mqtt_publish_command("SN123", "yarbo_Y", "stop", {})
76
+
77
+ # Return to charge (disable wireless charging first)
78
+ client.mqtt_publish_command("SN123", "yarbo_Y", "wireless_charging_cmd", {"cmd": 0})
79
+ client.mqtt_publish_command("SN123", "yarbo_Y", "cmd_recharge", {"cmd": 2})
80
+ ```
81
+
82
+ ## Request with Feedback
83
+
84
+ Some commands return data via the `data_feedback` MQTT topic:
85
+
86
+ ```python
87
+ # Fetch full device status snapshot
88
+ device_msg = client.get_device_msg("SN123", "yarbo_Y", timeout=10.0)
89
+
90
+ # Fetch all auto plans
91
+ plans = client.read_all_plan("SN123", "yarbo_Y", timeout=10.0)
92
+
93
+ # Fetch GPS reference origin
94
+ gps_ref = client.read_gps_ref("SN123", "yarbo_Y", timeout=10.0)
95
+ ```
96
+
97
+ ## Device Registry
98
+
99
+ Access device field definitions programmatically:
100
+
101
+ ```python
102
+ from yarbo_robot_sdk import get_field_definitions, get_control_field_definitions
103
+
104
+ # Sensor/binary_sensor field definitions
105
+ fields = get_field_definitions("yarbo_Y")
106
+ for f in fields:
107
+ print(f"{f.path} -> {f.name} ({f.entity_type})")
108
+
109
+ # Control field definitions (select/switch/number)
110
+ controls = get_control_field_definitions("yarbo_Y")
111
+ for c in controls:
112
+ print(f"{c.path} -> {c.name} ({c.entity_type})")
113
+ ```
114
+
115
+ ### Supported Control Topics
116
+
117
+ | Topic | Description | Payload Example |
118
+ |-------|-------------|-----------------|
119
+ | set_working_state | Set working state | `{"state": 1, "source": "smart_home"}` |
120
+ | set_sound_param | Sound control | `{"enable": true, "vol": 0.5, "mode": 0}` |
121
+ | light_ctrl | Headlight control | `{"body_left_r": 255, ...}` (7 fields) |
122
+ | start_plan | Start auto plan | `{"id": 123, "percent": 0}` |
123
+ | pause | Pause plan | `{}` |
124
+ | resume | Resume plan | `{}` |
125
+ | stop | Stop plan | `{}` |
126
+ | cmd_recharge | Return to charge | `{"cmd": 2}` |
127
+ | wireless_charging_cmd | Wireless charging | `{"cmd": 0}` |
128
+ | read_all_plan | Request plans | `{}` (response via data_feedback) |
129
+ | get_device_msg | Request full status | `{}` (response via data_feedback) |
130
+ | read_gps_ref | Request GPS ref | `{}` (response via data_feedback) |
131
+ | get_map | Request map data | `{}` (response via data_feedback) |
132
+
133
+ ### Network Helper
134
+
135
+ ```python
136
+ from yarbo_robot_sdk import extract_active_network
137
+
138
+ # Determine active network from route_priority data
139
+ # Returns the interface with the lowest non-negative priority value
140
+ result = extract_active_network({"hg0": 10, "wlan0": 600, "wwan0": -1})
141
+ # result = "Halow" (hg0 has lowest priority value)
142
+ ```
143
+
144
+ ## Session Persistence
145
+
146
+ ```python
147
+ # Save tokens
148
+ saved_token = client.token
149
+ saved_refresh_token = client.refresh_token
150
+
151
+ # Restore in a new client (no re-login needed)
152
+ client2 = YarboClient(api_base_url="https://api.yarbo.com")
153
+ client2.restore_session(
154
+ username="user@email.com",
155
+ token=saved_token,
156
+ refresh_token=saved_refresh_token,
157
+ )
158
+ ```
159
+
160
+ ## Documentation
161
+
162
+ - [API Reference](docs/api.md) — All methods, parameters, and return types
163
+ - [MQTT Topics](docs/mqtt-topics.md) — Topic formats, payload structures, compression
164
+ - [Device Fields](docs/device-fields.md) — Complete field definitions for all device types
165
+
166
+ ## License
167
+
168
+ MIT