Skip to content

Commit 93d735c

Browse files
committed
Address code review feedback
- Device.get_history() now uses decrypt_data_blob_async() to avoid blocking - Use asyncio.get_running_loop() instead of deprecated get_event_loop() - Fix Raises documentation: remove aiohttp.ClientError (wrapped by _make_api_request) - Fix get_pictures() docstring to clarify it returns empty list on error - Fix inconsistent status in HOME_ASSISTANT_REVIEW.md section 18 https://claude.ai/code/session_019KoQsx1g9tLyTsu2JakAnn
1 parent 2c285de commit 93d735c

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

docs/HOME_ASSISTANT_REVIEW.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ async def get_locations(...) -> List[str]:
398398

399399
**HA Rationale:** Demonstrates code quality and test thoroughness.
400400

401-
**Status:** ❌ TODO
401+
**Status:** ✅ FIXED
402+
- Coverage reporting implemented with pytest-cov
403+
- 100% branch coverage achieved
404+
- Codecov badge added to README
402405

403406
---
404407

fmd_api/client.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ async def create(
145145
Raises:
146146
ValueError: If base_url uses HTTP instead of HTTPS.
147147
FmdApiException: If authentication fails or server returns an error.
148-
aiohttp.ClientError: If a network error occurs.
149148
asyncio.TimeoutError: If the request times out.
150149
"""
151150
inst = cls(
@@ -215,7 +214,6 @@ async def authenticate(self, fmd_id: str, password: str, session_duration: int)
215214
216215
Raises:
217216
FmdApiException: If authentication fails or server returns an error.
218-
aiohttp.ClientError: If a network error occurs.
219217
asyncio.TimeoutError: If the request times out.
220218
"""
221219
log.info("[1] Requesting salt...")
@@ -493,7 +491,7 @@ async def decrypt_data_blob_async(self, data_b64: str) -> bytes:
493491
Raises:
494492
FmdApiException: If private key not loaded, blob too small, or decryption fails.
495493
"""
496-
loop = asyncio.get_event_loop()
494+
loop = asyncio.get_running_loop()
497495
return await loop.run_in_executor(None, self.decrypt_data_blob, data_b64)
498496

499497
# -------------------------
@@ -675,7 +673,6 @@ async def get_locations(self, num_to_get: int = -1, skip_empty: bool = True, max
675673
676674
Raises:
677675
FmdApiException: If server returns an error or unexpected response.
678-
aiohttp.ClientError: If a network error occurs.
679676
asyncio.TimeoutError: If the request times out.
680677
"""
681678
log.debug(f"Getting locations, num_to_get={num_to_get}, " f"skip_empty={skip_empty}")
@@ -753,10 +750,8 @@ async def get_pictures(self, num_to_get: int = -1, timeout: Optional[float] = No
753750
timeout: Custom timeout for this request (uses client default if None).
754751
755752
Returns:
756-
List of picture blobs (may be base64 strings or metadata dicts).
757-
758-
Raises:
759-
aiohttp.ClientError: If a network error occurs (returns empty list).
753+
List of picture blobs (may be base64 strings or metadata dicts), or an empty
754+
list if a network or HTTP error occurs.
760755
"""
761756
req_timeout = aiohttp.ClientTimeout(total=timeout if timeout is not None else self.timeout)
762757
try:

fmd_api/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def get_history(self, limit: int = -1) -> AsyncIterator[Location]:
7070

7171
for b in blobs:
7272
try:
73-
decrypted = self.client.decrypt_data_blob(b)
73+
decrypted = await self.client.decrypt_data_blob_async(b)
7474
yield Location.from_json(decrypted.decode("utf-8"))
7575
except Exception as e:
7676
# skip invalid blobs but log

0 commit comments

Comments
 (0)