Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ring_doorbell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def query(self,
attempts=RETRY_TOKEN,
method='GET',
raw=False,
extra_params=None):
extra_params=None,
json=None):
"""Query data from Ring API."""
if self.debug:
_LOGGER.debug("Querying %s", url)
Expand Down Expand Up @@ -189,7 +190,7 @@ def query(self,
elif method == 'PUT':
req = self.session.put((url), params=urlencode(params))
elif method == 'POST':
req = self.session.post((url), params=urlencode(params))
req = self.session.post((url), params=urlencode(params), json=json)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)


if self.debug:
_LOGGER.debug("_query %s ret %s", loop, req.status_code)
Expand Down
2 changes: 2 additions & 0 deletions ring_doorbell/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
NEW_SESSION_ENDPOINT = '/clients_api/session'
RINGTONES_ENDPOINT = '/ringtones'
SIREN_ENDPOINT = DOORBELLS_ENDPOINT + '/siren_{1}'
SNAPSHOT_ENDPOINT = "/clients_api/snapshots/image/{0}"
SNAPSHOT_TIMESTAMP_ENDPOINT = "/clients_api/snapshots/timestamps"
TESTSOUND_CHIME_ENDPOINT = CHIMES_ENDPOINT + '/play_sound'
URL_DOORBELL_HISTORY = DOORBELLS_ENDPOINT + '/history'
URL_RECORDING = '/clients_api/dings/{0}/recording'
Expand Down
19 changes: 18 additions & 1 deletion ring_doorbell/doorbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime
import os
import pytz
import time


from ring_doorbell.generic import RingGeneric
Expand All @@ -14,7 +15,8 @@
API_URI, DOORBELLS_ENDPOINT, DOORBELL_VOL_MIN, DOORBELL_VOL_MAX,
DOORBELL_EXISTING_TYPE, DINGS_ENDPOINT, FILE_EXISTS,
LIVE_STREAMING_ENDPOINT, MSG_BOOLEAN_REQUIRED, MSG_EXISTING_TYPE,
MSG_VOL_OUTBOUND, URL_DOORBELL_HISTORY, URL_RECORDING)
MSG_VOL_OUTBOUND, SNAPSHOT_ENDPOINT, SNAPSHOT_TIMESTAMP_ENDPOINT,
URL_DOORBELL_HISTORY, URL_RECORDING)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -342,3 +344,18 @@ def volume(self, value):
def connection_status(self):
"""Return connection status."""
return self._attrs.get('alerts').get('connection')

def get_snapshot(self, retries=3, delay=1):
"""Take a snapshot and download it"""
url = API_URI + SNAPSHOT_TIMESTAMP_ENDPOINT
payload = {"doorbot_ids": [self._attrs.get('id')]}
self._ring.query(url, json=payload)
request_time = time.time()
for _ in range(retries):
time.sleep(delay)
response = self._ring.query(url, method="POST", json=payload,
raw=1).json()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

if response["timestamps"][0]["timestamp"] / 1000 > request_time:
return self._ring.query(API_URI + SNAPSHOT_ENDPOINT.format(
self._attrs.get('id')), raw=True).content
return False