Skip to content

Commit 153595e

Browse files
committed
Rename methods get_picture/get_pictures/fetch_pictures/download_photo for clarity
1 parent 7588569 commit 153595e

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Tips:
120120
- `Device` helper (per‑device convenience)
121121
- `await device.refresh()` → hydrate cached state
122122
- `await device.get_location()` → parsed last location
123-
- `await device.get_pictures(n)` + `await device.get_picture(item)`
123+
- `await device.get_picture_blobs(n)` + `await device.decode_picture(blob)`
124124
- Commands: `await device.play_sound()`, `await device.take_front_picture()`,
125125
`await device.take_rear_picture()`, `await device.lock(message=None)`,
126126
`await device.wipe(confirm=True)`

docs/MIGRATE_FROM_V1.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ client = await FmdClient.create("https://fmd.example.com", "alice", "secret")
9292

9393
| V1 | V2 (FmdClient) | V2 (Device) | Notes |
9494
|----|----------------|-------------|-------|
95-
| `await api.get_pictures(10)` | `await client.get_pictures(10)` | `await device.get_pictures(10)` | Both available (old: fetch_pictures deprecated) |
96-
| N/A | N/A | `await device.get_picture(blob)` | Helper method (old: download_photo deprecated) |
95+
| `await api.get_pictures(10)` | `await client.get_pictures(10)` | `await device.get_picture_blobs(10)` | Both available (old: get_pictures/fetch_pictures deprecated) |
96+
| N/A | N/A | `await device.decode_picture(blob)` | Helper method (old: get_picture/download_photo deprecated) |
9797

9898
### Export Data
9999

@@ -153,8 +153,8 @@ await device.lock(message="Lost device") # Lock with message
153153
await device.wipe(confirm=True) # Factory reset (DESTRUCTIVE)
154154

155155
# Pictures
156-
pictures = await device.get_pictures(10)
157-
photo_result = await device.get_picture(pictures[0])
156+
pictures = await device.get_picture_blobs(10)
157+
photo_result = await device.decode_picture(pictures[0])
158158
```
159159

160160
---

fmd_api/device.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ async def take_rear_photo(self) -> bool:
9393

9494
async def fetch_pictures(self, num_to_get: int = -1) -> List[dict]:
9595
warnings.warn(
96-
"Device.fetch_pictures() is deprecated; use get_pictures()",
96+
"Device.fetch_pictures() is deprecated; use get_picture_blobs()",
9797
DeprecationWarning,
9898
stacklevel=2,
9999
)
100-
return await self.get_pictures(num_to_get=num_to_get)
100+
return await self.get_picture_blobs(num_to_get=num_to_get)
101101

102102
async def download_photo(self, picture_blob_b64: str) -> PhotoResult:
103103
"""
@@ -122,12 +122,28 @@ async def take_rear_picture(self) -> bool:
122122
return await self.client.take_picture("back")
123123

124124
async def get_pictures(self, num_to_get: int = -1) -> List[dict]:
125-
"""Get picture blobs (metadata) from the server.
125+
"""Deprecated: use get_picture_blobs()."""
126+
warnings.warn(
127+
"Device.get_pictures() is deprecated; use get_picture_blobs()",
128+
DeprecationWarning,
129+
stacklevel=2,
130+
)
131+
return await self.get_picture_blobs(num_to_get=num_to_get)
126132

127-
Returns the raw list from the server (typically base64-encoded encrypted blobs)."""
133+
async def get_picture(self, picture_blob_b64: str) -> PhotoResult:
134+
"""Deprecated: use decode_picture()."""
135+
warnings.warn(
136+
"Device.get_picture() is deprecated; use decode_picture()",
137+
DeprecationWarning,
138+
stacklevel=2,
139+
)
140+
return await self.decode_picture(picture_blob_b64)
141+
142+
async def get_picture_blobs(self, num_to_get: int = -1) -> List[dict]:
143+
"""Get raw picture blobs (base64-encoded encrypted strings) from the server."""
128144
return await self.client.get_pictures(num_to_get=num_to_get)
129145

130-
async def get_picture(self, picture_blob_b64: str) -> PhotoResult:
146+
async def decode_picture(self, picture_blob_b64: str) -> PhotoResult:
131147
"""Decrypt and decode a single picture blob into a PhotoResult."""
132148
decrypted = self.client.decrypt_data_blob(picture_blob_b64)
133149
# decrypted is bytes, often containing a base64-encoded image (as text)

tests/functional/test_device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ async def main():
3232
loc = await device.get_location()
3333
print("Cached location:", loc)
3434
# fetch pictures and attempt to download the first one
35-
pics = await device.get_pictures(5)
35+
pics = await device.get_picture_blobs(5)
3636
print("Pictures listed:", len(pics))
3737
if pics:
3838
try:
39-
photo = await device.get_picture(pics[0])
39+
photo = await device.decode_picture(pics[0])
4040
fn = "device_photo.jpg"
4141
with open(fn, "wb") as f:
4242
f.write(photo.data)

tests/unit/test_device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def decrypt(self, packet, padding_obj):
7575
client.access_token = "token"
7676
device = Device(client, "alice")
7777
try:
78-
pics = await device.get_pictures()
78+
pics = await device.get_picture_blobs()
7979
assert len(pics) == 1
8080
# download the picture and verify we got PNGDATA bytes
81-
photo = await device.get_picture(pics[0])
81+
photo = await device.decode_picture(pics[0])
8282
assert photo.data == b"PNGDATA"
8383
assert photo.mime_type.startswith("image/")
8484
finally:
@@ -626,8 +626,8 @@ def decrypt(self, packet, padding_obj):
626626

627627

628628
@pytest.mark.asyncio
629-
async def test_device_get_pictures():
630-
"""Test Device.get_pictures method."""
629+
async def test_device_get_picture_blobs():
630+
"""Test Device.get_picture_blobs method."""
631631
client = FmdClient("https://fmd.example.com")
632632
client.access_token = "token"
633633

@@ -639,7 +639,7 @@ async def test_device_get_pictures():
639639
m.put("https://fmd.example.com/api/v1/pictures", payload={"Data": mock_pictures})
640640

641641
try:
642-
pictures = await device.get_pictures(num_to_get=1)
642+
pictures = await device.get_picture_blobs(num_to_get=1)
643643
assert len(pictures) == 1
644644
assert pictures[0]["id"] == 0
645645
finally:

0 commit comments

Comments
 (0)