Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To reduce the number of network requests, we can use the
location
endpoint.Instead of fetching device list + iterating all devices (n+1), we can fetch locations+device list, then iterate the locations to fetch latest samples.
Nothing wrong with the current implementation, but this caused some users to experience 429 error (too many requests) if they had >10 devices. For users with 10 devices, this will now be:
In total 3 requests, and when locations and devices are cached, this will be 1 request. Most users has only one location, but in some cases they might have a cabin, maybe an autogenerated "hidden" location etc. In my case on my account, I have 3 locations. In my case I'll go from 7 (+ device list) to 3 (+ locations and device list).
Some user could have many locations without any devices, this can be solved by ignoring empty locations. To keep this simple for now this is not covered in this PR.
This PR also includes
product_name
. Then we can use this directly in Home Assistant:instead of this:
https://github.com/home-assistant/core/blob/dev/homeassistant/components/airthings/sensor.py#L152
Also added the
location_name
which can be helpful for debugging if the user has multiple devices with more or less the same name, for examplekitchen
in your home + cabin. Not sure where to use it / present it to the user, but it's now available to be used.Documentation:
https://developer.airthings.com/consumer-api-docs#tag/Locations
Will fix these issues:
home-assistant/core#101666
#4
Example
Disclaimer: I work for Airthings. Discussed this problem with the cloud developers and this is the way to go. Less load on our cloud, and fewer 429 errors for the users.