-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to support Geocaching Home Assistant integration feature updates #23
Conversation
…ot been able to test that it works yet, /Per&Albin
Cache info and trackable journeys
… some refactoring and cleanup
Fix trackable parsing and add missing fields
Update NearbyCachesSetting
Replace find count
Trackable journey improvements
Separate nearby caches logic to allow directed usage
Add comments and improve documentation
Add settings validation method
Cache and Trackable URLs
Formatting and cleanup
Haven't checked it yet but first of all, what an incredible addition! |
Simply lovely! Thanks! This is exactly what I hoped for when I started this package. Very happy with it! One question I have in my mind since the beginning: Given the fact that 350 users are using the integration, and a maximum of 1200 API calls per minute are allowed, how do we make sure not to hit that rate limit, making the integration unuseable for all users for a minute, or even longer if we hit that limit too often? And if we do hit the limit, how will the integration respond? It's something that we probably should have built in from the beginning but with just some generic requests the need wasn't there. How are your views on this? We can try to contact Groundspeak to try stretching the limits, but I doubt they can do that. But maybe the influence of the largest open source community in the world can convince them to move ;) Can you make a rough estimation of the expected calls per minute? It would help to get a better view of the (possible) problem and how to overcome it.. |
And in addition to @Sholofly's comment there are also limitations on basic vs premium members, non-premium have more restrictions in what they can see or request, there should be checks built-in for that more information on this: https://api.groundspeak.com/documentation#restrictions This is one of the reasons we kept the initial implementation very basic, because we didnt have checks on that yet |
Thank you both for your comments. As a note:
Here is a breakdown of the API requests: Retrieving a new status initiates the following requests:
So in total, each new status yields 4 + TT API calls, with a minimum of 1 call (tracked trackables, tracked caches and nearby caches disabled). We can expect these to occur during the same minute, as they are called in succession when the update is triggered. TT is tied to each integration instance and that user's configuration, with a minimum of 1 and currently no maximum. However, pagination is not implemented so there is an imposed max limit there when making the API call, however we should probably include some handling in the code that limits the number of tracked trackables and caches. Currently we do not supply the The minimum number of requests per status update is therefore 1, with the maximum being 4 + To expand on the API imposed limits:
Some quick estimations therefore yield (with the current update interval at one every hour): With the three rate limits as: And assuming each integration is under a unique IP address, we get: Minimum configuration (tracked caches and trackables disabled, nearby caches disabled):
Maximum configuration (50 tracked caches, 10 tracked trackables, 100 nearby caches):
Note about the calculations:
All in all, I do not think it will be an issue at the moment, however I do think it would be a good idea to add some limitations in the code as well for all of the API calls. I also think updating the data each hour is not really necessary for this integration, so we could for example update it every other hour, and set the hour it updates on based on a coin flip (tails is hour 1, 3, 5, 7..., heads is hour 2, 4, 6, 8...) which would halve the API calls and importantly the rates, allowing for double the users. This is of course my own interpretations of the restrictions, I may have misinterpreted them so it is a good idea to double check that, and that my math looks reasonable. I have not spent much time digging into the restrictions, so I may also have missed something. TLDR: We do not currently enforce any limits to the number of tracked caches or tracked trackables but could easily do so by implementing it. For nearby caches we do enforce limits in the code, currently allowing the entire span (0-100 caches). All three are affected by the API imposed limitations described above. There are ways of enforcing or scheduling to allow the integration to scale more under a single partner key, which could be implemented with different levels of ambition. |
If I understand these restrictions correctly, they should not be an issue for us as we only fetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read everything twice and couldn't find something to correct. Must say I am not a Python developer so it doesn't say much from my side. You should probably ask a native Python programmer to review it too, if you idn't do that already.
Brilliant change! Please let me know if you are planning to review this by a more experienced python developer. Otherwise I will complete the PR. I will create a new release 0.3.0 that will automaticcally publish te package to pypi |
… handling: Raise error if too many codes were configured in settings. Automatically remove duplicate codes
@Sholofly I made some additions to this PR:
These changes were made to address my previous comments, and make it easy to change the limits down the line. There are now two imposed limits in the code:
The limits are configurable in Regarding the review, we have previous experience in python even though it is not our main language. However, I am confident enough in these changes that I do not think they should need a further review. We have tried to put comments and documentation where necessary to make it more maintainable and not overuse python specific syntax to make it more accessible for non python-natives. I think most of the reviewing will take place in the HA side of things, so these changes may get revisited as part of that PR which we will try to publish in the near future. So from our end bumping the version number and merging is fine! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition!
Introduction
This PR adds the necessary features required for our updates to the HA Geocaching integration. These updates are:
Following is an explanation of the features we have added to the Geocaching integration.
Feature overview
For each model, we create a new device which groups all relevant entities together, in the same way as the current integration does with the profile entities. For each cache we add in HA, we therefore add a device for that specific cache with some entities that hold data for that cache. The same goes for each trackable we add. There are therefore now in total 3 different device types: Profile (1 created for the integration), Cache (1 created for each nearby cache, and another created for each tracked cache) and Trackable (1 created for each tracked trackable).
Trackable device
Each trackable contains 7 entities. These are:
In addition to these entities, we also store its trackable journey (from the trackable log, filtered for only events where it moved) in the extra attributes which can be parsed and extracted using Jinja. See an example of this later.
Cache device
Each cache contains 7 entities. These are:
Tracked trackables and caches
During configuration, the user can select one or more caches (and trackables) to track. These will then be returned as part of the
GeocachingStatus
object with their updated information. For example, a user can choose to track their own hidden caches, and their own trackables (or caches/trackables they are interested in) and then display the information for those in Home Assistant.Configuration:
![image](https://private-user-images.githubusercontent.com/34547876/395245024-155ed565-f199-4829-93f4-7047d1c131d5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ1MTcsIm5iZiI6MTczOTYxNDIxNywicGF0aCI6Ii8zNDU0Nzg3Ni8zOTUyNDUwMjQtMTU1ZWQ1NjUtZjE5OS00ODI5LTkzZjQtNzA0N2QxYzEzMWQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDEwMTAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVhYWIyNjMwNDIwZTA3YzJiY2NlZDFjOWU0MzA5OGJhMWJlNmU2MWNiZDg5ZDA0OTI4ZDQ5NzIyMmEzYzdiZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.FYgN78pksz3Ves5xXal1Ji0pMJJnEH5ijU5wcf7wGBc)
Displaying a Trackable:
![image](https://private-user-images.githubusercontent.com/34547876/395245942-b5068115-c159-4ebc-a01a-6c17d63fe7c2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ1MTcsIm5iZiI6MTczOTYxNDIxNywicGF0aCI6Ii8zNDU0Nzg3Ni8zOTUyNDU5NDItYjUwNjgxMTUtYzE1OS00ZWJjLWEwMWEtNmMxN2Q2M2ZlN2MyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDEwMTAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFmZDZkODA4YWM0OTFjNGJiMDU1MDYyYzgwM2ExMGEyZGYyMTQzNGNlM2RmZmEzZDRjOTJmNjk3OTNhOGM5MmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Yrjffm_zs9HFy--_LYq0YLpPm1HNLVY8iMxjy9JbStM)
Displaying a Cache:
![image](https://private-user-images.githubusercontent.com/34547876/395246787-5efd9732-d075-437f-8431-485cd063e8df.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ1MTcsIm5iZiI6MTczOTYxNDIxNywicGF0aCI6Ii8zNDU0Nzg3Ni8zOTUyNDY3ODctNWVmZDk3MzItZDA3NS00MzdmLTg0MzEtNDg1Y2QwNjNlOGRmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDEwMTAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI5YTAxYjM1ZjM2MTYwZjY3M2IxODJmY2I4MjA2M2FhYjEzZTdlNDRjNDM1MTcwOGIzYzczMzQxZDBkNGY2MDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9-0tjvlsAvzNUaOC88FtTKw4DmkBT7PXb2ejWs4lUQU)
Nearby caches
We use the home location of the HA instance as the position, and then search for caches in a radius around this position. These are considered "nearby caches". As with the tracked caches, we generate a cache device for each nearby cache. The user can configure the settings for this in the configuration step, to adjust the radius and maximum number of caches to generate devices for. A known limitation for this feature is that the nearby cache devices are generated during the configuration, and will therefore not be dynamically updated should a new cache be placed nearby. We looked into supporting this but were unable to within our time span.
Configuration:
![image](https://private-user-images.githubusercontent.com/34547876/395248799-7fb6a545-f6b5-4d95-9858-0683b358a43a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ1MTcsIm5iZiI6MTczOTYxNDIxNywicGF0aCI6Ii8zNDU0Nzg3Ni8zOTUyNDg3OTktN2ZiNmE1NDUtZjZiNS00ZDk1LTk4NTgtMDY4M2IzNThhNDNhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDEwMTAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk0YjdjYWZlMzk3M2NmYjBmMzE2ZjBhZWM0MTZmODliYzAxYTNiOTUyMDAzODk1NDJlMzNkODlhNmEzMjJkMDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.EoaMhUuRMIhmnqUNwl6TfRxsQr38OcvViGEdygBgq14)
Displaying the nearby caches:
![image](https://private-user-images.githubusercontent.com/34547876/395248984-6fede1ae-d84c-449a-afb0-e52deb01c6cb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTQ1MTcsIm5iZiI6MTczOTYxNDIxNywicGF0aCI6Ii8zNDU0Nzg3Ni8zOTUyNDg5ODQtNmZlZGUxYWUtZDg0Yy00NDlhLWFmYjAtZTUyZGViMDFjNmNiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDEwMTAxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUyM2Q5MjQwNzJjODIyZTVhMTkwMjkwODcyODQ4MjRjN2I4NjllMmE2MjEyOTE3NWJhZTkzMmZmNzU5NWJhNmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.D1o-znybnIwKP-8GQnuUJMXspAPpF5Bhr5aC91X4QJw)
Additions to profile device
For the profile device, which is the current featureset for the integration, we have added two sensors: total number of caches nearby, and total distance traveled by all tracked Trackables.
Setup
To test, we have made changes to the
ha-core
repository. This PR is used with thegeo
branch of our fork, available here. We did not manage to get it working just using thehass --skip-pip-packages geocachingapi
command, it would continue to use the downloaded version from pypi instead of our local version of this repository. Therefore we made some temporary changes during development, which we will revert before opening a PR for theha-core
repository. This is our first time developing Home Assistant, so if you know of a better way to solve it you can ignore these instructions, but be aware that there are changes made in ourgeo
branch that are temporary and used to set up our development environments.We used Dev Containers in Visual Studio Code to develop our features. In order to get everything working, we created a bind mount for the dev container, and then we had to:
$HOME/Repos/geocachingapi-python
, see the bind mountgeo
branchCtrl + Shift + P -> Dev Containers: Rebuild Container Without Cache
pip3 install -e config/custom_libraries/geocachingapi
hass --skip-pip-packages geocachingapi
The cards we used to display the information in the previous images are available here.
Thank you for the previous work with this library and HA integration. Please let us know if you have any questions or comments. If this PR gets merged, then we will try to merge the forked
ha-core
geo-branch afterwards, after reverting our temporary development changes. Merging this PR would of course warrant a new version, so let us know which version this should be before merging.Credits
The feature updates to the Geocaching integration and updates to this repository has been developed by: