velasmart 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.
- velasmart-0.1.0/LICENSE +21 -0
- velasmart-0.1.0/PKG-INFO +53 -0
- velasmart-0.1.0/README.md +33 -0
- velasmart-0.1.0/pyproject.toml +28 -0
- velasmart-0.1.0/setup.cfg +4 -0
- velasmart-0.1.0/tests/test_client.py +65 -0
- velasmart-0.1.0/velasmart/__init__.py +12 -0
- velasmart-0.1.0/velasmart/client.py +139 -0
- velasmart-0.1.0/velasmart/const.py +11 -0
- velasmart-0.1.0/velasmart.egg-info/PKG-INFO +53 -0
- velasmart-0.1.0/velasmart.egg-info/SOURCES.txt +12 -0
- velasmart-0.1.0/velasmart.egg-info/dependency_links.txt +1 -0
- velasmart-0.1.0/velasmart.egg-info/requires.txt +1 -0
- velasmart-0.1.0/velasmart.egg-info/top_level.txt +1 -0
velasmart-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VelaSmart
|
|
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.
|
velasmart-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: velasmart
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Asyncio client for the VelaSmart cloud API
|
|
5
|
+
Author: VelaSmart
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/liulijun2019/velasmart
|
|
8
|
+
Project-URL: Repository, https://github.com/liulijun2019/velasmart
|
|
9
|
+
Keywords: velasmart,curtain,homeassistant
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: aiohttp>=3.8
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# velasmart
|
|
22
|
+
|
|
23
|
+
Asyncio client for the VelaSmart cloud API. Used by the VelaSmart Home Assistant
|
|
24
|
+
integration.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install velasmart
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import asyncio
|
|
36
|
+
|
|
37
|
+
from velasmart import VelaSmartApiClient
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def main():
|
|
41
|
+
client = VelaSmartApiClient("username", "password")
|
|
42
|
+
await client.authenticate()
|
|
43
|
+
devices = await client.get_devices()
|
|
44
|
+
for device in devices:
|
|
45
|
+
print(device["id"], device["name"])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
asyncio.run(main())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# velasmart
|
|
2
|
+
|
|
3
|
+
Asyncio client for the VelaSmart cloud API. Used by the VelaSmart Home Assistant
|
|
4
|
+
integration.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install velasmart
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
import asyncio
|
|
16
|
+
|
|
17
|
+
from velasmart import VelaSmartApiClient
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def main():
|
|
21
|
+
client = VelaSmartApiClient("username", "password")
|
|
22
|
+
await client.authenticate()
|
|
23
|
+
devices = await client.get_devices()
|
|
24
|
+
for device in devices:
|
|
25
|
+
print(device["id"], device["name"])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
asyncio.run(main())
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "velasmart"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Asyncio client for the VelaSmart cloud API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "VelaSmart" }]
|
|
13
|
+
keywords = ["velasmart", "curtain", "homeassistant"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
]
|
|
21
|
+
dependencies = ["aiohttp>=3.8"]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/liulijun2019/velasmart"
|
|
25
|
+
Repository = "https://github.com/liulijun2019/velasmart"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
include = ["velasmart*"]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Tests for the VelaSmart cloud API client."""
|
|
2
|
+
|
|
3
|
+
from velasmart import VelaSmartApiClient, VelaSmartApiError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_parse_devices() -> None:
|
|
7
|
+
"""Test parsing the nested device list response."""
|
|
8
|
+
result = {
|
|
9
|
+
"code": 200,
|
|
10
|
+
"data": {
|
|
11
|
+
"list": [
|
|
12
|
+
{
|
|
13
|
+
"list": [
|
|
14
|
+
{
|
|
15
|
+
"deviceId": "5c1c0a6612",
|
|
16
|
+
"deviceName": "BidRoller",
|
|
17
|
+
"gatewayMac": "e08cfec409a2",
|
|
18
|
+
"deviceType": 3,
|
|
19
|
+
"position": 50,
|
|
20
|
+
"onlineStatus": 0,
|
|
21
|
+
"electric": 31,
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
devices = VelaSmartApiClient._parse_devices(result)
|
|
29
|
+
assert len(devices) == 1
|
|
30
|
+
device = devices[0]
|
|
31
|
+
assert device["id"] == "5c1c0a6612"
|
|
32
|
+
assert device["name"] == "BidRoller"
|
|
33
|
+
assert device["gateway_mac"] == "e08cfec409a2"
|
|
34
|
+
assert device["device_type"] == 3
|
|
35
|
+
assert device["position"] == 50
|
|
36
|
+
assert device["is_closed"] is False
|
|
37
|
+
assert device["online"] is False
|
|
38
|
+
assert device["battery"] == 31
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_parse_devices_empty() -> None:
|
|
42
|
+
"""Test parsing an empty device list."""
|
|
43
|
+
result = {"code": 200, "data": {"list": []}}
|
|
44
|
+
assert VelaSmartApiClient._parse_devices(result) == []
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_parse_devices_position_closed() -> None:
|
|
48
|
+
"""Test that position 0 marks the device as closed."""
|
|
49
|
+
result = {
|
|
50
|
+
"code": 200,
|
|
51
|
+
"data": {
|
|
52
|
+
"list": [
|
|
53
|
+
{
|
|
54
|
+
"list": [
|
|
55
|
+
{
|
|
56
|
+
"deviceId": "abc",
|
|
57
|
+
"position": 0,
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
devices = VelaSmartApiClient._parse_devices(result)
|
|
65
|
+
assert devices[0]["is_closed"] is True
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""VelaSmart cloud API client."""
|
|
2
|
+
|
|
3
|
+
from velasmart.client import VelaSmartApiClient, VelaSmartApiError
|
|
4
|
+
from velasmart.const import AUTH_URL, DEVICE_LIST_URL, SEND_ORDER_URL
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"AUTH_URL",
|
|
8
|
+
"DEVICE_LIST_URL",
|
|
9
|
+
"SEND_ORDER_URL",
|
|
10
|
+
"VelaSmartApiClient",
|
|
11
|
+
"VelaSmartApiError",
|
|
12
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Asyncio client for the VelaSmart cloud API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import aiohttp
|
|
9
|
+
|
|
10
|
+
from velasmart.const import AUTH_URL, DEVICE_LIST_URL, SEND_ORDER_URL
|
|
11
|
+
|
|
12
|
+
_LOGGER = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
TIMEOUT = aiohttp.ClientTimeout(total=10)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class VelaSmartApiError(Exception):
|
|
18
|
+
"""Raised when the VelaSmart cloud API returns an error."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class VelaSmartApiClient:
|
|
22
|
+
"""Client for the VelaSmart cloud API."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
username: str,
|
|
27
|
+
password: str,
|
|
28
|
+
session: aiohttp.ClientSession | None = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
"""Initialize the client."""
|
|
31
|
+
self._username = username
|
|
32
|
+
self._password = password
|
|
33
|
+
self._session = session
|
|
34
|
+
self._token: str | None = None
|
|
35
|
+
|
|
36
|
+
async def _post(
|
|
37
|
+
self,
|
|
38
|
+
url: str,
|
|
39
|
+
*,
|
|
40
|
+
headers: dict[str, str] | None = None,
|
|
41
|
+
data: dict[str, Any] | None = None,
|
|
42
|
+
) -> dict[str, Any]:
|
|
43
|
+
"""Perform a POST request, reusing an injected session when available."""
|
|
44
|
+
if self._session is not None:
|
|
45
|
+
async with self._session.post(
|
|
46
|
+
url, headers=headers, json=data, timeout=TIMEOUT
|
|
47
|
+
) as response:
|
|
48
|
+
return await response.json()
|
|
49
|
+
|
|
50
|
+
async with aiohttp.ClientSession(timeout=TIMEOUT) as session:
|
|
51
|
+
async with session.post(url, headers=headers, json=data) as response:
|
|
52
|
+
return await response.json()
|
|
53
|
+
|
|
54
|
+
async def authenticate(self) -> None:
|
|
55
|
+
"""Authenticate with the cloud API and store the returned token."""
|
|
56
|
+
try:
|
|
57
|
+
result = await self._post(
|
|
58
|
+
AUTH_URL,
|
|
59
|
+
data={"account": self._username, "password": self._password},
|
|
60
|
+
)
|
|
61
|
+
except aiohttp.ClientError as err:
|
|
62
|
+
raise VelaSmartApiError(f"Network error: {err}") from err
|
|
63
|
+
|
|
64
|
+
if result.get("code") != 200:
|
|
65
|
+
raise VelaSmartApiError(f"Authentication failed: {result}")
|
|
66
|
+
|
|
67
|
+
token = (result.get("data") or {}).get("token")
|
|
68
|
+
if not token:
|
|
69
|
+
raise VelaSmartApiError("Authentication response did not contain a token")
|
|
70
|
+
self._token = token
|
|
71
|
+
|
|
72
|
+
async def get_devices(self) -> list[dict[str, Any]]:
|
|
73
|
+
"""Fetch the list of devices for the account."""
|
|
74
|
+
if not self._token:
|
|
75
|
+
await self.authenticate()
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
result = await self._post(
|
|
79
|
+
DEVICE_LIST_URL, headers={"token": self._token}, data={}
|
|
80
|
+
)
|
|
81
|
+
except aiohttp.ClientError as err:
|
|
82
|
+
raise VelaSmartApiError(f"Network error: {err}") from err
|
|
83
|
+
|
|
84
|
+
if result.get("code") != 200:
|
|
85
|
+
raise VelaSmartApiError(f"Failed to fetch device list: {result}")
|
|
86
|
+
|
|
87
|
+
return self._parse_devices(result)
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _parse_devices(result: dict[str, Any]) -> list[dict[str, Any]]:
|
|
91
|
+
"""Parse the nested device list returned by the API."""
|
|
92
|
+
data = result.get("data") or {}
|
|
93
|
+
groups = data.get("list") or []
|
|
94
|
+
devices: list[dict[str, Any]] = []
|
|
95
|
+
for group in groups:
|
|
96
|
+
if not isinstance(group, dict):
|
|
97
|
+
continue
|
|
98
|
+
for device in group.get("list") or []:
|
|
99
|
+
if not isinstance(device, dict):
|
|
100
|
+
continue
|
|
101
|
+
position = int(device.get("position", 0) or 0)
|
|
102
|
+
devices.append(
|
|
103
|
+
{
|
|
104
|
+
"id": device.get("deviceId", ""),
|
|
105
|
+
"name": device.get("deviceName", "VelaSmart Curtain"),
|
|
106
|
+
"gateway_mac": device.get("gatewayMac", ""),
|
|
107
|
+
"device_type": device.get("deviceType", 3),
|
|
108
|
+
"position": position,
|
|
109
|
+
"is_closed": position == 0,
|
|
110
|
+
"online": device.get("onlineStatus", 0) == 1,
|
|
111
|
+
"battery": device.get("electric"),
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
return devices
|
|
115
|
+
|
|
116
|
+
async def send_command(
|
|
117
|
+
self, device_id: str, curtain_type: int, position: int
|
|
118
|
+
) -> None:
|
|
119
|
+
"""Send a position command to the given device."""
|
|
120
|
+
if not self._token:
|
|
121
|
+
await self.authenticate()
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
result = await self._post(
|
|
125
|
+
SEND_ORDER_URL,
|
|
126
|
+
headers={"token": self._token},
|
|
127
|
+
data={
|
|
128
|
+
"deviceId": device_id,
|
|
129
|
+
"curtainType": curtain_type,
|
|
130
|
+
"operateCode": 3,
|
|
131
|
+
"angle": 0,
|
|
132
|
+
"position": position,
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
except aiohttp.ClientError as err:
|
|
136
|
+
raise VelaSmartApiError(f"Network error: {err}") from err
|
|
137
|
+
|
|
138
|
+
if result.get("code") != 200:
|
|
139
|
+
raise VelaSmartApiError(f"Command failed: {result}")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Constants for the VelaSmart cloud API."""
|
|
2
|
+
|
|
3
|
+
AUTH_URL = (
|
|
4
|
+
"https://aize2kydb3.execute-api.us-east-1.amazonaws.com/prod/assistantLogin"
|
|
5
|
+
)
|
|
6
|
+
DEVICE_LIST_URL = (
|
|
7
|
+
"https://aize2kydb3.execute-api.us-east-1.amazonaws.com/prod/findDeviceByAccount"
|
|
8
|
+
)
|
|
9
|
+
SEND_ORDER_URL = (
|
|
10
|
+
"https://aize2kydb3.execute-api.us-east-1.amazonaws.com/prod/assistantSendOrder"
|
|
11
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: velasmart
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Asyncio client for the VelaSmart cloud API
|
|
5
|
+
Author: VelaSmart
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/liulijun2019/velasmart
|
|
8
|
+
Project-URL: Repository, https://github.com/liulijun2019/velasmart
|
|
9
|
+
Keywords: velasmart,curtain,homeassistant
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: aiohttp>=3.8
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# velasmart
|
|
22
|
+
|
|
23
|
+
Asyncio client for the VelaSmart cloud API. Used by the VelaSmart Home Assistant
|
|
24
|
+
integration.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install velasmart
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import asyncio
|
|
36
|
+
|
|
37
|
+
from velasmart import VelaSmartApiClient
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def main():
|
|
41
|
+
client = VelaSmartApiClient("username", "password")
|
|
42
|
+
await client.authenticate()
|
|
43
|
+
devices = await client.get_devices()
|
|
44
|
+
for device in devices:
|
|
45
|
+
print(device["id"], device["name"])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
asyncio.run(main())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tests/test_client.py
|
|
5
|
+
velasmart/__init__.py
|
|
6
|
+
velasmart/client.py
|
|
7
|
+
velasmart/const.py
|
|
8
|
+
velasmart.egg-info/PKG-INFO
|
|
9
|
+
velasmart.egg-info/SOURCES.txt
|
|
10
|
+
velasmart.egg-info/dependency_links.txt
|
|
11
|
+
velasmart.egg-info/requires.txt
|
|
12
|
+
velasmart.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp>=3.8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
velasmart
|