Join GitHub today
Optimize Ring Sensors platform setup #16886
Could reduce few seconds startup time for Ring users
Related issue (if applicable): fixes #
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>
Example entry for
so I had staged these commits in my own dev environment and I received the following warnings:
I have a Ring doorbell and a ring floodlight camera
@awarecan I am running dev and I do indeed have that PR applied before I staged this PR. Before I applied this PR I got the following error, and I can confirm that only this error comes back when I revert this PR.
I have confirmed this with several HA restarts as well to make sure only this warning shows up when this PR is reverted.
I don't have better way to measure platform setup performance (maybe worth a PR to improve), but I found
By enabled it, you need change
ring = Ring(debug=True, username=username, password=password, cache_file=cache)
logger: default: info logs: ring_doorbell: debug
@arsaboo yes just about every restart I do, here is an example of the logging:
@awarecan I just enabled debugging and I see a lot of errors actually, I see this repeated hundreds of times if not more:
these particular errors begin showing up during and after setup, they don't seem to stop at the level of frequency they go.
Since sensor.ring and camera.ring both taking over 10 seconds, I think it is safe to say ring platform spent majority of those 13 seconds to setup.
So, if you can compare with the record before this PR, we can have conclusion if we got performance improve.
Regarding the debug information, it was a bug in ring_doorbell lib, when it write a "Sorry.. Something went wrong..." log in debug mode, which actually means "Everything is good"
This is three API call in same thread, they are mapping to one update() method call, you can find, it can only finish 2 update() call in 1 seconds. If my calculation is right, 2 ring device need at least 16 update() call to add all sensors, that means 8 seconds.
The same calculation gave me 28 update() for previous logic, that means 14 seconds, so plus other overhead, I will bet if you switch back the previous logic, sensor domain need 20 seconds to complete setup.
Even for current logic, I still think there is a big room to improve, IMO, add two device, we should only call update() twice. But it will beyond this pull request's scope.
@awarecan here are the results with the PR reverted, you are correct the average is 25 seconds for the
With that said during one of my tests with the PR reverted I still saw the
great improvement :)