daybetter-services-python 1.0.5__tar.gz → 1.0.7__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.7}/PKG-INFO +2 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_python/__init__.py +1 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_python/client.py +50 -6
- daybetter_services_python-1.0.7/daybetter_python/exceptions.py +38 -0
- daybetter_services_python-1.0.7/daybetter_python/py.typed +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7/daybetter_services_python.egg-info}/PKG-INFO +2 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_services_python.egg-info/SOURCES.txt +1 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/pyproject.toml +5 -1
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/setup.py +5 -1
- daybetter_services_python-1.0.5/daybetter_python/exceptions.py +0 -13
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/LICENSE +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/README.md +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_services_python.egg-info/dependency_links.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_services_python.egg-info/requires.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_services_python.egg-info/top_level.txt +0 -0
- {daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: daybetter-services-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.7
|
|
4
4
|
Summary: Python client for DayBetter devices and services
|
|
5
5
|
Home-page: https://github.com/THDayBetter/daybetter-python
|
|
6
6
|
Author: THDayBetter
|
|
@@ -21,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Typing :: Typed
|
|
24
25
|
Requires-Python: >=3.8
|
|
25
26
|
Description-Content-Type: text/markdown
|
|
26
27
|
License-File: LICENSE
|
{daybetter_services_python-1.0.5 → daybetter_services_python-1.0.7}/daybetter_python/client.py
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import aiohttp
|
|
4
4
|
import logging
|
|
5
|
-
from typing import Any, Dict, List, Optional, Tuple
|
|
5
|
+
from typing import Any, Dict, List, Optional, Tuple, Type
|
|
6
6
|
|
|
7
7
|
from .exceptions import DayBetterError, AuthenticationError, APIError
|
|
8
8
|
|
|
@@ -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]] = []
|
|
@@ -35,7 +56,12 @@ class DayBetterClient:
|
|
|
35
56
|
self._session = aiohttp.ClientSession()
|
|
36
57
|
return self
|
|
37
58
|
|
|
38
|
-
async def __aexit__(
|
|
59
|
+
async def __aexit__(
|
|
60
|
+
self,
|
|
61
|
+
exc_type: Optional[Type[BaseException]],
|
|
62
|
+
exc_val: Optional[BaseException],
|
|
63
|
+
exc_tb: Optional[Any],
|
|
64
|
+
) -> None:
|
|
39
65
|
"""Async context manager exit."""
|
|
40
66
|
if self._session:
|
|
41
67
|
await self._session.close()
|
|
@@ -306,6 +332,24 @@ class DayBetterClient:
|
|
|
306
332
|
Raises:
|
|
307
333
|
APIError: If API request fails
|
|
308
334
|
"""
|
|
335
|
+
# 根据 hass_code 动态更新 base_url(如果之前没有明确指定)
|
|
336
|
+
# 如果 hass_code 以 "db-" 开头,切换到正式环境
|
|
337
|
+
if hass_code.startswith("db-") and self.base_url != self.PROD_BASE_URL:
|
|
338
|
+
old_url = self.base_url
|
|
339
|
+
self.base_url = self.PROD_BASE_URL
|
|
340
|
+
_LOGGER.info(
|
|
341
|
+
"Switching to production environment based on hass_code. "
|
|
342
|
+
"URL changed from %s to %s", old_url, self.base_url
|
|
343
|
+
)
|
|
344
|
+
elif not hass_code.startswith("db-") and self.base_url != self.TEST_BASE_URL:
|
|
345
|
+
# 如果 hass_code 不以 "db-" 开头,且当前不是测试环境,切换到测试环境
|
|
346
|
+
old_url = self.base_url
|
|
347
|
+
self.base_url = self.TEST_BASE_URL
|
|
348
|
+
_LOGGER.info(
|
|
349
|
+
"Switching to test environment based on hass_code. "
|
|
350
|
+
"URL changed from %s to %s", old_url, self.base_url
|
|
351
|
+
)
|
|
352
|
+
|
|
309
353
|
try:
|
|
310
354
|
session = self._get_session()
|
|
311
355
|
url = f"{self.base_url}hass/integrate"
|
|
@@ -415,7 +459,7 @@ class DayBetterClient:
|
|
|
415
459
|
_LOGGER.debug("Fetched %d sensor devices", len(merged))
|
|
416
460
|
return merged
|
|
417
461
|
|
|
418
|
-
async def close(self):
|
|
462
|
+
async def close(self) -> None:
|
|
419
463
|
"""Close the client session."""
|
|
420
464
|
if self._session:
|
|
421
465
|
await self._session.close()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""DayBetter client exceptions."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DayBetterError(Exception):
|
|
5
|
+
"""Base exception for DayBetter client."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, message: str) -> None:
|
|
8
|
+
"""Initialize the exception.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
message: Error message
|
|
12
|
+
"""
|
|
13
|
+
super().__init__(message)
|
|
14
|
+
self.message = message
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AuthenticationError(DayBetterError):
|
|
18
|
+
"""Authentication failed."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, message: str = "Authentication failed") -> None:
|
|
21
|
+
"""Initialize the authentication error.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
message: Error message
|
|
25
|
+
"""
|
|
26
|
+
super().__init__(message)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class APIError(DayBetterError):
|
|
30
|
+
"""API request failed."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, message: str) -> None:
|
|
33
|
+
"""Initialize the API error.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
message: Error message
|
|
37
|
+
"""
|
|
38
|
+
super().__init__(message)
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: daybetter-services-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.7
|
|
4
4
|
Summary: Python client for DayBetter devices and services
|
|
5
5
|
Home-page: https://github.com/THDayBetter/daybetter-python
|
|
6
6
|
Author: THDayBetter
|
|
@@ -21,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Typing :: Typed
|
|
24
25
|
Requires-Python: >=3.8
|
|
25
26
|
Description-Content-Type: text/markdown
|
|
26
27
|
License-File: LICENSE
|
|
@@ -5,6 +5,7 @@ setup.py
|
|
|
5
5
|
daybetter_python/__init__.py
|
|
6
6
|
daybetter_python/client.py
|
|
7
7
|
daybetter_python/exceptions.py
|
|
8
|
+
daybetter_python/py.typed
|
|
8
9
|
daybetter_services_python.egg-info/PKG-INFO
|
|
9
10
|
daybetter_services_python.egg-info/SOURCES.txt
|
|
10
11
|
daybetter_services_python.egg-info/dependency_links.txt
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "daybetter-services-python"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.7"
|
|
8
8
|
description = "Python client for DayBetter devices and services"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -25,6 +25,7 @@ classifiers = [
|
|
|
25
25
|
"Programming Language :: Python :: 3.10",
|
|
26
26
|
"Programming Language :: Python :: 3.11",
|
|
27
27
|
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Typing :: Typed",
|
|
28
29
|
]
|
|
29
30
|
requires-python = ">=3.8"
|
|
30
31
|
dependencies = [
|
|
@@ -55,3 +56,6 @@ target-version = ['py38']
|
|
|
55
56
|
[tool.isort]
|
|
56
57
|
profile = "black"
|
|
57
58
|
line_length = 88
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.package-data]
|
|
61
|
+
daybetter_python = ["py.typed"]
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="daybetter-services-python",
|
|
8
|
-
version="1.0.
|
|
8
|
+
version="1.0.7",
|
|
9
9
|
author="THDayBetter",
|
|
10
10
|
author_email="chenp2368@163.com",
|
|
11
11
|
description="Python client for DayBetter devices and services",
|
|
@@ -13,6 +13,9 @@ setup(
|
|
|
13
13
|
long_description_content_type="text/markdown",
|
|
14
14
|
url="https://github.com/THDayBetter/daybetter-python",
|
|
15
15
|
packages=find_packages(),
|
|
16
|
+
package_data={
|
|
17
|
+
"daybetter_python": ["py.typed"],
|
|
18
|
+
},
|
|
16
19
|
classifiers=[
|
|
17
20
|
"Development Status :: 4 - Beta",
|
|
18
21
|
"Intended Audience :: Developers",
|
|
@@ -23,6 +26,7 @@ setup(
|
|
|
23
26
|
"Programming Language :: Python :: 3.10",
|
|
24
27
|
"Programming Language :: Python :: 3.11",
|
|
25
28
|
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Typing :: Typed",
|
|
26
30
|
],
|
|
27
31
|
python_requires=">=3.8",
|
|
28
32
|
install_requires=["aiohttp>=3.8.0"],
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"""DayBetter client exceptions."""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class DayBetterError(Exception):
|
|
5
|
-
"""Base exception for DayBetter client."""
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class AuthenticationError(DayBetterError):
|
|
9
|
-
"""Authentication failed."""
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class APIError(DayBetterError):
|
|
13
|
-
"""API request failed."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|