daybetter-services-python 1.0.5__tar.gz → 1.0.6__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.
- {daybetter_services_python-1.0.5/daybetter_services_python.egg-info → daybetter_services_python-1.0.6}/PKG-INFO +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_python/__init__.py +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_python/client.py +42 -3
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6/daybetter_services_python.egg-info}/PKG-INFO +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/pyproject.toml +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/setup.py +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/LICENSE +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/README.md +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_python/exceptions.py +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_services_python.egg-info/SOURCES.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_services_python.egg-info/dependency_links.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_services_python.egg-info/requires.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_services_python.egg-info/top_level.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/setup.cfg +0 -0
{daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_python/client.py
RENAMED
|
@@ -12,19 +12,40 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
12
12
|
class DayBetterClient:
|
|
13
13
|
"""DayBetter API client."""
|
|
14
14
|
|
|
15
|
+
# 测试环境URL
|
|
16
|
+
TEST_BASE_URL = "https://cloud.v2.dbiot.link/daybetter/hass/api/v1.0/"
|
|
17
|
+
# 正式环境URL
|
|
18
|
+
PROD_BASE_URL = "https://a.dbiot.org/daybetter/hass/api/v1.0/"
|
|
19
|
+
|
|
15
20
|
def __init__(
|
|
16
21
|
self,
|
|
17
22
|
token: str,
|
|
18
|
-
base_url: str =
|
|
23
|
+
base_url: Optional[str] = None,
|
|
24
|
+
hass_code: Optional[str] = None
|
|
19
25
|
):
|
|
20
26
|
"""Initialize the client.
|
|
21
27
|
|
|
22
28
|
Args:
|
|
23
29
|
token: Authentication token
|
|
24
|
-
base_url: Base URL for the API
|
|
30
|
+
base_url: Base URL for the API (optional, will be determined by hass_code if not provided)
|
|
31
|
+
hass_code: Home Assistant integration code (optional, if provided and starts with "db-",
|
|
32
|
+
will use production environment)
|
|
25
33
|
"""
|
|
26
34
|
self.token = token
|
|
27
|
-
|
|
35
|
+
|
|
36
|
+
# 根据 hass_code 或 base_url 确定使用的环境
|
|
37
|
+
if base_url is not None:
|
|
38
|
+
# 如果明确指定了 base_url,使用指定的 URL
|
|
39
|
+
self.base_url = base_url
|
|
40
|
+
elif hass_code is not None and hass_code.startswith("db-"):
|
|
41
|
+
# 如果 hass_code 以 "db-" 开头,使用正式环境
|
|
42
|
+
self.base_url = self.PROD_BASE_URL
|
|
43
|
+
_LOGGER.debug("Using production environment based on hass_code")
|
|
44
|
+
else:
|
|
45
|
+
# 默认使用测试环境
|
|
46
|
+
self.base_url = self.TEST_BASE_URL
|
|
47
|
+
_LOGGER.debug("Using test environment")
|
|
48
|
+
|
|
28
49
|
self._session: Optional[aiohttp.ClientSession] = None
|
|
29
50
|
self._auth_valid = True
|
|
30
51
|
self._devices: List[Dict[str, Any]] = []
|
|
@@ -306,6 +327,24 @@ class DayBetterClient:
|
|
|
306
327
|
Raises:
|
|
307
328
|
APIError: If API request fails
|
|
308
329
|
"""
|
|
330
|
+
# 根据 hass_code 动态更新 base_url(如果之前没有明确指定)
|
|
331
|
+
# 如果 hass_code 以 "db-" 开头,切换到正式环境
|
|
332
|
+
if hass_code.startswith("db-") and self.base_url != self.PROD_BASE_URL:
|
|
333
|
+
old_url = self.base_url
|
|
334
|
+
self.base_url = self.PROD_BASE_URL
|
|
335
|
+
_LOGGER.info(
|
|
336
|
+
"Switching to production environment based on hass_code. "
|
|
337
|
+
"URL changed from %s to %s", old_url, self.base_url
|
|
338
|
+
)
|
|
339
|
+
elif not hass_code.startswith("db-") and self.base_url != self.TEST_BASE_URL:
|
|
340
|
+
# 如果 hass_code 不以 "db-" 开头,且当前不是测试环境,切换到测试环境
|
|
341
|
+
old_url = self.base_url
|
|
342
|
+
self.base_url = self.TEST_BASE_URL
|
|
343
|
+
_LOGGER.info(
|
|
344
|
+
"Switching to test environment based on hass_code. "
|
|
345
|
+
"URL changed from %s to %s", old_url, self.base_url
|
|
346
|
+
)
|
|
347
|
+
|
|
309
348
|
try:
|
|
310
349
|
session = self._get_session()
|
|
311
350
|
url = f"{self.base_url}hass/integrate"
|
|
File without changes
|
|
File without changes
|
{daybetter_services_python-1.0.5 → daybetter_services_python-1.0.6}/daybetter_python/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|