daybetter-services-python 1.0.0__tar.gz → 1.0.2__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.
Files changed (14) hide show
  1. {daybetter_services_python-1.0.0/daybetter_services_python.egg-info → daybetter_services_python-1.0.2}/PKG-INFO +1 -1
  2. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/__init__.py +1 -1
  3. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/client.py +78 -1
  4. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2/daybetter_services_python.egg-info}/PKG-INFO +1 -1
  5. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/pyproject.toml +1 -1
  6. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/setup.py +1 -1
  7. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/LICENSE +0 -0
  8. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/README.md +0 -0
  9. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/exceptions.py +0 -0
  10. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/SOURCES.txt +0 -0
  11. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/dependency_links.txt +0 -0
  12. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/requires.txt +0 -0
  13. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/top_level.txt +0 -0
  14. {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: daybetter-services-python
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: Python client for DayBetter devices and services
5
5
  Home-page: https://github.com/THDayBetter/daybetter-python
6
6
  Author: THDayBetter
@@ -3,5 +3,5 @@
3
3
  from .client import DayBetterClient
4
4
  from .exceptions import DayBetterError, AuthenticationError, APIError
5
5
 
6
- __version__ = "1.0.0"
6
+ __version__ = "1.0.2"
7
7
  __all__ = ["DayBetterClient", "DayBetterError", "AuthenticationError", "APIError"]
@@ -15,7 +15,7 @@ class DayBetterClient:
15
15
  def __init__(
16
16
  self,
17
17
  token: str,
18
- base_url: str = "https://a.dbiot.org/daybetter/hass/api/v1.0/"
18
+ base_url: str = "https://cloud.v2.dbiot.link/daybetter/hass/api/v1.0/"
19
19
  ):
20
20
  """Initialize the client.
21
21
 
@@ -248,6 +248,83 @@ class DayBetterClient:
248
248
  _LOGGER.exception("Exception while fetching MQTT config: %s", e)
249
249
  raise DayBetterError(f"Unexpected error: {e}")
250
250
 
251
+ async def fetch_device_statuses(self) -> List[Dict[str, Any]]:
252
+ """Fetch statuses for all devices.
253
+
254
+ Returns:
255
+ List of device status dictionaries. Example item:
256
+ {
257
+ "deviceName": str,
258
+ "type": int,
259
+ "online": bool,
260
+ "temp": int,
261
+ "humi": int,
262
+ "bettery": int
263
+ }
264
+
265
+ Raises:
266
+ AuthenticationError: If authentication fails
267
+ APIError: If API request fails
268
+ """
269
+ try:
270
+ session = self._get_session()
271
+ url = f"{self.base_url}hass/status"
272
+ headers = self._get_headers()
273
+
274
+ async with session.post(url, headers=headers) as resp:
275
+ if resp.status == 200:
276
+ data = await resp.json()
277
+ self._auth_valid = True
278
+ # API expected to return { "data": [...] }
279
+ return data.get("data", [])
280
+ elif resp.status == 401:
281
+ _LOGGER.error("Authentication failed - token may be expired")
282
+ self._auth_valid = False
283
+ raise AuthenticationError("Authentication failed - token may be expired")
284
+ else:
285
+ error_text = await resp.text()
286
+ _LOGGER.error("Failed to fetch device statuses: %s", error_text)
287
+ raise APIError(f"API error {resp.status}: {error_text}")
288
+ except aiohttp.ClientError as e:
289
+ _LOGGER.exception("Client error while fetching device statuses: %s", e)
290
+ raise APIError(f"Client error: {e}")
291
+ except Exception as e:
292
+ _LOGGER.exception("Exception while fetching device statuses: %s", e)
293
+ raise DayBetterError(f"Unexpected error: {e}")
294
+
295
+ async def integrate(self, hass_code: str) -> Dict[str, Any]:
296
+ """Integrate with Home Assistant using hassCode.
297
+
298
+ Args:
299
+ hass_code: Home Assistant integration code from APP
300
+
301
+ Returns:
302
+ Integration result dictionary
303
+
304
+ Raises:
305
+ APIError: If API request fails
306
+ """
307
+ try:
308
+ session = self._get_session()
309
+ url = f"{self.base_url}integrate"
310
+ payload = {"hassCode": hass_code}
311
+
312
+ async with session.post(url, json=payload) as resp:
313
+ if resp.status == 200:
314
+ data = await resp.json()
315
+ _LOGGER.debug("Integration successful: %s", data)
316
+ return data
317
+ else:
318
+ error_text = await resp.text()
319
+ _LOGGER.error("Failed to integrate: %s", error_text)
320
+ raise APIError(f"API error {resp.status}: {error_text}")
321
+ except aiohttp.ClientError as e:
322
+ _LOGGER.exception("Client error while integrating: %s", e)
323
+ raise APIError(f"Client error: {e}")
324
+ except Exception as e:
325
+ _LOGGER.exception("Exception while integrating: %s", e)
326
+ raise DayBetterError(f"Unexpected error: {e}")
327
+
251
328
  @property
252
329
  def is_authenticated(self) -> bool:
253
330
  """Check if the API client is authenticated."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: daybetter-services-python
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: Python client for DayBetter devices and services
5
5
  Home-page: https://github.com/THDayBetter/daybetter-python
6
6
  Author: THDayBetter
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "daybetter-services-python"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  description = "Python client for DayBetter devices and services"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -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.0",
8
+ version="1.0.2",
9
9
  author="THDayBetter",
10
10
  author_email="chenp2368@163.com",
11
11
  description="Python client for DayBetter devices and services",