Skip to content

async_get_snapshot doesn't seem to work well with battery cams (fix incoming) #527

Description

@reeve

Hi! 👋

I've been looking at an issue with the Ring Home Assistant integration where dashboards with camera snapshots on them seem to often show old images or fail to load any image at all. The initial issue was determined (by someone else) to be due to the HA code pulling a frame from the last recording rather than using async_get_snapshot (see discussion here: home-assistant/core#155796). There is a PR for that but it was never submitted. I was going to just submit that but when I tested it locally it seemed to still not work.

After some experimentation it seems like the existing implementation of async_get_snapshot doesn't work as expected - particularly for battery powered cams. Specifically, new images are not (usually) created when we call the timestamp endpoint (which seems to be the assumption of the code) and so no image is ever downloaded, because the existing image is too old. Even with cameras which do seem to more often actually capture an image, the logic in the method can get stuck in a kind of race condition where the image was generated from the previous call and so is too old by the time of next call. After trying a bunch of things without luck I looked at the ring-mqtt library to see what it does, and it actually uses an entirely different API endpoint. This seems to work much better (and looks to be the same endpoint as the Ring mobile app uses, as the images I see in both places match).

I think that if we replaced the existing implementation with a call to this new endpoint (https://prd-api-us.prd.rings.solutions/snapshots/next/) it would be much more reliable (and less complex). In my testing it reliably pulls images in ~0.5-3.0 seconds depending on the camera type. I've created a branch with the change, will link it to this issue. I'm hoping if you agree to the change we can get it merged so we can fix the HA integration.

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions