daybetter-services-python 1.0.3__tar.gz → 1.0.5__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.3/daybetter_services_python.egg-info → daybetter_services_python-1.0.5}/PKG-INFO +1 -1
  2. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_python/__init__.py +1 -1
  3. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_python/client.py +86 -1
  4. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5/daybetter_services_python.egg-info}/PKG-INFO +1 -1
  5. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/pyproject.toml +1 -1
  6. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/setup.py +1 -1
  7. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/LICENSE +0 -0
  8. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/README.md +0 -0
  9. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_python/exceptions.py +0 -0
  10. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_services_python.egg-info/SOURCES.txt +0 -0
  11. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_services_python.egg-info/dependency_links.txt +0 -0
  12. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_services_python.egg-info/requires.txt +0 -0
  13. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/daybetter_services_python.egg-info/top_level.txt +0 -0
  14. {daybetter_services_python-1.0.3 → daybetter_services_python-1.0.5}/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
3
+ Version: 1.0.5
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.3"
6
+ __version__ = "1.0.5"
7
7
  __all__ = ["DayBetterClient", "DayBetterError", "AuthenticationError", "APIError"]
@@ -27,6 +27,8 @@ class DayBetterClient:
27
27
  self.base_url = base_url
28
28
  self._session: Optional[aiohttp.ClientSession] = None
29
29
  self._auth_valid = True
30
+ self._devices: List[Dict[str, Any]] = []
31
+ self._pids: Dict[str, Any] = {}
30
32
 
31
33
  async def __aenter__(self):
32
34
  """Async context manager entry."""
@@ -68,7 +70,7 @@ class DayBetterClient:
68
70
  if resp.status == 200:
69
71
  data = await resp.json()
70
72
  devices = data.get("data", [])
71
- _LOGGER.debug("Fetched devices: %s", devices)
73
+ _LOGGER.debug("Fetched %d devices", len(devices))
72
74
  self._auth_valid = True
73
75
  return devices
74
76
  elif resp.status == 401:
@@ -330,6 +332,89 @@ class DayBetterClient:
330
332
  """Check if the API client is authenticated."""
331
333
  return self._auth_valid
332
334
 
335
+ def filter_sensor_devices(
336
+ self,
337
+ devices: List[Dict[str, Any]],
338
+ pids: Dict[str, Any],
339
+ ) -> List[Dict[str, Any]]:
340
+ """Filter devices to only include sensors based on PID.
341
+
342
+ Args:
343
+ devices: List of all devices
344
+ pids: Dictionary containing device type PIDs
345
+
346
+ Returns:
347
+ List of sensor devices only
348
+ """
349
+ sensor_pids_str = pids.get("sensor", "")
350
+ if not sensor_pids_str:
351
+ return []
352
+
353
+ sensor_pids = {pid.strip() for pid in sensor_pids_str.split(",")}
354
+
355
+ return [
356
+ device
357
+ for device in devices
358
+ if device.get("deviceMoldPid", "") in sensor_pids
359
+ ]
360
+
361
+ def merge_device_status(
362
+ self,
363
+ devices: List[Dict[str, Any]],
364
+ statuses: List[Dict[str, Any]],
365
+ ) -> List[Dict[str, Any]]:
366
+ """Merge device info with status info.
367
+
368
+ Args:
369
+ devices: List of device info dictionaries
370
+ statuses: List of device status dictionaries
371
+
372
+ Returns:
373
+ List of merged device dictionaries
374
+ """
375
+ status_dict = {status.get("deviceName"): status for status in statuses}
376
+
377
+ merged = []
378
+ for device in devices:
379
+ device_name = device.get("deviceName")
380
+ merged_device = device.copy()
381
+
382
+ if device_name in status_dict:
383
+ merged_device.update(status_dict[device_name])
384
+
385
+ merged.append(merged_device)
386
+
387
+ return merged
388
+
389
+ async def fetch_sensor_data(self) -> List[Dict[str, Any]]:
390
+ """Fetch and process sensor data in one call.
391
+
392
+ This method fetches device statuses, devices list, and PIDs,
393
+ filters for sensor devices, and merges the data.
394
+
395
+ Returns:
396
+ List of sensor devices with merged status data
397
+
398
+ Raises:
399
+ AuthenticationError: If authentication fails
400
+ APIError: If API request fails
401
+ """
402
+ # Fetch current statuses
403
+ statuses = await self.fetch_device_statuses()
404
+
405
+ # Fetch devices and PIDs if not cached
406
+ if not self._devices or not self._pids:
407
+ self._devices = await self.fetch_devices()
408
+ self._pids = await self.fetch_pids()
409
+
410
+ # Filter to sensor devices only
411
+ sensor_devices = self.filter_sensor_devices(self._devices, self._pids)
412
+
413
+ # Merge with current status
414
+ merged = self.merge_device_status(sensor_devices, statuses)
415
+ _LOGGER.debug("Fetched %d sensor devices", len(merged))
416
+ return merged
417
+
333
418
  async def close(self):
334
419
  """Close the client session."""
335
420
  if self._session:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: daybetter-services-python
3
- Version: 1.0.3
3
+ Version: 1.0.5
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.3"
7
+ version = "1.0.5"
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.3",
8
+ version="1.0.5",
9
9
  author="THDayBetter",
10
10
  author_email="chenp2368@163.com",
11
11
  description="Python client for DayBetter devices and services",