Skip to content

Commit

Permalink
get_snapshot() logic to be compliant with legacy
Browse files Browse the repository at this point in the history
Still allows the user to specify the filename,
however, still keep the same older format as
Home Assistant is built on top of that functionality.
  • Loading branch information
tchellomello committed Jan 18, 2021
1 parent ee04f66 commit bb4b9d1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ring_doorbell/doorbot.py
Expand Up @@ -427,7 +427,7 @@ def connection_status(self):
"""Return connection status."""
return self._attrs.get("alerts").get("connection")

def get_snapshot(self, retries=3, delay=1, filename="snapshot.jpg"):
def get_snapshot(self, retries=3, delay=1, filename=None):
"""Take a snapshot and download it"""
url = SNAPSHOT_TIMESTAMP_ENDPOINT
payload = {"doorbot_ids": [self._attrs.get("id")]}
Expand All @@ -437,10 +437,11 @@ def get_snapshot(self, retries=3, delay=1, filename="snapshot.jpg"):
time.sleep(delay)
response = self._ring.query(url, method="POST", json=payload).json()
if response["timestamps"][0]["timestamp"] / 1000 > request_time:
return self._ring.query(
SNAPSHOT_ENDPOINT.format(self._attrs.get("id"), raw=True)
).content
with open(filename, "wb") as jpg:
jpg.write(snapshot)
snapshot = self._ring.query(SNAPSHOT_ENDPOINT.format(
self._attrs.get("id")), raw=True).content
if filename:
with open(filename, "wb") as jpg:
jpg.write(snapshot)
return True
return snapshot
return False

0 comments on commit bb4b9d1

Please sign in to comment.