sigenergy-cloud 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sigenergy-cloud contributors
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,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: sigenergy-cloud
3
+ Version: 0.1.0
4
+ Summary: Async Python client for the Sigenergy Cloud app API
5
+ Author: sigenergy-cloud contributors
6
+ Maintainer-email: Daniel Schlaug <daniel@schlaug.com>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/solidfox/sigenergy-cloud
9
+ Project-URL: Issues, https://github.com/solidfox/sigenergy-cloud/issues
10
+ Project-URL: Source, https://github.com/solidfox/sigenergy-cloud
11
+ Keywords: sigenergy,home-assistant,asyncio,energy,solar,evse
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Home Automation
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: aiohttp>=3.9.0
27
+ Requires-Dist: pycryptodome>=3.19.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
31
+ Requires-Dist: aioresponses>=0.7; extra == "dev"
32
+ Requires-Dist: python-dotenv>=1.0; extra == "dev"
33
+ Requires-Dist: build>=1.2; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # sigenergy-cloud
37
+
38
+ Async Python client for the Sigenergy Cloud app API.
39
+
40
+ This package is a minimal async wrapper around the private Sigenergy Cloud app
41
+ API. It is built for Home Assistant style integrations that need to read and
42
+ control Sigenergy stations, batteries, and DC chargers.
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ python -m pip install sigenergy-cloud
48
+ ```
49
+
50
+ ## Example
51
+
52
+ ```python
53
+ from sigenergy_cloud import SigenergyCloudClient
54
+
55
+ client = SigenergyCloudClient("user@example.com", "password", region="eu")
56
+ await client.connect()
57
+
58
+ flow = await client.energy_flow()
59
+ mode = await client.current_operational_mode()
60
+ chargers = client.dc_sns
61
+
62
+ await client.close()
63
+ ```
64
+
65
+ ## Shape
66
+
67
+ - Use `SigenergyCloudClient` for cloud calls.
68
+ - Call `connect()` once before reading data or changing settings.
69
+ - The client keeps the station ID and charger serial numbers after connecting.
70
+ - Simple settings use small typed value objects.
71
+ - Vendor response payloads are returned as dictionaries where the API shape is
72
+ still being mapped.
73
+
74
+ ## Regions
75
+
76
+ | Region | Base URL |
77
+ | --- | --- |
78
+ | `eu` | `https://api-eu.sigencloud.com/` |
79
+ | `cn` | `https://api-cn.sigencloud.com/` |
80
+ | `apac` | `https://api-apac.sigencloud.com/` |
81
+ | `us` | `https://api-us.sigencloud.com/` |
@@ -0,0 +1,46 @@
1
+ # sigenergy-cloud
2
+
3
+ Async Python client for the Sigenergy Cloud app API.
4
+
5
+ This package is a minimal async wrapper around the private Sigenergy Cloud app
6
+ API. It is built for Home Assistant style integrations that need to read and
7
+ control Sigenergy stations, batteries, and DC chargers.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ python -m pip install sigenergy-cloud
13
+ ```
14
+
15
+ ## Example
16
+
17
+ ```python
18
+ from sigenergy_cloud import SigenergyCloudClient
19
+
20
+ client = SigenergyCloudClient("user@example.com", "password", region="eu")
21
+ await client.connect()
22
+
23
+ flow = await client.energy_flow()
24
+ mode = await client.current_operational_mode()
25
+ chargers = client.dc_sns
26
+
27
+ await client.close()
28
+ ```
29
+
30
+ ## Shape
31
+
32
+ - Use `SigenergyCloudClient` for cloud calls.
33
+ - Call `connect()` once before reading data or changing settings.
34
+ - The client keeps the station ID and charger serial numbers after connecting.
35
+ - Simple settings use small typed value objects.
36
+ - Vendor response payloads are returned as dictionaries where the API shape is
37
+ still being mapped.
38
+
39
+ ## Regions
40
+
41
+ | Region | Base URL |
42
+ | --- | --- |
43
+ | `eu` | `https://api-eu.sigencloud.com/` |
44
+ | `cn` | `https://api-cn.sigencloud.com/` |
45
+ | `apac` | `https://api-apac.sigencloud.com/` |
46
+ | `us` | `https://api-us.sigencloud.com/` |
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sigenergy-cloud"
7
+ version = "0.1.0"
8
+ description = "Async Python client for the Sigenergy Cloud app API"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [
13
+ { name = "sigenergy-cloud contributors" },
14
+ ]
15
+ maintainers = [
16
+ { name = "Daniel Schlaug", email = "daniel@schlaug.com" },
17
+ ]
18
+ requires-python = ">=3.10"
19
+ keywords = ["sigenergy", "home-assistant", "asyncio", "energy", "solar", "evse"]
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Framework :: AsyncIO",
23
+ "Intended Audience :: Developers",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Topic :: Home Automation",
31
+ "Typing :: Typed",
32
+ ]
33
+ dependencies = [
34
+ "aiohttp>=3.9.0",
35
+ "pycryptodome>=3.19.0",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ dev = [
40
+ "pytest>=8.0",
41
+ "pytest-asyncio>=0.23",
42
+ "aioresponses>=0.7",
43
+ "python-dotenv>=1.0",
44
+ "build>=1.2",
45
+ ]
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/solidfox/sigenergy-cloud"
49
+ Issues = "https://github.com/solidfox/sigenergy-cloud/issues"
50
+ Source = "https://github.com/solidfox/sigenergy-cloud"
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.setuptools.package-data]
56
+ sigenergy_cloud = ["py.typed"]
57
+
58
+ [tool.pytest.ini_options]
59
+ asyncio_mode = "auto"
60
+ markers = [
61
+ "live: requires real SIGENERGY_USERNAME / SIGENERGY_PASSWORD env vars (deselect with -m 'not live')",
62
+ "write: test writes to the device — always paired with the restore fixture",
63
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ """Owned async client for the Sigenergy Cloud app API."""
2
+
3
+ from .client import SigenergyCloudClient
4
+ from .errors import (
5
+ SigenergyCloudAPIError,
6
+ SigenergyCloudAuthError,
7
+ SigenergyCloudError,
8
+ SigenergyCloudRateLimitError,
9
+ SigenergyCloudTokenExpiredError,
10
+ )
11
+ from .models import BatteryLevelSettings, PeakShavingSchedule, PeakShavingSlot
12
+
13
+ __all__ = [
14
+ "BatteryLevelSettings",
15
+ "PeakShavingSchedule",
16
+ "PeakShavingSlot",
17
+ "SigenergyCloudAPIError",
18
+ "SigenergyCloudAuthError",
19
+ "SigenergyCloudClient",
20
+ "SigenergyCloudError",
21
+ "SigenergyCloudRateLimitError",
22
+ "SigenergyCloudTokenExpiredError",
23
+ ]
@@ -0,0 +1,135 @@
1
+ """Authentication primitives for the Sigenergy Cloud app API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import time
7
+ from dataclasses import dataclass
8
+ from typing import Any
9
+
10
+ import aiohttp
11
+ from Crypto.Cipher import AES
12
+ from Crypto.Util.Padding import pad
13
+
14
+ from .errors import SigenergyCloudAuthError, SigenergyCloudTokenExpiredError
15
+
16
+ _PASSWORD_AES_KEY = "sigensigensigenp"
17
+ _PASSWORD_AES_IV = "sigensigensigenp"
18
+ _OAUTH_CLIENT_ID = "sigen"
19
+ _OAUTH_CLIENT_SECRET = "sigen"
20
+ _TOKEN_REFRESH_MARGIN_SECONDS = 60
21
+
22
+
23
+ def encrypt_password(password: str) -> str:
24
+ """Return the AES-CBC password encoding expected by Sigenergy Cloud."""
25
+ cipher = AES.new(
26
+ _PASSWORD_AES_KEY.encode("utf-8"),
27
+ AES.MODE_CBC,
28
+ _PASSWORD_AES_IV.encode("latin1"),
29
+ )
30
+ encrypted = cipher.encrypt(pad(password.encode("utf-8"), AES.block_size))
31
+ return base64.b64encode(encrypted).decode("utf-8")
32
+
33
+
34
+ @dataclass(frozen=True, slots=True)
35
+ class TokenBundle:
36
+ """OAuth tokens plus their local expiry deadline."""
37
+
38
+ access_token: str
39
+ refresh_token: str
40
+ expires_at: float
41
+
42
+ @classmethod
43
+ def from_api(cls, payload: dict[str, Any]) -> "TokenBundle":
44
+ """Create a token bundle from Sigenergy's OAuth response shape."""
45
+ expires_in = int(payload["expires_in"])
46
+ return cls(
47
+ access_token=str(payload["access_token"]),
48
+ refresh_token=str(payload["refresh_token"]),
49
+ expires_at=time.time() + max(0, expires_in - _TOKEN_REFRESH_MARGIN_SECONDS),
50
+ )
51
+
52
+ @property
53
+ def expired(self) -> bool:
54
+ """Return true when the token should be refreshed before use."""
55
+ return time.time() >= self.expires_at
56
+
57
+
58
+ class OAuthSession:
59
+ """Small state holder for Sigenergy's password-grant OAuth flow."""
60
+
61
+ def __init__(self) -> None:
62
+ self._tokens: TokenBundle | None = None
63
+
64
+ @property
65
+ def headers(self) -> dict[str, str]:
66
+ """Return JSON headers for authenticated cloud requests."""
67
+ if self._tokens is None:
68
+ raise SigenergyCloudAuthError("Sigenergy Cloud is not authenticated")
69
+ return {
70
+ "Authorization": f"Bearer {self._tokens.access_token}",
71
+ "Content-Type": "application/json",
72
+ }
73
+
74
+ async def authenticate(
75
+ self,
76
+ session: aiohttp.ClientSession,
77
+ base_url: str,
78
+ username: str,
79
+ encrypted_password: str,
80
+ ) -> None:
81
+ """Authenticate with username/password and store access tokens."""
82
+ self._tokens = await self._request_token(
83
+ session,
84
+ base_url,
85
+ {
86
+ "username": username,
87
+ "password": encrypted_password,
88
+ "grant_type": "password",
89
+ },
90
+ SigenergyCloudAuthError,
91
+ )
92
+
93
+ async def ensure_token(self, session: aiohttp.ClientSession, base_url: str) -> None:
94
+ """Refresh the token if needed."""
95
+ if self._tokens is None:
96
+ raise SigenergyCloudAuthError("Sigenergy Cloud is not authenticated")
97
+ if not self._tokens.expired:
98
+ return
99
+ self._tokens = await self._request_token(
100
+ session,
101
+ base_url,
102
+ {
103
+ "grant_type": "refresh_token",
104
+ "refresh_token": self._tokens.refresh_token,
105
+ },
106
+ SigenergyCloudTokenExpiredError,
107
+ )
108
+
109
+ async def _request_token(
110
+ self,
111
+ session: aiohttp.ClientSession,
112
+ base_url: str,
113
+ form: dict[str, str],
114
+ error_type: type[SigenergyCloudAuthError],
115
+ ) -> TokenBundle:
116
+ url = f"{base_url}auth/oauth/token"
117
+ async with session.post(
118
+ url,
119
+ data=form,
120
+ auth=aiohttp.BasicAuth(_OAUTH_CLIENT_ID, _OAUTH_CLIENT_SECRET),
121
+ ) as response:
122
+ body = await response.text()
123
+ if response.status != 200:
124
+ raise error_type(
125
+ f"Sigenergy Cloud authentication failed: HTTP {response.status}; {body}"
126
+ )
127
+ payload = await response.json()
128
+
129
+ token_payload = payload.get("data", payload)
130
+ if not isinstance(token_payload, dict):
131
+ raise error_type(f"Unexpected Sigenergy Cloud token response: {payload!r}")
132
+ try:
133
+ return TokenBundle.from_api(token_payload)
134
+ except KeyError as exc:
135
+ raise error_type(f"Incomplete Sigenergy Cloud token response: {payload!r}") from exc