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.
- {daybetter_services_python-1.0.0/daybetter_services_python.egg-info → daybetter_services_python-1.0.2}/PKG-INFO +1 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/__init__.py +1 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/client.py +78 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2/daybetter_services_python.egg-info}/PKG-INFO +1 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/pyproject.toml +1 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/setup.py +1 -1
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/LICENSE +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/README.md +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/exceptions.py +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/SOURCES.txt +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/dependency_links.txt +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/requires.txt +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_services_python.egg-info/top_level.txt +0 -0
- {daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/setup.cfg +0 -0
{daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/client.py
RENAMED
|
@@ -15,7 +15,7 @@ class DayBetterClient:
|
|
|
15
15
|
def __init__(
|
|
16
16
|
self,
|
|
17
17
|
token: str,
|
|
18
|
-
base_url: str = "https://
|
|
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."""
|
|
File without changes
|
|
File without changes
|
{daybetter_services_python-1.0.0 → daybetter_services_python-1.0.2}/daybetter_python/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|