python-ring-doorbell icon indicating copy to clipboard operation
python-ring-doorbell copied to clipboard

timestamp check on get_snapshot

Open PyxAI opened this issue 4 years ago • 3 comments

Hi everyone, thanks for this great contribution! I keep getting a False response from this check which made me wonder why is check even needed?

request_time = time.time()
for _ in range(retries):
    time.sleep(delay)
    response = self._ring.query(url, method="POST", json=payload).json()
    if response["timestamps"][0]["timestamp"] / 1000 > request_time: #<<<------This line
        return self._ring.query(SNAPSHOT_ENDPOINT.format(self._attrs.get("id"))).content

PyxAI avatar May 31 '20 05:05 PyxAI

In any case, seems that the snapshot is a cached image, i am not able to get a fresh image all the time. What I am trying to do is to setup a face recognition system on the ring device. So instead of "someone is at your door" alert, you would get "Mom is at your door", and similar benefits. The first issue is that I have to poll the API for new events And the second issue is that I cannot get a new snapshot when I want it, but that system takes a snapshot every 10 minutes or so, and I can only get the last one, not take one on demand

PyxAI avatar May 31 '20 08:05 PyxAI

Very cool application idea with the image recognition! Latency would be important for near real time functionality indeed.

4Dolio avatar Jun 26 '20 05:06 4Dolio

I also get False with get_snapshot.

I figured out the only way I can get this working is to (1) update the first query, and (2) comment out the 'timestamp' line.

Granted, the snapshots are often a few minutes old. But for now, its better than nothing.

def get_snapshot(self, retries=3, delay=1):
        """Take a snapshot and download it"""
        url = SNAPSHOT_TIMESTAMP_ENDPOINT
        payload = {"doorbot_ids": [self._attrs.get("id")]}
        self._ring.query(url, method="POST", json=payload)      <--- updated this line
        for _ in range(retries):
            time.sleep(delay)            
            self._ring.query(url, method="POST", json=payload).json()   
            #if response["timestamps"][0]["timestamp"] / 1000 > request_time:      <--- commented out this line
            return self._ring.query(                             
                SNAPSHOT_ENDPOINT.format(self._attrs.get("id"), raw=True)
            ).content                       
        return False

clinkadink avatar Jun 27 '20 20:06 clinkadink

There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs. Please make sure to update to the latest ring_doorbell version and check if that solves the issue. Thank you for your contributions.

github-actions[bot] avatar Apr 18 '24 18:04 github-actions[bot]