py-sungrow-isolarcloud 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.
- py_sungrow_isolarcloud/__init__.py +42 -0
- py_sungrow_isolarcloud/client.py +472 -0
- py_sungrow_isolarcloud/const.py +48 -0
- py_sungrow_isolarcloud/crypto.py +93 -0
- py_sungrow_isolarcloud/models.py +519 -0
- py_sungrow_isolarcloud/py.typed +0 -0
- py_sungrow_isolarcloud-0.1.0.dist-info/METADATA +87 -0
- py_sungrow_isolarcloud-0.1.0.dist-info/RECORD +11 -0
- py_sungrow_isolarcloud-0.1.0.dist-info/WHEEL +5 -0
- py_sungrow_isolarcloud-0.1.0.dist-info/licenses/LICENSE +21 -0
- py_sungrow_isolarcloud-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Async iSolarCloud API client package."""
|
|
2
|
+
|
|
3
|
+
from .client import (
|
|
4
|
+
ISolarCloudApiError,
|
|
5
|
+
ISolarCloudAuthError,
|
|
6
|
+
ISolarCloudClient,
|
|
7
|
+
ISolarCloudConnectionError,
|
|
8
|
+
ISolarCloudError,
|
|
9
|
+
)
|
|
10
|
+
from .const import GATEWAY_AUTO, GATEWAYS
|
|
11
|
+
from .models import (
|
|
12
|
+
ActiveFault,
|
|
13
|
+
AuthSession,
|
|
14
|
+
ChargingPileSummary,
|
|
15
|
+
DevicePoint,
|
|
16
|
+
DeviceSummary,
|
|
17
|
+
PlantData,
|
|
18
|
+
PlantFlow,
|
|
19
|
+
PlantSummary,
|
|
20
|
+
PlantWeather,
|
|
21
|
+
ValueUnit,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"ActiveFault",
|
|
26
|
+
"AuthSession",
|
|
27
|
+
"ChargingPileSummary",
|
|
28
|
+
"DevicePoint",
|
|
29
|
+
"DeviceSummary",
|
|
30
|
+
"GATEWAYS",
|
|
31
|
+
"GATEWAY_AUTO",
|
|
32
|
+
"ISolarCloudApiError",
|
|
33
|
+
"ISolarCloudAuthError",
|
|
34
|
+
"ISolarCloudClient",
|
|
35
|
+
"ISolarCloudConnectionError",
|
|
36
|
+
"ISolarCloudError",
|
|
37
|
+
"PlantData",
|
|
38
|
+
"PlantFlow",
|
|
39
|
+
"PlantSummary",
|
|
40
|
+
"PlantWeather",
|
|
41
|
+
"ValueUnit",
|
|
42
|
+
]
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
"""Async HTTP client for iSolarCloud."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
from datetime import UTC, datetime
|
|
8
|
+
from email.utils import parsedate_to_datetime
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import aiohttp
|
|
12
|
+
|
|
13
|
+
from .const import (
|
|
14
|
+
AUTO_GATEWAY_ORDER,
|
|
15
|
+
DEFAULT_ACCESS_KEY,
|
|
16
|
+
DEFAULT_APP_KEY,
|
|
17
|
+
DEFAULT_USER_AGENT,
|
|
18
|
+
DEFAULT_WEB_VERSION,
|
|
19
|
+
ENDPOINT_GET_CHARGING_PILE_LIST,
|
|
20
|
+
ENDPOINT_GET_DEVICE_POINTS,
|
|
21
|
+
ENDPOINT_GET_PS_ALL_DEVICE_LIST,
|
|
22
|
+
ENDPOINT_GET_PS_BATTERY_INFO,
|
|
23
|
+
ENDPOINT_GET_PS_DETAIL_WITH_PS_TYPE,
|
|
24
|
+
ENDPOINT_GET_PS_LIST,
|
|
25
|
+
ENDPOINT_GET_PS_WEATHER_INFO,
|
|
26
|
+
ENDPOINT_LOGIN,
|
|
27
|
+
ENDPOINT_QUERY_FAULT_LIST,
|
|
28
|
+
GATEWAY_AUTO,
|
|
29
|
+
GATEWAYS,
|
|
30
|
+
)
|
|
31
|
+
from .crypto import (
|
|
32
|
+
aes_decrypt_hex,
|
|
33
|
+
aes_encrypt_hex,
|
|
34
|
+
current_gmt_header,
|
|
35
|
+
current_timestamp_ms,
|
|
36
|
+
generate_aes_key,
|
|
37
|
+
generate_did,
|
|
38
|
+
generate_nonce,
|
|
39
|
+
rsa_encrypt_base64,
|
|
40
|
+
)
|
|
41
|
+
from .models import (
|
|
42
|
+
ActiveFault,
|
|
43
|
+
AuthSession,
|
|
44
|
+
ChargingPileSummary,
|
|
45
|
+
DevicePoint,
|
|
46
|
+
DeviceSummary,
|
|
47
|
+
PlantData,
|
|
48
|
+
PlantFlow,
|
|
49
|
+
PlantSummary,
|
|
50
|
+
PlantWeather,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
_LOGGER = logging.getLogger(__name__)
|
|
54
|
+
|
|
55
|
+
_TOKEN_INVALID_CODES = {"E00003"}
|
|
56
|
+
_TOKEN_INVALID_MSGS = ("er_token_login_invalid", "need to login again")
|
|
57
|
+
_AUTH_FAILED_MSGS = ("account or password", "user_account", "er_invalid_appkey", "e914")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ISolarCloudError(Exception):
|
|
61
|
+
"""Base iSolarCloud client exception."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ISolarCloudAuthError(ISolarCloudError):
|
|
65
|
+
"""Raised when credentials are invalid or authentication fails."""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ISolarCloudConnectionError(ISolarCloudError):
|
|
69
|
+
"""Raised on network, timeout, or non-200 transport errors."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ISolarCloudApiError(ISolarCloudError):
|
|
73
|
+
"""Raised when iSolarCloud returns an API-level error."""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ISolarCloudClient:
|
|
77
|
+
"""Async iSolarCloud client using AES+RSA encrypted JSON over HTTPS."""
|
|
78
|
+
|
|
79
|
+
def __init__(
|
|
80
|
+
self,
|
|
81
|
+
session: aiohttp.ClientSession,
|
|
82
|
+
username: str,
|
|
83
|
+
password: str,
|
|
84
|
+
gateway: str = GATEWAY_AUTO,
|
|
85
|
+
app_key: str = DEFAULT_APP_KEY,
|
|
86
|
+
lang: str = "_en_US",
|
|
87
|
+
timeout_seconds: int = 30,
|
|
88
|
+
) -> None:
|
|
89
|
+
self._http = session
|
|
90
|
+
self._username = username
|
|
91
|
+
self._password = password
|
|
92
|
+
self._configured_gateway = gateway
|
|
93
|
+
self._app_key = app_key
|
|
94
|
+
self._lang = lang
|
|
95
|
+
self._timeout = aiohttp.ClientTimeout(total=timeout_seconds)
|
|
96
|
+
self._did = generate_did()
|
|
97
|
+
self._clock_offset_seconds = 0.0
|
|
98
|
+
self._auth: AuthSession | None = None
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def active_gateway(self) -> str | None:
|
|
102
|
+
"""Return the currently authenticated gateway URL."""
|
|
103
|
+
return self._auth.gateway if self._auth else None
|
|
104
|
+
|
|
105
|
+
def _gateway_candidates(self) -> list[str]:
|
|
106
|
+
if self._configured_gateway != GATEWAY_AUTO:
|
|
107
|
+
resolved = GATEWAYS.get(self._configured_gateway, self._configured_gateway)
|
|
108
|
+
return [resolved.rstrip("/")]
|
|
109
|
+
if self._auth:
|
|
110
|
+
ordered = [self._auth.gateway]
|
|
111
|
+
for candidate in AUTO_GATEWAY_ORDER:
|
|
112
|
+
if candidate not in ordered:
|
|
113
|
+
ordered.append(candidate)
|
|
114
|
+
return ordered
|
|
115
|
+
return list(AUTO_GATEWAY_ORDER)
|
|
116
|
+
|
|
117
|
+
async def async_login(self) -> AuthSession:
|
|
118
|
+
"""Authenticate against configured or auto-discovered regional gateway."""
|
|
119
|
+
last_error: Exception | None = None
|
|
120
|
+
for base_url in self._gateway_candidates():
|
|
121
|
+
try:
|
|
122
|
+
payload = {
|
|
123
|
+
"user_account": self._username,
|
|
124
|
+
"user_password": self._password,
|
|
125
|
+
"login_type": "1",
|
|
126
|
+
"strong_weak_password": "1",
|
|
127
|
+
"rememberMe": False,
|
|
128
|
+
"supportTotp": 1,
|
|
129
|
+
"isNamePassword": True,
|
|
130
|
+
"sys_code": "900",
|
|
131
|
+
}
|
|
132
|
+
result = await self._post_encrypted(
|
|
133
|
+
base_url=base_url,
|
|
134
|
+
endpoint=ENDPOINT_LOGIN,
|
|
135
|
+
data=payload,
|
|
136
|
+
include_auth=False,
|
|
137
|
+
)
|
|
138
|
+
result_data = result.get("result_data") or {}
|
|
139
|
+
token = str(result_data.get("token") or "")
|
|
140
|
+
user_id = str(result_data.get("user_id") or "")
|
|
141
|
+
if not token or not user_id:
|
|
142
|
+
raise ISolarCloudAuthError("Login succeeded without token or user_id")
|
|
143
|
+
self._auth = AuthSession(
|
|
144
|
+
token=token,
|
|
145
|
+
user_id=user_id,
|
|
146
|
+
gateway=base_url,
|
|
147
|
+
login_at=datetime.now(UTC),
|
|
148
|
+
)
|
|
149
|
+
return self._auth
|
|
150
|
+
except ISolarCloudAuthError:
|
|
151
|
+
raise
|
|
152
|
+
except (ISolarCloudConnectionError, ISolarCloudApiError) as err:
|
|
153
|
+
_LOGGER.debug("Gateway %s login failed: %s", base_url, err)
|
|
154
|
+
last_error = err
|
|
155
|
+
continue
|
|
156
|
+
|
|
157
|
+
if isinstance(last_error, ISolarCloudError):
|
|
158
|
+
raise last_error
|
|
159
|
+
raise ISolarCloudConnectionError("No iSolarCloud gateway succeeded")
|
|
160
|
+
|
|
161
|
+
async def async_get_ps_list(self) -> list[PlantSummary]:
|
|
162
|
+
"""Fetch all plants accessible by the authenticated user."""
|
|
163
|
+
data = await self._call_authed(
|
|
164
|
+
ENDPOINT_GET_PS_LIST,
|
|
165
|
+
{
|
|
166
|
+
"curPage": 1,
|
|
167
|
+
"size": 100,
|
|
168
|
+
"valid_flag": "1,3",
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
result_data = data.get("result_data") or {}
|
|
172
|
+
rows = result_data.get("pageList") or []
|
|
173
|
+
return [PlantSummary.from_dict(row) for row in rows if row.get("ps_id") is not None]
|
|
174
|
+
|
|
175
|
+
async def async_get_ps_detail_with_ps_type(self, ps_id: str) -> PlantFlow:
|
|
176
|
+
"""Fetch curated plant power flow & energy totals."""
|
|
177
|
+
data = await self._call_authed(
|
|
178
|
+
ENDPOINT_GET_PS_DETAIL_WITH_PS_TYPE,
|
|
179
|
+
{
|
|
180
|
+
"ps_id": ps_id,
|
|
181
|
+
"is_get_ps_level_data": "1",
|
|
182
|
+
"version_tag": "1",
|
|
183
|
+
"is_shut_down_flag": "1",
|
|
184
|
+
"is_get_hm_info": "1",
|
|
185
|
+
"func_code": "5",
|
|
186
|
+
},
|
|
187
|
+
)
|
|
188
|
+
result_data = data.get("result_data") or {}
|
|
189
|
+
return PlantFlow.from_detail_dict(result_data)
|
|
190
|
+
|
|
191
|
+
async def async_get_ps_all_device_list(self, ps_id: str) -> list[DeviceSummary]:
|
|
192
|
+
"""Fetch device inventory for one plant."""
|
|
193
|
+
data = await self._call_authed(
|
|
194
|
+
ENDPOINT_GET_PS_ALL_DEVICE_LIST,
|
|
195
|
+
{
|
|
196
|
+
"ps_id": ps_id,
|
|
197
|
+
"curPage": "1",
|
|
198
|
+
"size": "100",
|
|
199
|
+
"is_get_g2point5_inverter": "1",
|
|
200
|
+
"is_get_second_level_flag": "1",
|
|
201
|
+
},
|
|
202
|
+
)
|
|
203
|
+
result_data = data.get("result_data") or {}
|
|
204
|
+
rows = result_data.get("pageList") or result_data.get("list") or []
|
|
205
|
+
return [
|
|
206
|
+
DeviceSummary.from_dict(ps_id, row)
|
|
207
|
+
for row in rows
|
|
208
|
+
if row.get("ps_key") or row.get("uuid")
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
async def async_get_device_points(
|
|
212
|
+
self, ps_key: str, device_type: int
|
|
213
|
+
) -> dict[int, DevicePoint]:
|
|
214
|
+
"""Fetch curated device telemetry points for any device_type."""
|
|
215
|
+
data = await self._call_authed(
|
|
216
|
+
ENDPOINT_GET_DEVICE_POINTS,
|
|
217
|
+
{
|
|
218
|
+
"ps_key": ps_key,
|
|
219
|
+
"device_type": str(device_type),
|
|
220
|
+
},
|
|
221
|
+
)
|
|
222
|
+
rows = data.get("result_data") or []
|
|
223
|
+
points: dict[int, DevicePoint] = {}
|
|
224
|
+
if isinstance(rows, list):
|
|
225
|
+
for row in rows:
|
|
226
|
+
if not isinstance(row, dict):
|
|
227
|
+
continue
|
|
228
|
+
pt = DevicePoint.from_dict(row)
|
|
229
|
+
if pt is not None:
|
|
230
|
+
points[pt.point_id] = pt
|
|
231
|
+
return points
|
|
232
|
+
|
|
233
|
+
async def async_get_active_faults(self, ps_id: str) -> list[ActiveFault]:
|
|
234
|
+
"""Fetch active/open faults for a plant."""
|
|
235
|
+
data = await self._call_authed(
|
|
236
|
+
ENDPOINT_QUERY_FAULT_LIST,
|
|
237
|
+
{"ps_id": ps_id, "curPage": "1", "size": "20", "process_status": "8"},
|
|
238
|
+
)
|
|
239
|
+
result_data = data.get("result_data") or {}
|
|
240
|
+
rows = result_data.get("pageList") or result_data.get("list") or []
|
|
241
|
+
return [ActiveFault.from_dict(row) for row in rows if isinstance(row, dict)]
|
|
242
|
+
|
|
243
|
+
async def async_get_ps_weather_info(self, ps_id: str) -> PlantWeather | None:
|
|
244
|
+
"""Fetch local plant weather summary."""
|
|
245
|
+
data = await self._call_authed(ENDPOINT_GET_PS_WEATHER_INFO, {"ps_id": ps_id})
|
|
246
|
+
result_data = data.get("result_data")
|
|
247
|
+
if not isinstance(result_data, dict):
|
|
248
|
+
return None
|
|
249
|
+
return PlantWeather.from_dict(result_data)
|
|
250
|
+
|
|
251
|
+
async def async_get_charging_piles(self, ps_id: str) -> list[ChargingPileSummary]:
|
|
252
|
+
"""Fetch EV charging piles for a plant."""
|
|
253
|
+
data = await self._call_authed(
|
|
254
|
+
ENDPOINT_GET_CHARGING_PILE_LIST,
|
|
255
|
+
{"psId": ps_id, "curPage": "1", "size": "20"},
|
|
256
|
+
)
|
|
257
|
+
result_data = data.get("result_data") or {}
|
|
258
|
+
rows = result_data.get("list") or result_data.get("pageList") or []
|
|
259
|
+
return [
|
|
260
|
+
ChargingPileSummary.from_dict(row)
|
|
261
|
+
for row in rows
|
|
262
|
+
if isinstance(row, dict) and (row.get("charging_pile_sn") or row.get("sn"))
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
async def async_get_ps_battery_info(self, ps_id: str) -> dict[str, Any] | None:
|
|
266
|
+
"""Fetch plant-level battery summary when available."""
|
|
267
|
+
data = await self._call_authed(ENDPOINT_GET_PS_BATTERY_INFO, {"ps_id": ps_id})
|
|
268
|
+
result_data = data.get("result_data")
|
|
269
|
+
if isinstance(result_data, dict):
|
|
270
|
+
return result_data
|
|
271
|
+
return None
|
|
272
|
+
|
|
273
|
+
async def async_fetch_all_plants(self) -> dict[str, PlantData]:
|
|
274
|
+
"""Fetch plant summaries, flows, devices, and device points for all plants."""
|
|
275
|
+
if self._auth is None:
|
|
276
|
+
await self.async_login()
|
|
277
|
+
plants = await self.async_get_ps_list()
|
|
278
|
+
output: dict[str, PlantData] = {}
|
|
279
|
+
for plant in plants:
|
|
280
|
+
flow = await self.async_get_ps_detail_with_ps_type(plant.ps_id)
|
|
281
|
+
devices = await self.async_get_ps_all_device_list(plant.ps_id)
|
|
282
|
+
for dev in devices:
|
|
283
|
+
if dev.device_type is not None:
|
|
284
|
+
try:
|
|
285
|
+
dev.points = await self.async_get_device_points(dev.ps_key, dev.device_type)
|
|
286
|
+
except ISolarCloudError as err:
|
|
287
|
+
_LOGGER.debug(
|
|
288
|
+
"Could not fetch points for %s (type=%s): %s",
|
|
289
|
+
dev.ps_key,
|
|
290
|
+
dev.device_type,
|
|
291
|
+
err,
|
|
292
|
+
)
|
|
293
|
+
active_faults: list[ActiveFault] = []
|
|
294
|
+
if flow.has_fault or any(d.has_fault for d in devices):
|
|
295
|
+
try:
|
|
296
|
+
active_faults = await self.async_get_active_faults(plant.ps_id)
|
|
297
|
+
except ISolarCloudError as err:
|
|
298
|
+
_LOGGER.debug("Could not fetch active faults for %s: %s", plant.ps_id, err)
|
|
299
|
+
|
|
300
|
+
weather: PlantWeather | None = None
|
|
301
|
+
try:
|
|
302
|
+
weather = await self.async_get_ps_weather_info(plant.ps_id)
|
|
303
|
+
except ISolarCloudError as err:
|
|
304
|
+
_LOGGER.debug("Could not fetch weather for %s: %s", plant.ps_id, err)
|
|
305
|
+
|
|
306
|
+
charging_piles: list[ChargingPileSummary] = []
|
|
307
|
+
if flow.has_charging_pile:
|
|
308
|
+
try:
|
|
309
|
+
charging_piles = await self.async_get_charging_piles(plant.ps_id)
|
|
310
|
+
except ISolarCloudError as err:
|
|
311
|
+
_LOGGER.debug("Could not fetch charging piles for %s: %s", plant.ps_id, err)
|
|
312
|
+
|
|
313
|
+
battery_info: dict[str, Any] | None = None
|
|
314
|
+
if flow.battery_soc is not None:
|
|
315
|
+
try:
|
|
316
|
+
battery_info = await self.async_get_ps_battery_info(plant.ps_id)
|
|
317
|
+
except ISolarCloudError as err:
|
|
318
|
+
_LOGGER.debug("Could not fetch battery info for %s: %s", plant.ps_id, err)
|
|
319
|
+
|
|
320
|
+
output[plant.ps_id] = PlantData(
|
|
321
|
+
summary=plant,
|
|
322
|
+
flow=flow,
|
|
323
|
+
devices=devices,
|
|
324
|
+
active_faults=active_faults,
|
|
325
|
+
weather=weather,
|
|
326
|
+
charging_piles=charging_piles,
|
|
327
|
+
battery_info=battery_info,
|
|
328
|
+
)
|
|
329
|
+
return output
|
|
330
|
+
|
|
331
|
+
async def _call_authed(self, endpoint: str, data: dict[str, Any]) -> dict[str, Any]:
|
|
332
|
+
if self._auth is None:
|
|
333
|
+
await self.async_login()
|
|
334
|
+
assert self._auth is not None
|
|
335
|
+
try:
|
|
336
|
+
return await self._post_encrypted(
|
|
337
|
+
base_url=self._auth.gateway,
|
|
338
|
+
endpoint=endpoint,
|
|
339
|
+
data=data,
|
|
340
|
+
include_auth=True,
|
|
341
|
+
)
|
|
342
|
+
except ISolarCloudAuthError:
|
|
343
|
+
_LOGGER.debug("Session token expired on %s, re-authenticating once", endpoint)
|
|
344
|
+
await self.async_login()
|
|
345
|
+
return await self._post_encrypted(
|
|
346
|
+
base_url=self._auth.gateway,
|
|
347
|
+
endpoint=endpoint,
|
|
348
|
+
data=data,
|
|
349
|
+
include_auth=True,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
async def _post_encrypted(
|
|
353
|
+
self,
|
|
354
|
+
base_url: str,
|
|
355
|
+
endpoint: str,
|
|
356
|
+
data: dict[str, Any],
|
|
357
|
+
include_auth: bool,
|
|
358
|
+
retry_clock: bool = True,
|
|
359
|
+
) -> dict[str, Any]:
|
|
360
|
+
aes_key = generate_aes_key()
|
|
361
|
+
body_dict: dict[str, Any] = {
|
|
362
|
+
**data,
|
|
363
|
+
"appkey": self._app_key,
|
|
364
|
+
"lang": self._lang,
|
|
365
|
+
"sys_code": data.get("sys_code", 200),
|
|
366
|
+
"api_key_param": {
|
|
367
|
+
"timestamp": current_timestamp_ms(self._clock_offset_seconds),
|
|
368
|
+
"nonce": generate_nonce(),
|
|
369
|
+
},
|
|
370
|
+
}
|
|
371
|
+
if include_auth and self._auth is not None:
|
|
372
|
+
body_dict["token"] = self._auth.token
|
|
373
|
+
body_dict["user_id"] = self._auth.user_id
|
|
374
|
+
|
|
375
|
+
compact_json = json.dumps(body_dict, separators=(",", ":"))
|
|
376
|
+
encrypted_body = aes_encrypt_hex(compact_json, aes_key)
|
|
377
|
+
|
|
378
|
+
headers = {
|
|
379
|
+
"accept": "application/json, text/plain, */*",
|
|
380
|
+
"accept-language": "en-US,en;q=0.9",
|
|
381
|
+
"user-agent": DEFAULT_USER_AGENT,
|
|
382
|
+
"origin": "https://www.isolarcloud.com",
|
|
383
|
+
"referer": "https://www.isolarcloud.com/",
|
|
384
|
+
"content-type": "text/plain;charset=UTF-8",
|
|
385
|
+
"sys_code": "200",
|
|
386
|
+
"_pl": "js",
|
|
387
|
+
"_did": self._did,
|
|
388
|
+
"_global_new_web": "1",
|
|
389
|
+
"_vc": DEFAULT_WEB_VERSION,
|
|
390
|
+
"_browser_brand": "chrome",
|
|
391
|
+
"_browser_version": "132.0",
|
|
392
|
+
"x-client-tz": current_gmt_header(),
|
|
393
|
+
"x-sign-code": "0",
|
|
394
|
+
"x-access-key": DEFAULT_ACCESS_KEY,
|
|
395
|
+
"x-random-secret-key": rsa_encrypt_base64(aes_key),
|
|
396
|
+
}
|
|
397
|
+
if include_auth and self._auth is not None and self._auth.token:
|
|
398
|
+
prefix = self._auth.token.split("_", 1)[0].strip()
|
|
399
|
+
if prefix:
|
|
400
|
+
headers["x-limit-obj"] = rsa_encrypt_base64(prefix)
|
|
401
|
+
|
|
402
|
+
url = f"{base_url.rstrip('/')}{endpoint}"
|
|
403
|
+
try:
|
|
404
|
+
async with self._http.post(
|
|
405
|
+
url,
|
|
406
|
+
data=encrypted_body,
|
|
407
|
+
headers=headers,
|
|
408
|
+
timeout=self._timeout,
|
|
409
|
+
) as resp:
|
|
410
|
+
raw_text = await resp.text()
|
|
411
|
+
date_header = resp.headers.get("Date")
|
|
412
|
+
if resp.status == 401:
|
|
413
|
+
raise ISolarCloudAuthError(f"HTTP 401 on {endpoint}")
|
|
414
|
+
if resp.status != 200:
|
|
415
|
+
raise ISolarCloudConnectionError(f"HTTP {resp.status} on {endpoint}")
|
|
416
|
+
except (aiohttp.ClientError, TimeoutError) as err:
|
|
417
|
+
raise ISolarCloudConnectionError(f"Network error on {endpoint}: {err}") from err
|
|
418
|
+
|
|
419
|
+
parsed = self._decode_response(raw_text, aes_key)
|
|
420
|
+
result_code = str(parsed.get("result_code") or "")
|
|
421
|
+
result_msg = str(parsed.get("result_msg") or "")
|
|
422
|
+
|
|
423
|
+
if "expired request" in result_msg.lower() and retry_clock:
|
|
424
|
+
self._update_clock_offset(date_header)
|
|
425
|
+
return await self._post_encrypted(
|
|
426
|
+
base_url=base_url,
|
|
427
|
+
endpoint=endpoint,
|
|
428
|
+
data=data,
|
|
429
|
+
include_auth=include_auth,
|
|
430
|
+
retry_clock=False,
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
if result_code == "1" and result_msg.lower() in ("", "success"):
|
|
434
|
+
return parsed
|
|
435
|
+
|
|
436
|
+
lower_msg = result_msg.lower()
|
|
437
|
+
if result_code in _TOKEN_INVALID_CODES or any(m in lower_msg for m in _TOKEN_INVALID_MSGS):
|
|
438
|
+
raise ISolarCloudAuthError(f"Session invalid ({result_code}): {result_msg}")
|
|
439
|
+
if any(m in lower_msg for m in _AUTH_FAILED_MSGS):
|
|
440
|
+
raise ISolarCloudAuthError(f"Authentication failed ({result_code}): {result_msg}")
|
|
441
|
+
|
|
442
|
+
raise ISolarCloudApiError(f"API error on {endpoint} ({result_code}): {result_msg}")
|
|
443
|
+
|
|
444
|
+
def _decode_response(self, raw_text: str, aes_key: str) -> dict[str, Any]:
|
|
445
|
+
stripped = raw_text.strip()
|
|
446
|
+
if not stripped:
|
|
447
|
+
raise ISolarCloudApiError("Empty response body from iSolarCloud")
|
|
448
|
+
try:
|
|
449
|
+
decrypted = aes_decrypt_hex(stripped, aes_key)
|
|
450
|
+
data = json.loads(decrypted)
|
|
451
|
+
if isinstance(data, dict):
|
|
452
|
+
return data
|
|
453
|
+
except Exception:
|
|
454
|
+
pass
|
|
455
|
+
try:
|
|
456
|
+
data = json.loads(stripped)
|
|
457
|
+
if isinstance(data, dict):
|
|
458
|
+
return data
|
|
459
|
+
except json.JSONDecodeError as err:
|
|
460
|
+
raise ISolarCloudApiError(f"Invalid JSON response: {err}") from err
|
|
461
|
+
raise ISolarCloudApiError("Unexpected response payload structure")
|
|
462
|
+
|
|
463
|
+
def _update_clock_offset(self, date_header: str | None) -> None:
|
|
464
|
+
if not date_header:
|
|
465
|
+
return
|
|
466
|
+
try:
|
|
467
|
+
server_dt = parsedate_to_datetime(date_header)
|
|
468
|
+
if server_dt.tzinfo is None:
|
|
469
|
+
server_dt = server_dt.replace(tzinfo=UTC)
|
|
470
|
+
self._clock_offset_seconds = server_dt.timestamp() - datetime.now(UTC).timestamp()
|
|
471
|
+
except Exception:
|
|
472
|
+
pass
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Constants for the iSolarCloud wire protocol and endpoints."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
GATEWAY_AUTO = "auto"
|
|
6
|
+
|
|
7
|
+
GATEWAYS: dict[str, str] = {
|
|
8
|
+
"eu": "https://gateway.isolarcloud.eu",
|
|
9
|
+
"com": "https://gateway.isolarcloud.com",
|
|
10
|
+
"au": "https://augateway.isolarcloud.com",
|
|
11
|
+
"hk": "https://gateway.isolarcloud.com.hk",
|
|
12
|
+
"cn": "https://gateway.isolarcloud.com.cn",
|
|
13
|
+
"in": "https://gateway.isolarcloud.in",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
AUTO_GATEWAY_ORDER: tuple[str, ...] = (
|
|
17
|
+
"https://gateway.isolarcloud.eu",
|
|
18
|
+
"https://gateway.isolarcloud.com",
|
|
19
|
+
"https://augateway.isolarcloud.com",
|
|
20
|
+
"https://gateway.isolarcloud.com.hk",
|
|
21
|
+
"https://gateway.isolarcloud.com.cn",
|
|
22
|
+
"https://gateway.isolarcloud.in",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
DEFAULT_APP_KEY = "B0455FBE7AA0328DB57B59AA729F05D8"
|
|
26
|
+
DEFAULT_ACCESS_KEY = "9grzgbmxdsp3arfmmgq347xjbza4ysps"
|
|
27
|
+
DEFAULT_WEB_VERSION = "2026011301"
|
|
28
|
+
DEFAULT_USER_AGENT = (
|
|
29
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
30
|
+
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
RSA_PUBLIC_KEY_B64URL = (
|
|
34
|
+
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCkecphb6vgsBx4LJknKKes-eyj"
|
|
35
|
+
"7-RKQ3fikF5B67EObZ3t4moFZyMGuuJPiadYdaxvRqtxyblIlVM7omAasROtKRht"
|
|
36
|
+
"gKwwRxo2a6878qBhTgUVlsqugpI_7ZC9RmO2Rpmr8WzDeAapGANfHN5bVr7G7GYG"
|
|
37
|
+
"wIrjvyxMrAVit_oM4wIDAQAB"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
ENDPOINT_LOGIN = "/v1/userService/login"
|
|
41
|
+
ENDPOINT_GET_PS_LIST = "/v1/powerStationService/getPsList"
|
|
42
|
+
ENDPOINT_GET_PS_DETAIL_WITH_PS_TYPE = "/v1/powerStationService/getPsDetailWithPsType"
|
|
43
|
+
ENDPOINT_GET_PS_ALL_DEVICE_LIST = "/v1/devService/getPsAllDeviceList"
|
|
44
|
+
ENDPOINT_GET_DEVICE_POINTS = "/v1/devService/getDevicePoints"
|
|
45
|
+
ENDPOINT_QUERY_FAULT_LIST = "/v1/faultService/queryFaultList"
|
|
46
|
+
ENDPOINT_GET_CHARGING_PILE_LIST = "/v1/devService/getChargingPileList"
|
|
47
|
+
ENDPOINT_GET_PS_BATTERY_INFO = "/v1/powerStationService/getPsBatteryInfo"
|
|
48
|
+
ENDPOINT_GET_PS_WEATHER_INFO = "/v1/powerStationService/getPsWeatherInfo"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""AES-256-ECB + RSA PKCS#1 v1.5 wire cryptography for iSolarCloud."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import secrets
|
|
7
|
+
import string
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
|
|
10
|
+
from cryptography.hazmat.primitives import padding as sym_padding
|
|
11
|
+
from cryptography.hazmat.primitives.asymmetric import padding as asym_padding
|
|
12
|
+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
|
|
13
|
+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
14
|
+
from cryptography.hazmat.primitives.serialization import load_der_public_key
|
|
15
|
+
|
|
16
|
+
from .const import RSA_PUBLIC_KEY_B64URL
|
|
17
|
+
|
|
18
|
+
_ALPHANUM = string.ascii_lowercase + string.digits
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def load_rsa_public_key(b64url_der: str = RSA_PUBLIC_KEY_B64URL) -> RSAPublicKey:
|
|
22
|
+
"""Load the iSolarCloud DER RSA public key from URL-safe base64."""
|
|
23
|
+
padded = b64url_der + "=" * (-len(b64url_der) % 4)
|
|
24
|
+
der = base64.urlsafe_b64decode(padded)
|
|
25
|
+
key = load_der_public_key(der)
|
|
26
|
+
if not isinstance(key, RSAPublicKey):
|
|
27
|
+
raise TypeError("Expected an RSA public key")
|
|
28
|
+
return key
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def generate_aes_key() -> str:
|
|
32
|
+
"""Generate a 32-character AES key prefixed with 'web'."""
|
|
33
|
+
suffix = "".join(secrets.choice(_ALPHANUM) for _ in range(29))
|
|
34
|
+
return f"web{suffix}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def generate_nonce(length: int = 32) -> str:
|
|
38
|
+
"""Generate a random alphanumeric nonce."""
|
|
39
|
+
return "".join(secrets.choice(_ALPHANUM) for _ in range(length))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def generate_did() -> str:
|
|
43
|
+
"""Generate a 16-digit device identifier header value."""
|
|
44
|
+
return "".join(secrets.choice(string.digits) for _ in range(16))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def aes_encrypt_hex(plaintext: str, key: str) -> str:
|
|
48
|
+
"""Encrypt UTF-8 plaintext with AES-ECB PKCS7 and return lowercase hex."""
|
|
49
|
+
key_bytes = key.encode("utf-8")
|
|
50
|
+
if len(key_bytes) not in (16, 24, 32):
|
|
51
|
+
raise ValueError(f"AES key must be 16/24/32 bytes, got {len(key_bytes)}")
|
|
52
|
+
padder = sym_padding.PKCS7(128).padder()
|
|
53
|
+
padded = padder.update(plaintext.encode("utf-8")) + padder.finalize()
|
|
54
|
+
encryptor = Cipher(algorithms.AES(key_bytes), modes.ECB()).encryptor()
|
|
55
|
+
encrypted = encryptor.update(padded) + encryptor.finalize()
|
|
56
|
+
return encrypted.hex()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def aes_decrypt_hex(cipher_hex: str, key: str) -> str:
|
|
60
|
+
"""Decrypt hex-encoded AES-ECB PKCS7 ciphertext to UTF-8 text."""
|
|
61
|
+
key_bytes = key.encode("utf-8")
|
|
62
|
+
if len(key_bytes) not in (16, 24, 32):
|
|
63
|
+
raise ValueError(f"AES key must be 16/24/32 bytes, got {len(key_bytes)}")
|
|
64
|
+
raw = bytes.fromhex(cipher_hex.strip())
|
|
65
|
+
decryptor = Cipher(algorithms.AES(key_bytes), modes.ECB()).decryptor()
|
|
66
|
+
padded = decryptor.update(raw) + decryptor.finalize()
|
|
67
|
+
unpadder = sym_padding.PKCS7(128).unpadder()
|
|
68
|
+
plain = unpadder.update(padded) + unpadder.finalize()
|
|
69
|
+
return plain.decode("utf-8")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def rsa_encrypt_base64(plaintext: str, public_key: RSAPublicKey | None = None) -> str:
|
|
73
|
+
"""Encrypt plaintext using RSA PKCS#1 v1.5 and return standard base64."""
|
|
74
|
+
key = public_key or load_rsa_public_key()
|
|
75
|
+
encrypted = key.encrypt(plaintext.encode("utf-8"), asym_padding.PKCS1v15())
|
|
76
|
+
return base64.b64encode(encrypted).decode("ascii")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def current_gmt_header(now: datetime | None = None) -> str:
|
|
80
|
+
"""Format the x-client-tz header matching iSolarCloud's expectation."""
|
|
81
|
+
current = now or datetime.now().astimezone()
|
|
82
|
+
offset = current.utcoffset()
|
|
83
|
+
total_seconds = int(offset.total_seconds()) if offset is not None else 0
|
|
84
|
+
hours = int(total_seconds / 3600)
|
|
85
|
+
if hours >= 0:
|
|
86
|
+
return f"GMT%2B{hours}"
|
|
87
|
+
return f"GMT-{abs(hours)}"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def current_timestamp_ms(clock_offset_seconds: float = 0.0) -> int:
|
|
91
|
+
"""Return current UTC epoch milliseconds adjusted by any learned clock offset."""
|
|
92
|
+
now_s = datetime.now(UTC).timestamp() + clock_offset_seconds
|
|
93
|
+
return int(now_s * 1000)
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
"""Typed models and unit normalization for iSolarCloud responses."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
_UNIT_MAP: dict[str, str] = {
|
|
10
|
+
"℃": "°C",
|
|
11
|
+
"C": "°C",
|
|
12
|
+
"℉": "°F",
|
|
13
|
+
"F": "°F",
|
|
14
|
+
"kvar": "var",
|
|
15
|
+
"KVAR": "var",
|
|
16
|
+
"W/㎡": "W/m²",
|
|
17
|
+
"Wh/㎡": "Wh/m²",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def normalize_unit(unit: str | None) -> str | None:
|
|
22
|
+
"""Normalize Sungrow unit strings to Home Assistant canonical units."""
|
|
23
|
+
if unit is None:
|
|
24
|
+
return None
|
|
25
|
+
cleaned = unit.strip()
|
|
26
|
+
if not cleaned or cleaned == "--":
|
|
27
|
+
return None
|
|
28
|
+
return _UNIT_MAP.get(cleaned, cleaned)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def parse_float(raw: Any) -> float | None:
|
|
32
|
+
"""Parse numeric API values safely, treating '--' and blanks as None."""
|
|
33
|
+
if raw is None or isinstance(raw, bool):
|
|
34
|
+
return None
|
|
35
|
+
if isinstance(raw, (int, float)):
|
|
36
|
+
return float(raw)
|
|
37
|
+
text = str(raw).strip()
|
|
38
|
+
if not text or text == "--":
|
|
39
|
+
return None
|
|
40
|
+
try:
|
|
41
|
+
return float(text)
|
|
42
|
+
except ValueError:
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(slots=True)
|
|
47
|
+
class AuthSession:
|
|
48
|
+
"""Authenticated iSolarCloud session details."""
|
|
49
|
+
|
|
50
|
+
token: str
|
|
51
|
+
user_id: str
|
|
52
|
+
gateway: str
|
|
53
|
+
login_at: datetime
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(slots=True)
|
|
57
|
+
class ValueUnit:
|
|
58
|
+
"""Typed value + normalized unit extracted from iSolarCloud maps."""
|
|
59
|
+
|
|
60
|
+
value: float | None
|
|
61
|
+
unit: str | None = None
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def from_raw(cls, raw: Any, default_unit: str | None = None) -> ValueUnit:
|
|
65
|
+
"""Parse either a {value, unit} dict or a scalar value."""
|
|
66
|
+
if isinstance(raw, dict):
|
|
67
|
+
val = parse_float(raw.get("value"))
|
|
68
|
+
unit = normalize_unit(raw.get("unit")) or normalize_unit(default_unit)
|
|
69
|
+
return cls(value=val, unit=unit)
|
|
70
|
+
return cls(value=parse_float(raw), unit=normalize_unit(default_unit))
|
|
71
|
+
|
|
72
|
+
def in_kw(self) -> ValueUnit:
|
|
73
|
+
"""Convert W/kW/MW value to canonical kW."""
|
|
74
|
+
if self.value is None:
|
|
75
|
+
return ValueUnit(None, "kW")
|
|
76
|
+
if self.unit == "W":
|
|
77
|
+
return ValueUnit(round(self.value / 1000.0, 4), "kW")
|
|
78
|
+
if self.unit == "MW":
|
|
79
|
+
return ValueUnit(round(self.value * 1000.0, 4), "kW")
|
|
80
|
+
return ValueUnit(self.value, "kW")
|
|
81
|
+
|
|
82
|
+
def in_kwh(self) -> ValueUnit:
|
|
83
|
+
"""Convert Wh/kWh/MWh value to canonical kWh."""
|
|
84
|
+
if self.value is None:
|
|
85
|
+
return ValueUnit(None, "kWh")
|
|
86
|
+
if self.unit == "Wh":
|
|
87
|
+
return ValueUnit(round(self.value / 1000.0, 4), "kWh")
|
|
88
|
+
if self.unit == "MWh":
|
|
89
|
+
return ValueUnit(round(self.value * 1000.0, 4), "kWh")
|
|
90
|
+
return ValueUnit(self.value, "kWh")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass(slots=True)
|
|
94
|
+
class PlantSummary:
|
|
95
|
+
"""Plant metadata from getPsList."""
|
|
96
|
+
|
|
97
|
+
ps_id: str
|
|
98
|
+
ps_name: str
|
|
99
|
+
ps_status: int | None = None
|
|
100
|
+
ps_type: int | None = None
|
|
101
|
+
design_capacity_kwp: float | None = None
|
|
102
|
+
timezone: str | None = None
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def is_online(self) -> bool:
|
|
106
|
+
"""Return True when plant status indicates normal/online operation."""
|
|
107
|
+
return self.ps_status == 1
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def status_text(self) -> str | None:
|
|
111
|
+
"""Return human-readable plant status."""
|
|
112
|
+
if self.ps_status is None:
|
|
113
|
+
return None
|
|
114
|
+
return {0: "Offline", 1: "Normal", 2: "Fault"}.get(
|
|
115
|
+
self.ps_status, f"Status {self.ps_status}"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
@classmethod
|
|
119
|
+
def from_dict(cls, data: dict[str, Any]) -> PlantSummary:
|
|
120
|
+
"""Build PlantSummary from a getPsList item."""
|
|
121
|
+
cap = ValueUnit.from_raw(data.get("design_capacity"), "kWp")
|
|
122
|
+
if cap.value is None:
|
|
123
|
+
cap = ValueUnit.from_raw(data.get("total_capcity"), "kWp")
|
|
124
|
+
status_raw = parse_float(data.get("ps_status"))
|
|
125
|
+
ps_type_raw = parse_float(data.get("ps_type"))
|
|
126
|
+
return cls(
|
|
127
|
+
ps_id=str(data.get("ps_id", "")),
|
|
128
|
+
ps_name=str(data.get("ps_name") or data.get("ps_id") or "iSolarCloud Plant"),
|
|
129
|
+
ps_status=int(status_raw) if status_raw is not None else None,
|
|
130
|
+
ps_type=int(ps_type_raw) if ps_type_raw is not None else None,
|
|
131
|
+
design_capacity_kwp=cap.value,
|
|
132
|
+
timezone=data.get("time_zone") or data.get("ps_time_zone"),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@dataclass(slots=True)
|
|
137
|
+
class PlantFlow:
|
|
138
|
+
"""Curated plant power flow & energy metrics from getPsDetailWithPsType."""
|
|
139
|
+
|
|
140
|
+
pv_power: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kW"))
|
|
141
|
+
load_power: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kW"))
|
|
142
|
+
grid_power: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kW"))
|
|
143
|
+
battery_power: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kW"))
|
|
144
|
+
battery_soc: float | None = None
|
|
145
|
+
daily_pv_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
146
|
+
total_pv_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
147
|
+
daily_battery_charge: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
148
|
+
total_battery_charge: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
149
|
+
daily_battery_discharge: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
150
|
+
total_battery_discharge: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
151
|
+
daily_grid_import: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
152
|
+
total_grid_import: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
153
|
+
daily_grid_export: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
154
|
+
total_grid_export: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
155
|
+
daily_load_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
156
|
+
total_load_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
157
|
+
month_pv_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
158
|
+
daily_self_consumption_energy: ValueUnit = field(default_factory=lambda: ValueUnit(None, "kWh"))
|
|
159
|
+
today_income: ValueUnit = field(default_factory=lambda: ValueUnit(None, "EUR"))
|
|
160
|
+
total_income: ValueUnit = field(default_factory=lambda: ValueUnit(None, "EUR"))
|
|
161
|
+
co2_reduced_total: ValueUnit = field(default_factory=lambda: ValueUnit(None, "t"))
|
|
162
|
+
design_capacity_kwp: float | None = None
|
|
163
|
+
last_update_time: str | None = None
|
|
164
|
+
ps_fault_status: str | None = None
|
|
165
|
+
has_charging_pile: bool = False
|
|
166
|
+
|
|
167
|
+
@property
|
|
168
|
+
def has_fault(self) -> bool:
|
|
169
|
+
"""Return True when plant fault status indicates an active fault or alarm."""
|
|
170
|
+
return self.ps_fault_status in ("1", "2")
|
|
171
|
+
|
|
172
|
+
@property
|
|
173
|
+
def grid_import_power_kw(self) -> float | None:
|
|
174
|
+
"""Return positive grid import power in kW (0.0 when exporting)."""
|
|
175
|
+
if self.grid_power.value is None:
|
|
176
|
+
return None
|
|
177
|
+
return round(max(self.grid_power.value, 0.0), 4) + 0.0
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def grid_export_power_kw(self) -> float | None:
|
|
181
|
+
"""Return positive grid export power in kW (0.0 when importing)."""
|
|
182
|
+
if self.grid_power.value is None:
|
|
183
|
+
return None
|
|
184
|
+
return round(max(-self.grid_power.value, 0.0), 4) + 0.0
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def battery_charge_power_kw(self) -> float | None:
|
|
188
|
+
"""Return positive battery charging power in kW (0.0 when discharging)."""
|
|
189
|
+
if self.battery_power.value is None:
|
|
190
|
+
return None
|
|
191
|
+
return round(max(self.battery_power.value, 0.0), 4) + 0.0
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def battery_discharge_power_kw(self) -> float | None:
|
|
195
|
+
"""Return positive battery discharging power in kW (0.0 when charging)."""
|
|
196
|
+
if self.battery_power.value is None:
|
|
197
|
+
return None
|
|
198
|
+
return round(max(-self.battery_power.value, 0.0), 4) + 0.0
|
|
199
|
+
|
|
200
|
+
@classmethod
|
|
201
|
+
def from_detail_dict(cls, data: dict[str, Any]) -> PlantFlow:
|
|
202
|
+
"""Parse PsDetailBeanOversea fields into PlantFlow with canonical kW/kWh units."""
|
|
203
|
+
pv = ValueUnit.from_raw(
|
|
204
|
+
data.get("pv_power_map") or data.get("curr_power"),
|
|
205
|
+
"kW",
|
|
206
|
+
).in_kw()
|
|
207
|
+
load = ValueUnit.from_raw(data.get("load_power_map"), "kW").in_kw()
|
|
208
|
+
grid = ValueUnit.from_raw(data.get("power_grid_power_map"), "kW").in_kw()
|
|
209
|
+
battery = ValueUnit.from_raw(
|
|
210
|
+
data.get("charging_discharging_power_map") or data.get("es_active_power_map"),
|
|
211
|
+
"kW",
|
|
212
|
+
).in_kw()
|
|
213
|
+
soc = parse_float(data.get("battery_level_percent"))
|
|
214
|
+
cap = ValueUnit.from_raw(data.get("design_capacity"), "kWp")
|
|
215
|
+
|
|
216
|
+
daily_pv = ValueUnit.from_raw(
|
|
217
|
+
data.get("today_energy_virgin")
|
|
218
|
+
or data.get("today_energy")
|
|
219
|
+
or data.get("pv_energy_map"),
|
|
220
|
+
"kWh",
|
|
221
|
+
).in_kwh()
|
|
222
|
+
total_pv = ValueUnit.from_raw(
|
|
223
|
+
data.get("total_energy_virgin") or data.get("total_energy"),
|
|
224
|
+
"kWh",
|
|
225
|
+
).in_kwh()
|
|
226
|
+
|
|
227
|
+
return cls(
|
|
228
|
+
pv_power=pv,
|
|
229
|
+
load_power=load,
|
|
230
|
+
grid_power=grid,
|
|
231
|
+
battery_power=battery,
|
|
232
|
+
battery_soc=soc,
|
|
233
|
+
daily_pv_energy=daily_pv,
|
|
234
|
+
total_pv_energy=total_pv,
|
|
235
|
+
daily_battery_charge=ValueUnit.from_raw(
|
|
236
|
+
data.get("battery_charge_energy_map")
|
|
237
|
+
or data.get("dc_charge_today_energy")
|
|
238
|
+
or data.get("today_es_charge_energy"),
|
|
239
|
+
"kWh",
|
|
240
|
+
).in_kwh(),
|
|
241
|
+
total_battery_charge=ValueUnit.from_raw(
|
|
242
|
+
data.get("dc_charge_total_energy") or data.get("total_es_charge_energy"),
|
|
243
|
+
"kWh",
|
|
244
|
+
).in_kwh(),
|
|
245
|
+
daily_battery_discharge=ValueUnit.from_raw(
|
|
246
|
+
data.get("battery_discharge_energy_map") or data.get("today_es_discharge_energy"),
|
|
247
|
+
"kWh",
|
|
248
|
+
).in_kwh(),
|
|
249
|
+
total_battery_discharge=ValueUnit.from_raw(
|
|
250
|
+
data.get("total_es_discharge_energy"),
|
|
251
|
+
"kWh",
|
|
252
|
+
).in_kwh(),
|
|
253
|
+
daily_grid_import=ValueUnit.from_raw(
|
|
254
|
+
data.get("purchased_energy_map") or data.get("today_buy_energy"),
|
|
255
|
+
"kWh",
|
|
256
|
+
).in_kwh(),
|
|
257
|
+
total_grid_import=ValueUnit.from_raw(
|
|
258
|
+
data.get("total_buy_energy"),
|
|
259
|
+
"kWh",
|
|
260
|
+
).in_kwh(),
|
|
261
|
+
daily_grid_export=ValueUnit.from_raw(
|
|
262
|
+
data.get("feed_in_energy_map") or data.get("today_sell_energy"),
|
|
263
|
+
"kWh",
|
|
264
|
+
).in_kwh(),
|
|
265
|
+
total_grid_export=ValueUnit.from_raw(
|
|
266
|
+
data.get("total_sell_energy"),
|
|
267
|
+
"kWh",
|
|
268
|
+
).in_kwh(),
|
|
269
|
+
daily_load_energy=ValueUnit.from_raw(
|
|
270
|
+
data.get("load_energy_map") or data.get("today_use_energy"),
|
|
271
|
+
"kWh",
|
|
272
|
+
).in_kwh(),
|
|
273
|
+
total_load_energy=ValueUnit.from_raw(
|
|
274
|
+
data.get("total_use_energy")
|
|
275
|
+
or data.get("p83124_map_virgin")
|
|
276
|
+
or data.get("p83124_map"),
|
|
277
|
+
"kWh",
|
|
278
|
+
).in_kwh(),
|
|
279
|
+
month_pv_energy=ValueUnit.from_raw(
|
|
280
|
+
data.get("month_energy_virgin") or data.get("month_energy"),
|
|
281
|
+
"kWh",
|
|
282
|
+
).in_kwh(),
|
|
283
|
+
daily_self_consumption_energy=ValueUnit.from_raw(
|
|
284
|
+
data.get("zfzy_map_virgin") or data.get("zfzy_map"),
|
|
285
|
+
"kWh",
|
|
286
|
+
).in_kwh(),
|
|
287
|
+
today_income=ValueUnit.from_raw(data.get("today_income"), "EUR"),
|
|
288
|
+
total_income=ValueUnit.from_raw(data.get("total_income"), "EUR"),
|
|
289
|
+
co2_reduced_total=ValueUnit.from_raw(data.get("co2_reduce_total"), "t"),
|
|
290
|
+
design_capacity_kwp=cap.value,
|
|
291
|
+
last_update_time=data.get("data_last_update_time") or data.get("update_time"),
|
|
292
|
+
ps_fault_status=(
|
|
293
|
+
str(data.get("ps_fault_status"))
|
|
294
|
+
if data.get("ps_fault_status") is not None
|
|
295
|
+
else None
|
|
296
|
+
),
|
|
297
|
+
has_charging_pile=bool(
|
|
298
|
+
int(
|
|
299
|
+
parse_float(
|
|
300
|
+
data.get("has_charging_pile")
|
|
301
|
+
or (data.get("ps_energy_graph_data") or {}).get("has_charging_pile")
|
|
302
|
+
)
|
|
303
|
+
or 0
|
|
304
|
+
)
|
|
305
|
+
),
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
@dataclass(slots=True)
|
|
310
|
+
class DevicePoint:
|
|
311
|
+
"""Generic curated device telemetry point from /v1/devService/getDevicePoints."""
|
|
312
|
+
|
|
313
|
+
point_id: int
|
|
314
|
+
name: str
|
|
315
|
+
value: float | str | None
|
|
316
|
+
unit: str | None = None
|
|
317
|
+
is_numeric: bool = False
|
|
318
|
+
is_enum: bool = False
|
|
319
|
+
|
|
320
|
+
@classmethod
|
|
321
|
+
def from_dict(cls, data: dict[str, Any]) -> DevicePoint | None:
|
|
322
|
+
"""Parse one getDevicePoints row, returning None for unsupported '--' points."""
|
|
323
|
+
point_id_raw = data.get("point_id")
|
|
324
|
+
if point_id_raw is None:
|
|
325
|
+
return None
|
|
326
|
+
try:
|
|
327
|
+
point_id = int(point_id_raw)
|
|
328
|
+
except (TypeError, ValueError):
|
|
329
|
+
return None
|
|
330
|
+
|
|
331
|
+
raw_val = data.get("value")
|
|
332
|
+
if raw_val is None or str(raw_val).strip() in ("", "--"):
|
|
333
|
+
return None
|
|
334
|
+
|
|
335
|
+
name = str(
|
|
336
|
+
data.get("alias_point_name") or data.get("point_name") or f"Point {point_id}"
|
|
337
|
+
).strip()
|
|
338
|
+
unit = normalize_unit(data.get("unit"))
|
|
339
|
+
is_enum = str(data.get("flag") or "").lower() == "enum"
|
|
340
|
+
|
|
341
|
+
parsed_num = None if is_enum else parse_float(raw_val)
|
|
342
|
+
if parsed_num is not None:
|
|
343
|
+
return cls(
|
|
344
|
+
point_id=point_id,
|
|
345
|
+
name=name,
|
|
346
|
+
value=parsed_num,
|
|
347
|
+
unit=unit,
|
|
348
|
+
is_numeric=True,
|
|
349
|
+
is_enum=False,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
desc = str(data.get("value_description") or "").strip()
|
|
353
|
+
text_val = desc if desc and is_enum else str(raw_val).strip()
|
|
354
|
+
return cls(
|
|
355
|
+
point_id=point_id,
|
|
356
|
+
name=name,
|
|
357
|
+
value=text_val,
|
|
358
|
+
unit=None,
|
|
359
|
+
is_numeric=False,
|
|
360
|
+
is_enum=is_enum,
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
@dataclass(slots=True)
|
|
365
|
+
class DeviceSummary:
|
|
366
|
+
"""Device inventory entry from getPsAllDeviceList."""
|
|
367
|
+
|
|
368
|
+
ps_id: str
|
|
369
|
+
ps_key: str
|
|
370
|
+
uuid: str
|
|
371
|
+
device_name: str
|
|
372
|
+
device_model: str | None = None
|
|
373
|
+
device_sn: str | None = None
|
|
374
|
+
device_type: int | None = None
|
|
375
|
+
dev_status: int | None = None
|
|
376
|
+
fault_status: str | None = None
|
|
377
|
+
firmware_version: str | None = None
|
|
378
|
+
points: dict[int, DevicePoint] = field(default_factory=dict)
|
|
379
|
+
|
|
380
|
+
@property
|
|
381
|
+
def is_online(self) -> bool:
|
|
382
|
+
"""Return True when device status indicates online/normal."""
|
|
383
|
+
return self.dev_status == 1
|
|
384
|
+
|
|
385
|
+
@property
|
|
386
|
+
def has_fault(self) -> bool:
|
|
387
|
+
"""Return True when device fault status indicates an active fault or alarm."""
|
|
388
|
+
return self.fault_status in ("1", "2")
|
|
389
|
+
|
|
390
|
+
@classmethod
|
|
391
|
+
def from_dict(cls, ps_id: str, data: dict[str, Any]) -> DeviceSummary:
|
|
392
|
+
"""Build DeviceSummary from a getPsAllDeviceList row."""
|
|
393
|
+
dev_type_raw = parse_float(data.get("device_type"))
|
|
394
|
+
status_raw = parse_float(
|
|
395
|
+
data.get("device_status")
|
|
396
|
+
if data.get("device_status") is not None
|
|
397
|
+
else (data.get("dev_status") or data.get("dev_run_status"))
|
|
398
|
+
)
|
|
399
|
+
ps_key = str(data.get("ps_key") or data.get("uuid") or "")
|
|
400
|
+
return cls(
|
|
401
|
+
ps_id=str(data.get("ps_id") or ps_id),
|
|
402
|
+
ps_key=ps_key,
|
|
403
|
+
uuid=str(data.get("uuid") or ps_key),
|
|
404
|
+
device_name=str(data.get("device_name") or data.get("device_model") or ps_key),
|
|
405
|
+
device_model=data.get("device_model") or data.get("type_name"),
|
|
406
|
+
device_sn=data.get("device_sn") or data.get("sn"),
|
|
407
|
+
device_type=int(dev_type_raw) if dev_type_raw is not None else None,
|
|
408
|
+
dev_status=int(status_raw) if status_raw is not None else None,
|
|
409
|
+
fault_status=(
|
|
410
|
+
str(data.get("fault_status")) if data.get("fault_status") is not None else None
|
|
411
|
+
),
|
|
412
|
+
firmware_version=data.get("firmware_version_info") or data.get("soft_version"),
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
@dataclass(slots=True)
|
|
417
|
+
class ActiveFault:
|
|
418
|
+
"""Active fault/alarm entry from /v1/faultService/queryFaultList."""
|
|
419
|
+
|
|
420
|
+
fault_code: str | None = None
|
|
421
|
+
fault_name: str | None = None
|
|
422
|
+
fault_level: str | None = None
|
|
423
|
+
device_name: str | None = None
|
|
424
|
+
ps_key: str | None = None
|
|
425
|
+
occur_time: str | None = None
|
|
426
|
+
|
|
427
|
+
@classmethod
|
|
428
|
+
def from_dict(cls, data: dict[str, Any]) -> ActiveFault:
|
|
429
|
+
"""Parse a fault row into ActiveFault."""
|
|
430
|
+
return cls(
|
|
431
|
+
fault_code=(
|
|
432
|
+
str(data.get("fault_code")) if data.get("fault_code") is not None else None
|
|
433
|
+
),
|
|
434
|
+
fault_name=data.get("fault_name") or data.get("fault_desc"),
|
|
435
|
+
fault_level=(
|
|
436
|
+
str(data.get("fault_level_name") or data.get("fault_level"))
|
|
437
|
+
if (data.get("fault_level_name") or data.get("fault_level")) is not None
|
|
438
|
+
else None
|
|
439
|
+
),
|
|
440
|
+
device_name=data.get("device_name"),
|
|
441
|
+
ps_key=str(data.get("ps_key")) if data.get("ps_key") is not None else None,
|
|
442
|
+
occur_time=data.get("create_time") or data.get("occur_time"),
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
@dataclass(slots=True)
|
|
447
|
+
class PlantWeather:
|
|
448
|
+
"""Local plant weather from /v1/powerStationService/getPsWeatherInfo."""
|
|
449
|
+
|
|
450
|
+
temperature_c: float | None = None
|
|
451
|
+
high_temperature_c: float | None = None
|
|
452
|
+
low_temperature_c: float | None = None
|
|
453
|
+
sunrise: str | None = None
|
|
454
|
+
weather_code: str | None = None
|
|
455
|
+
|
|
456
|
+
@classmethod
|
|
457
|
+
def from_dict(cls, data: dict[str, Any]) -> PlantWeather:
|
|
458
|
+
"""Parse getPsWeatherInfo result_data into PlantWeather."""
|
|
459
|
+
w_map = data.get("weather_map") or {}
|
|
460
|
+
w_list = data.get("weather_info_list") or []
|
|
461
|
+
today = w_list[0] if isinstance(w_list, list) and w_list else {}
|
|
462
|
+
temp = parse_float(
|
|
463
|
+
w_map.get("current_temperature_c")
|
|
464
|
+
if w_map.get("current_temperature_c") is not None
|
|
465
|
+
else today.get("current_temperature")
|
|
466
|
+
)
|
|
467
|
+
return cls(
|
|
468
|
+
temperature_c=temp,
|
|
469
|
+
high_temperature_c=parse_float(today.get("high_temperature")),
|
|
470
|
+
low_temperature_c=parse_float(today.get("low_temperature")),
|
|
471
|
+
sunrise=w_map.get("sunrise"),
|
|
472
|
+
weather_code=(
|
|
473
|
+
str(w_map.get("weather_code") or today.get("weather_code"))
|
|
474
|
+
if (w_map.get("weather_code") or today.get("weather_code")) is not None
|
|
475
|
+
else None
|
|
476
|
+
),
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
@dataclass(slots=True)
|
|
481
|
+
class ChargingPileSummary:
|
|
482
|
+
"""EV charger summary from /v1/devService/getChargingPileList."""
|
|
483
|
+
|
|
484
|
+
pile_sn: str
|
|
485
|
+
pile_name: str
|
|
486
|
+
status: str | None = None
|
|
487
|
+
charging_power_kw: float | None = None
|
|
488
|
+
charging_energy_kwh: float | None = None
|
|
489
|
+
|
|
490
|
+
@classmethod
|
|
491
|
+
def from_dict(cls, data: dict[str, Any]) -> ChargingPileSummary:
|
|
492
|
+
"""Parse a charging pile row into ChargingPileSummary."""
|
|
493
|
+
sn = str(data.get("charging_pile_sn") or data.get("sn") or data.get("uuid") or "")
|
|
494
|
+
power = ValueUnit.from_raw(data.get("charging_power"), "kW").in_kw()
|
|
495
|
+
energy = ValueUnit.from_raw(data.get("charging_energy"), "kWh").in_kwh()
|
|
496
|
+
return cls(
|
|
497
|
+
pile_sn=sn,
|
|
498
|
+
pile_name=str(data.get("charging_pile_name") or sn or "EV Charger"),
|
|
499
|
+
status=(
|
|
500
|
+
str(data.get("charging_pile_status"))
|
|
501
|
+
if data.get("charging_pile_status") is not None
|
|
502
|
+
else None
|
|
503
|
+
),
|
|
504
|
+
charging_power_kw=power.value,
|
|
505
|
+
charging_energy_kwh=energy.value,
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
@dataclass(slots=True)
|
|
510
|
+
class PlantData:
|
|
511
|
+
"""Combined plant snapshot consumed by Home Assistant entities."""
|
|
512
|
+
|
|
513
|
+
summary: PlantSummary
|
|
514
|
+
flow: PlantFlow
|
|
515
|
+
devices: list[DeviceSummary] = field(default_factory=list)
|
|
516
|
+
active_faults: list[ActiveFault] = field(default_factory=list)
|
|
517
|
+
weather: PlantWeather | None = None
|
|
518
|
+
charging_piles: list[ChargingPileSummary] = field(default_factory=list)
|
|
519
|
+
battery_info: dict[str, Any] | None = None
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-sungrow-isolarcloud
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async Python client library for the Sungrow iSolarCloud API
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/skamoll/py-sungrow-isolarcloud
|
|
7
|
+
Project-URL: Repository, https://github.com/skamoll/py-sungrow-isolarcloud
|
|
8
|
+
Project-URL: Issues, https://github.com/skamoll/py-sungrow-isolarcloud/issues
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
13
|
+
Requires-Dist: cryptography>=42.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
17
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# py-sungrow-isolarcloud
|
|
21
|
+
|
|
22
|
+
[](https://github.com/skamoll/py-sungrow-isolarcloud/actions/workflows/ci.yml)
|
|
23
|
+
[](LICENSE)
|
|
24
|
+
|
|
25
|
+
Typed, asynchronous Python client library for the **Sungrow iSolarCloud** cloud API.
|
|
26
|
+
|
|
27
|
+
For the Home Assistant custom integration (HACS) built on top of this library, see [`skamoll/hass_sungrow_isolarcloud`](https://github.com/skamoll/hass_sungrow_isolarcloud).
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- **Encrypted Wire Protocol:** RSA PKCS#1 v1.5 key exchange + AES-128-ECB payload encryption/decryption with automatic clock-skew (`Expired request`) and session-expiry recovery.
|
|
32
|
+
- **Regional Gateway Auto-Discovery:** Supports `auto` probing across `eu`, `com`, `au`, `hk`, `cn`, and `in`, or explicit regional selection.
|
|
33
|
+
- **Ecosystem-Wide Models:** Parses plant summaries (`PlantSummary`), energy flows & directional powers (`PlantFlow`), device inventories (`DeviceSummary`), dynamic per-device telemetry (`DevicePoint`), conditional active faults (`ActiveFault`), local plant weather (`PlantWeather`), and EV chargers (`ChargingPileSummary`).
|
|
34
|
+
- **Canonical Units & Locale Support:** Normalizes power (`W`/`kW`/`MW` -> `kW`), energy (`Wh`/`kWh`/`MWh` -> `kWh`), temperatures (`°C`/`°F`), and reactive/apparent power (`var`/`VA`), with iSolarCloud `lang` support (`_en_US`, `_es_ES`, `_de_DE`, `_fr_FR`, etc.).
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install py-sungrow-isolarcloud
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import asyncio
|
|
46
|
+
import aiohttp
|
|
47
|
+
from py_sungrow_isolarcloud import GATEWAY_AUTO, ISolarCloudClient
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def main() -> None:
|
|
51
|
+
async with aiohttp.ClientSession() as session:
|
|
52
|
+
client = ISolarCloudClient(
|
|
53
|
+
session=session,
|
|
54
|
+
username="user@example.com",
|
|
55
|
+
password="your-password",
|
|
56
|
+
gateway=GATEWAY_AUTO,
|
|
57
|
+
lang="_en_US",
|
|
58
|
+
)
|
|
59
|
+
plants = await client.async_fetch_all_plants()
|
|
60
|
+
for ps_id, plant in plants.items():
|
|
61
|
+
print(ps_id, plant.summary.ps_name, plant.flow.pv_power)
|
|
62
|
+
for dev in plant.devices:
|
|
63
|
+
print(" ", dev.device_name, dev.device_model, len(dev.points), "points")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python -m venv .venv
|
|
73
|
+
source .venv/bin/activate
|
|
74
|
+
pip install -e ".[dev]"
|
|
75
|
+
ruff check . && ruff format --check .
|
|
76
|
+
pytest -v
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Contributing, Issues & Security
|
|
80
|
+
|
|
81
|
+
- **Contributing:** See [CONTRIBUTING.md](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
82
|
+
- **Reporting Bugs & Feature Requests:** Open an issue using the [GitHub Issue Templates](https://github.com/skamoll/py-sungrow-isolarcloud/issues/new/choose). Never include credentials, tokens, or personal plant IDs.
|
|
83
|
+
- **Security Vulnerabilities:** Please report privately via [SECURITY.md](SECURITY.md) instead of opening a public issue.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
py_sungrow_isolarcloud/__init__.py,sha256=6q1cO7OHWN-41lr8d2OQOIws5DPTlskrEPjlSc32AOY,824
|
|
2
|
+
py_sungrow_isolarcloud/client.py,sha256=AXTW5VExl0a2sgi9ARPGO8rNDKKb1Bis7xImUai7i1w,18030
|
|
3
|
+
py_sungrow_isolarcloud/const.py,sha256=tXv2TSl3_E3IgaMNUmHRZwXlrDBPqwEuMrs506lh4rQ,1884
|
|
4
|
+
py_sungrow_isolarcloud/crypto.py,sha256=ozgHujo_AUHHC7kWviYjwf0fu9qxklQyFIcQbBM2w48,3764
|
|
5
|
+
py_sungrow_isolarcloud/models.py,sha256=-3b02ZtH0OolZhQtn7WRGQ0xhv6AmBq7crmOYtpB-tE,19905
|
|
6
|
+
py_sungrow_isolarcloud/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
py_sungrow_isolarcloud-0.1.0.dist-info/licenses/LICENSE,sha256=95T5qs8RAS-yORRLrwj6plPQCbaS7DexgXiskV4RM3E,1063
|
|
8
|
+
py_sungrow_isolarcloud-0.1.0.dist-info/METADATA,sha256=bLxlfQ4936zJPnrKTZhxPdsZDE-Rr6IhizPt4wpDEPA,3668
|
|
9
|
+
py_sungrow_isolarcloud-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
py_sungrow_isolarcloud-0.1.0.dist-info/top_level.txt,sha256=a73blrZe_gmRzR7h62nfVP9AmvmqwYYfHcIIpI_am8U,23
|
|
11
|
+
py_sungrow_isolarcloud-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 skamoll
|
|
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 KIND, 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 @@
|
|
|
1
|
+
py_sungrow_isolarcloud
|