libnubiacare-py 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.
@@ -0,0 +1,220 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # uv
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs/Zensical documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
201
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
203
+ # could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michał Żarłok
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,117 @@
1
+ Metadata-Version: 2.5
2
+ Name: libnubiacare-py
3
+ Version: 0.1.0
4
+ Summary: Async client library for the Nubia Care API
5
+ Project-URL: Homepage, https://github.com/mishaaq/libnubiacare-py
6
+ Project-URL: Repository, https://github.com/mishaaq/libnubiacare-py
7
+ Project-URL: Issues, https://github.com/mishaaq/libnubiacare-py/issues
8
+ Author: Michał Żarłok
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Framework :: AsyncIO
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Home Automation
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: aiohttp>=3.9
25
+ Requires-Dist: cryptography>=42
26
+ Description-Content-Type: text/markdown
27
+
28
+ # libnubiacare-py
29
+
30
+ An asynchronous Python client for the Nubia Care API used by ZTE Kids watches.
31
+ The library handles request signing, password encryption, and the API's JSON
32
+ responses. It leaves the `aiohttp.ClientSession` and authenticated session data
33
+ under the caller's control, which makes it suitable for Home Assistant
34
+ integrations.
35
+
36
+ ## Installation
37
+
38
+ ```console
39
+ python -m pip install libnubiacare-py
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ```python
45
+ import asyncio
46
+
47
+ import aiohttp
48
+
49
+ from nubia_care import NubiaAPI, NubiaAuth
50
+
51
+
52
+ async def main() -> None:
53
+ async with aiohttp.ClientSession() as http_session:
54
+ auth = NubiaAuth(http_session)
55
+ credentials = await auth.async_login("account@example.com", "password")
56
+
57
+ api = NubiaAPI(auth)
58
+ devices = await api.async_get_devices(credentials)
59
+ for device in devices:
60
+ details = await api.async_get_device(credentials, device.id)
61
+ print(details.id, details.name)
62
+ if details.location is not None:
63
+ print(details.location.latitude, details.location.longitude)
64
+
65
+ firmware = await api.async_get_device_firmware(credentials, device.id)
66
+ print(firmware.device_firmware, firmware.firmware)
67
+
68
+ # Store credentials.to_dict() in the application's own config entry
69
+ # or credential store. The library does not retain login credentials.
70
+
71
+
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ `NubiaAuth` owns the built-in request signing and HTTP handling, while the
76
+ caller provides the shared `aiohttp.ClientSession` and keeps the returned
77
+ `NubiaSession` in their persistence layer. The API provides typed device and
78
+ location views while retaining each response in `raw_data`. Use
79
+ `NubiaDevice.id` as the identifier for device-details and firmware requests.
80
+ JSON decimal numbers are decoded as `Decimal`, so numeric latitude and
81
+ longitude values retain their reported precision; coordinate values returned
82
+ as strings remain strings.
83
+
84
+ The API host, mobile client description, and protocol keys can be supplied to
85
+ `NubiaAuth` for compatible service variants. See the class documentation and
86
+ type signatures for the supported options.
87
+
88
+ `NubiaDevice` exposes device capabilities through `device.features.supports()`
89
+ and `device.features.available_features()`. It also exposes parsed
90
+ `battery_level`, `device_type`, `permissions`, `model`, and `model_name`
91
+ properties; `battery_level` reads the `percent` value from the API's nested
92
+ `battery` object and is `None` when that value is unavailable. The original API
93
+ response remains available as `device.raw_data`.
94
+
95
+ ## CLI
96
+
97
+ The repository includes a simple verification script for checking access to the
98
+ Nubia Care API from a source checkout:
99
+
100
+ ```console
101
+ PYTHONPATH=src .venv/bin/python scripts/nubia_care_cli.py
102
+ ```
103
+
104
+ The script prompts for a Nubia Care login and password, then prints a JSON
105
+ summary for each related device, including the latest device metadata and
106
+ location information. It is intended for local validation and troubleshooting,
107
+ and it is not part of the installed library API.
108
+
109
+ ## Development
110
+
111
+ Run the test suite with:
112
+
113
+ ```console
114
+ PYTHONPATH=src .venv/bin/python -m unittest discover -s tests
115
+ ```
116
+
117
+ Releases are published to PyPI from GitHub Releases.
@@ -0,0 +1,90 @@
1
+ # libnubiacare-py
2
+
3
+ An asynchronous Python client for the Nubia Care API used by ZTE Kids watches.
4
+ The library handles request signing, password encryption, and the API's JSON
5
+ responses. It leaves the `aiohttp.ClientSession` and authenticated session data
6
+ under the caller's control, which makes it suitable for Home Assistant
7
+ integrations.
8
+
9
+ ## Installation
10
+
11
+ ```console
12
+ python -m pip install libnubiacare-py
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```python
18
+ import asyncio
19
+
20
+ import aiohttp
21
+
22
+ from nubia_care import NubiaAPI, NubiaAuth
23
+
24
+
25
+ async def main() -> None:
26
+ async with aiohttp.ClientSession() as http_session:
27
+ auth = NubiaAuth(http_session)
28
+ credentials = await auth.async_login("account@example.com", "password")
29
+
30
+ api = NubiaAPI(auth)
31
+ devices = await api.async_get_devices(credentials)
32
+ for device in devices:
33
+ details = await api.async_get_device(credentials, device.id)
34
+ print(details.id, details.name)
35
+ if details.location is not None:
36
+ print(details.location.latitude, details.location.longitude)
37
+
38
+ firmware = await api.async_get_device_firmware(credentials, device.id)
39
+ print(firmware.device_firmware, firmware.firmware)
40
+
41
+ # Store credentials.to_dict() in the application's own config entry
42
+ # or credential store. The library does not retain login credentials.
43
+
44
+
45
+ asyncio.run(main())
46
+ ```
47
+
48
+ `NubiaAuth` owns the built-in request signing and HTTP handling, while the
49
+ caller provides the shared `aiohttp.ClientSession` and keeps the returned
50
+ `NubiaSession` in their persistence layer. The API provides typed device and
51
+ location views while retaining each response in `raw_data`. Use
52
+ `NubiaDevice.id` as the identifier for device-details and firmware requests.
53
+ JSON decimal numbers are decoded as `Decimal`, so numeric latitude and
54
+ longitude values retain their reported precision; coordinate values returned
55
+ as strings remain strings.
56
+
57
+ The API host, mobile client description, and protocol keys can be supplied to
58
+ `NubiaAuth` for compatible service variants. See the class documentation and
59
+ type signatures for the supported options.
60
+
61
+ `NubiaDevice` exposes device capabilities through `device.features.supports()`
62
+ and `device.features.available_features()`. It also exposes parsed
63
+ `battery_level`, `device_type`, `permissions`, `model`, and `model_name`
64
+ properties; `battery_level` reads the `percent` value from the API's nested
65
+ `battery` object and is `None` when that value is unavailable. The original API
66
+ response remains available as `device.raw_data`.
67
+
68
+ ## CLI
69
+
70
+ The repository includes a simple verification script for checking access to the
71
+ Nubia Care API from a source checkout:
72
+
73
+ ```console
74
+ PYTHONPATH=src .venv/bin/python scripts/nubia_care_cli.py
75
+ ```
76
+
77
+ The script prompts for a Nubia Care login and password, then prints a JSON
78
+ summary for each related device, including the latest device metadata and
79
+ location information. It is intended for local validation and troubleshooting,
80
+ and it is not part of the installed library API.
81
+
82
+ ## Development
83
+
84
+ Run the test suite with:
85
+
86
+ ```console
87
+ PYTHONPATH=src .venv/bin/python -m unittest discover -s tests
88
+ ```
89
+
90
+ Releases are published to PyPI from GitHub Releases.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "libnubiacare-py"
7
+ version = "0.1.0"
8
+ description = "Async client library for the Nubia Care API"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Michał Żarłok" }]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Framework :: AsyncIO",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Home Automation",
27
+ ]
28
+ dependencies = [
29
+ "aiohttp>=3.9",
30
+ "cryptography>=42",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/mishaaq/libnubiacare-py"
35
+ Repository = "https://github.com/mishaaq/libnubiacare-py"
36
+ Issues = "https://github.com/mishaaq/libnubiacare-py/issues"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/nubia_care"]
40
+
41
+ [tool.hatch.build.targets.sdist]
42
+ include = [
43
+ "/src",
44
+ "/tests",
45
+ "/README.md",
46
+ "/LICENSE",
47
+ "/pyproject.toml",
48
+ ]
@@ -0,0 +1,35 @@
1
+ """Async client library for the Nubia Care API."""
2
+
3
+ from .api import NubiaAPI
4
+ from .auth import NubiaAuth
5
+ from .exceptions import (
6
+ NubiaApiError,
7
+ NubiaAuthenticationError,
8
+ NubiaConnectionError,
9
+ NubiaDeviceNotFoundError,
10
+ NubiaError,
11
+ NubiaProtocolError,
12
+ )
13
+ from .models import (
14
+ DeviceFeatures,
15
+ NubiaDevice,
16
+ NubiaFirmware,
17
+ NubiaLocation,
18
+ NubiaSession,
19
+ )
20
+
21
+ __all__ = [
22
+ "NubiaAPI",
23
+ "NubiaApiError",
24
+ "NubiaAuthenticationError",
25
+ "NubiaAuth",
26
+ "NubiaConnectionError",
27
+ "NubiaDevice",
28
+ "NubiaDeviceNotFoundError",
29
+ "NubiaError",
30
+ "NubiaFirmware",
31
+ "NubiaLocation",
32
+ "NubiaProtocolError",
33
+ "NubiaSession",
34
+ "DeviceFeatures",
35
+ ]
@@ -0,0 +1,89 @@
1
+ """Nubia Care API resources and endpoint methods."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+
7
+ from .auth import NubiaAuth
8
+ from .exceptions import NubiaApiError, NubiaDeviceNotFoundError, NubiaProtocolError
9
+ from .models import NubiaDevice, NubiaFirmware, NubiaSession
10
+
11
+
12
+ class NubiaAPI:
13
+ """Access Nubia Care resources using the authenticated request layer."""
14
+
15
+ def __init__(self, auth: NubiaAuth) -> None:
16
+ """Initialize the API resource facade with a NubiaAuth instance."""
17
+ self._auth = auth
18
+
19
+ async def async_get_devices(
20
+ self, session: NubiaSession
21
+ ) -> list[NubiaDevice]:
22
+ """Return the account's related devices."""
23
+ payload = await self._auth.async_request(
24
+ "GET",
25
+ f"getway/accounts/{session.openid}/related-device",
26
+ session=session,
27
+ )
28
+ data = payload.get("data", payload)
29
+ if not isinstance(data, Mapping):
30
+ raise NubiaProtocolError("related-device response is not an object")
31
+ devices: list[NubiaDevice] = []
32
+ entries = data.get("chatGroupDevices") or []
33
+ if not isinstance(entries, list):
34
+ raise NubiaProtocolError(
35
+ "related-device field chatGroupDevices is not a list"
36
+ )
37
+ for entry in entries:
38
+ if not isinstance(entry, Mapping):
39
+ raise NubiaProtocolError(
40
+ "related-device field chatGroupDevices contains invalid data"
41
+ )
42
+ if not isinstance(entry.get("imei"), str):
43
+ raise NubiaProtocolError(
44
+ "related-device entry in chatGroupDevices is missing imei"
45
+ )
46
+ devices.append(NubiaDevice(entry))
47
+ return devices
48
+
49
+ async def async_get_device(
50
+ self, session: NubiaSession, device_id: str
51
+ ) -> NubiaDevice:
52
+ """Return current details for one device by its API device ID."""
53
+ try:
54
+ payload = await self._auth.async_request(
55
+ "GET",
56
+ f"getway/devices/{device_id}",
57
+ session=session,
58
+ )
59
+ except NubiaApiError as err:
60
+ if err.status != 404:
61
+ raise
62
+ raise NubiaDeviceNotFoundError(
63
+ f"Nubia Care account has no device with ID {device_id!r}",
64
+ status=err.status,
65
+ ) from err
66
+ data = payload.get("data", payload)
67
+ if not isinstance(data, Mapping):
68
+ raise NubiaProtocolError("device detail response is not an object")
69
+ if not isinstance(data.get("imei"), str):
70
+ raise NubiaProtocolError("device detail response is missing imei")
71
+ return NubiaDevice(data)
72
+
73
+ async def async_get_device_firmware(
74
+ self, session: NubiaSession, device_id: str
75
+ ) -> NubiaFirmware:
76
+ """Return available and installed firmware versions for a device."""
77
+ payload = await self._auth.async_request(
78
+ "POST",
79
+ "api/device/upgrade",
80
+ auth_token=session.accesstoken,
81
+ json_body={
82
+ "deviceId": device_id,
83
+ "token": session.accesstoken,
84
+ },
85
+ )
86
+ data = payload.get("data")
87
+ if not isinstance(data, Mapping):
88
+ raise NubiaProtocolError("firmware response is missing its data object")
89
+ return NubiaFirmware(data)