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
Implement OpenSky library #92814
Implement OpenSky library #92814
Conversation
Also pinging @OzGav, since he replied to the other PR. |
Oh and to explain the change in functionality, currently I use the radius to calculate the north, east, south and west edges of the circle, and making it a box. That means that all the diagonal directions are now longer since it's a cube, not a radius |
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.
Please move get_bounding_box and calculate_point to the library.
Please also add a link to the library changelog in the PR description.
@@ -70,6 +70,124 @@ | |||
) | |||
|
|||
|
|||
def calculate_point( |
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.
Please move calculate_point
to the library
return phi2, lembda2 | ||
|
||
|
||
def get_bounding_box(latitude: float, longitude: float, radius: float) -> BoundingBox: |
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.
Please move get_bounding_box
to the library
@epenet do you agree on the chosen solution direction? Before I move it to the library and we end up not using it. |
Just note I have a fork with the bounding box solution and ability to login to increase the api limit |
I am not commenting on library code. I am only commenting on HA code. |
Of course of course, but even when moving this code to the library, the HA integration would work different, so I first want to know if that change is a good change before actually implementing it in the library. |
You mean #91162? I only see the authentication part, but only as a breaking change. |
This is my current component that I am using as a custom. https://github.com/OzGav/opensky It is combination of other PRs that have been rejected as well as the authentication addition that I wrote plus some other guards to try and trap errors due to website unavailability. |
Right. I wrote https://github.com/joostlek/python-opensky which now also has auth support and is async. Let's try to at least get the integration up to standards and then we can take a look at how we can improve it |
Sounds good. There are a bunch of requirements (Architecture Decision Records) that apply to new or updated components that I don't have time to address hence my custom component. The community will very much appreciate it if you can bring this component up to speed to keep it within core. |
First of all, I agree with @epenet that the calculations should be in the library 👍 To answer the question: I don't think there are any concerns with the changes in this PR or with the development path you outline in the PR description, it makes sense. |
Please mark the PR as ready for review when the requested changes have been implemented 👍 |
@emontnemery Did the changes. Is it preferred to add tests in this PR or follow ups? |
I don't have any more concerns about this PR.
Several small PRs are preferred over fewer large PRs; it's fine to add tests in a follow-up since opensky does not yet have tests 👍 |
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.
LGTM, thanks @joostlek 👍
…icator * 'dev' of https://github.com/home-assistant/core: (400 commits) Fix todoist state updates (home-assistant#91915) Bump pydeconz to v112 (home-assistant#91924) Fix directv attribute media_position_updated_at (home-assistant#92383) Add a DataUpdateCoordinator to Hydrawise (home-assistant#93223) Add UDP listener in Lightwave (home-assistant#85385) Prevent SensorEntity and RestoreEntity inheritance (home-assistant#88971) Implement OpenSky library (home-assistant#92814) Bump pygti and change the request for the new api version (home-assistant#92283) Fully Kiosk: Truncate long URLs (home-assistant#92347) Enable strict type checks of cloud (home-assistant#92576) Remove legacy translations from electrasmart (home-assistant#93446) Update aioairzone-cloud to v0.1.3 (home-assistant#93443) Add backup location and mount failed repair (home-assistant#93126) Remove unused zwave discovery logic (home-assistant#93436) Bump PySwitchbee to 1.8.0 (home-assistant#92348) remove template deprecated function `device_trigger.py` (home-assistant#93419) Fix reference string in data disk repair (home-assistant#93220) Use SnapshotAssertion in Renault tests (part 2) (home-assistant#92395) Add ability to unload demo integration (home-assistant#92515) Move Twitch constants to separate file (home-assistant#92605) ...
Proposed change
So in #92593 we discovered that the old way of implementing was bad. Since the
/states/all
request we did, fetched all planes all over the world (Last time I ran it on my pc I received 9000+ records). When we had the list, we would calculate for each plane if their distance to the set point was below the set radius. If so, it would fire events and add it to the state of the entity.Currently as a workaround, the max scan interval is set to once every 15 minutes, to allow our requests (which cost 4 credits, from the 400 you get as anonymous user) to actually work. Since before it ran every 12 seconds or so, and shitting it's pants in the logs since it kept receiving 429 with no valid JSON.
There are 2 other types of users within OpenSky. Users that are authenticated, they get 4000 credits a day, and users who are actively helping the network, they get 8000 per day and they can request their own states from the sensor as much as they'd like (until general rate limiting kicks in ofc).
In the comment of that PR, we also see that people want to add a way to authenticate themselves for OpenSky so they can benefit from more frequent updates. But before we are able to do that, we need to improve our codebase since it's still a yaml integration and all the logic is currently in the integration. Also, since the radius functionality is only a thing that home assistant has, it's heavy in the current implementation, so we need to change this functionality to be less heavy or change the way we configure.
Last weekend I built https://github.com/joostlek/python-opensky, an async library for OpenSky. OpenSky also has their own python library, but we like async, async is good. (And I wanted to get into library development).
So to give a rough sketch of a future for OpenSky:
The distance method is taken from https://gist.github.com/jtornero/9f3ddabc6a89f8292bb2. There are uncertainties about the license, but I am not an expert on both licensing or maths. So if someone has a better plan, lmk!
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: